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 /* Initialize the protocol and registered fields */
144 static int proto_irlap = -1;
145 static int hf_lap_a = -1;
146 static int hf_lap_a_cr = -1;
147 static int hf_lap_a_address = -1;
148 static int hf_lap_c = -1;
149 static int hf_lap_c_nr = -1;
150 static int hf_lap_c_ns = -1;
151 static int hf_lap_c_p = -1;
152 static int hf_lap_c_f = -1;
153 static int hf_lap_c_s = -1;
154 static int hf_lap_c_u_cmd = -1;
155 static int hf_lap_c_u_rsp = -1;
156 static int hf_lap_c_i = -1;
157 static int hf_lap_c_s_u = -1;
158 static int hf_lap_i = -1;
159 static int hf_snrm_saddr = -1;
160 static int hf_snrm_daddr = -1;
161 static int hf_snrm_ca = -1;
162 static int hf_ua_saddr = -1;
163 static int hf_ua_daddr = -1;
164 static int hf_negotiation_param = -1;
165 static int hf_param_pi = -1;
166 static int hf_param_pl = -1;
167 static int hf_param_pv = -1;
168 static int hf_xid_ident = -1;
169 static int hf_xid_saddr = -1;
170 static int hf_xid_daddr = -1;
171 static int hf_xid_flags = -1;
172 static int hf_xid_s = -1;
173 static int hf_xid_conflict = -1;
174 static int hf_xid_slotnr = -1;
175 static int hf_xid_version = -1;
177 static int proto_irlmp = -1;
178 static int hf_lmp_xid_hints = -1;
179 static int hf_lmp_xid_charset = -1;
180 static int hf_lmp_xid_name = -1;
181 static int hf_lmp_xid_name_no_ascii = -1;
182 static int hf_lmp_dst = -1;
183 static int hf_lmp_dst_control = -1;
184 static int hf_lmp_dst_lsap = -1;
185 static int hf_lmp_src = -1;
186 static int hf_lmp_src_r = -1;
187 static int hf_lmp_src_lsap = -1;
188 static int hf_lmp_opcode = -1;
189 static int hf_lmp_rsvd = -1;
190 static int hf_lmp_reason = -1;
191 static int hf_lmp_mode = -1;
192 static int hf_lmp_status = -1;
194 static int proto_iap = -1;
195 static int hf_iap_ctl = -1;
196 static int hf_iap_ctl_lst = -1;
197 static int hf_iap_ctl_ack = -1;
198 static int hf_iap_ctl_opcode = -1;
199 static int hf_iap_class_name = -1;
200 static int hf_iap_attr_name = -1;
201 static int hf_iap_return = -1;
202 static int hf_iap_list_len = -1;
203 static int hf_iap_list_entry = -1;
204 static int hf_iap_obj_id = -1;
205 static int hf_iap_attr_type = -1;
206 static int hf_iap_int = -1;
207 static int hf_iap_seq_len = -1;
208 static int hf_iap_oct_seq = -1;
209 static int hf_iap_char_set = -1;
210 static int hf_iap_string = -1;
211 static int hf_iap_invaloctet = -1;
212 static int hf_iap_invallsap = -1;
214 static int proto_ttp = -1;
215 static int hf_ttp_p = -1;
216 static int hf_ttp_icredit = -1;
217 static int hf_ttp_m = -1;
218 static int hf_ttp_dcredit = -1;
220 static int proto_log = -1;
221 static int hf_log_msg = -1;
222 static int hf_log_missed = -1;
224 /* Initialize the subtree pointers */
225 static gint ett_irlap = -1;
226 static gint ett_lap_a = -1;
227 static gint ett_lap_c = -1;
228 static gint ett_lap_i = -1;
229 static gint ett_xid_flags = -1;
230 static gint ett_log = -1;
231 static gint ett_irlmp = -1;
232 static gint ett_lmp_dst = -1;
233 static gint ett_lmp_src = -1;
234 static gint ett_iap = -1;
235 static gint ett_iap_ctl = -1;
236 static gint ett_ttp = -1;
238 #define MAX_PARAMETERS 32
239 static gint ett_param[MAX_PARAMETERS];
241 static gint ett_iap_entry[MAX_IAP_ENTRIES];
243 static const xdlc_cf_items irlap_cf_items = {
255 /* IAP conversation type */
256 typedef struct iap_conversation {
257 struct iap_conversation* pnext;
258 guint32 iap_query_frame;
259 ias_attr_dissector_t* pattr_dissector;
260 } iap_conversation_t;
262 /* IrLMP conversation type */
263 typedef struct lmp_conversation {
264 struct lmp_conversation* pnext;
265 guint32 iap_result_frame;
267 dissector_t proto_dissector;
268 } lmp_conversation_t;
270 static GMemChunk* iap_conv_chunk = NULL;
271 static GMemChunk* lmp_conv_chunk = NULL;
273 static const true_false_string lap_cr_vals = {
278 static const true_false_string set_notset = {
283 static const value_string lap_c_ftype_vals[] = {
284 { XDLC_I, "Information frame" },
285 { XDLC_S, "Supervisory frame" },
286 { XDLC_U, "Unnumbered frame" },
290 static const value_string lap_c_u_cmd_abbr_vals[] = {
291 { XDLC_SNRM, "SNRM" },
292 { XDLC_DISC, "DISC" },
294 { IRDA_XID_CMD, "XID" },
295 { XDLC_TEST, "TEST" },
299 static const value_string lap_c_u_rsp_abbr_vals[] = {
300 { XDLC_SNRM, "RNRM" },
302 { XDLC_FRMR, "FRMR" },
307 { XDLC_TEST, "TEST" },
311 static const value_string lap_c_u_cmd_vals[] = {
312 { XDLC_SNRM>>2, "Set Normal Response Mode" },
313 { XDLC_DISC>>2, "Disconnect" },
314 { XDLC_UI>>2, "Unnumbered Information" },
315 { IRDA_XID_CMD>>2, "Exchange Station Identification" },
316 { XDLC_TEST>>2, "Test" },
320 static const value_string lap_c_u_rsp_vals[] = {
321 { XDLC_SNRM>>2, "Request Normal Response Mode" },
322 { XDLC_UA>>2, "Unnumbered Acknowledge" },
323 { XDLC_FRMR>>2, "Frame Reject" },
324 { XDLC_DM>>2, "Disconnect Mode" },
325 { XDLC_RD>>2, "Request Disconnect" },
326 { XDLC_UI>>2, "Unnumbered Information" },
327 { XDLC_XID>>2, "Exchange Station Identification" },
328 { XDLC_TEST>>2, "Test" },
332 static const value_string lap_c_s_vals[] = {
333 { XDLC_RR>>2, "Receiver ready" },
334 { XDLC_RNR>>2, "Receiver not ready" },
335 { XDLC_REJ>>2, "Reject" },
336 { XDLC_SREJ>>2, "Selective reject" },
340 static const value_string xid_slot_numbers[] = {
341 /* Number of XID slots */
349 static const value_string lmp_opcode_vals[] = {
350 /* IrLMP frame opcodes */
351 { CONNECT_CMD, "Connect Command" },
352 { CONNECT_CNF, "Connect Confirm" },
353 { DISCONNECT, "Disconnect" },
354 { ACCESSMODE_CMD, "Access Mode Command" },
355 { ACCESSMODE_CNF, "Access Mode Confirm" },
359 static const value_string lmp_reason_vals[] = {
360 /* IrLMP disconnect reasons */
361 { 0x01, "User Request" },
362 { 0x02, "Unexpected IrLAP Disconnect" },
363 { 0x03, "Failed to establish IrLAP connection" },
364 { 0x04, "IrLAP Reset" },
365 { 0x05, "Link Management Initiated Disconnect" },
366 { 0x06, "Data delivered on disconnected LSAP-Connection"},
367 { 0x07, "Non Responsive LM-MUX Client" },
368 { 0x08, "No available LM-MUX Client" },
369 { 0x09, "Connection Half Open" },
370 { 0x0A, "Illegal Source Address" },
371 { 0xFF, "Unspecified Disconnect Reason" },
375 static const value_string lmp_mode_vals[] = {
377 { 0x00, "Multiplexed" },
378 { 0x01, "Exclusive" },
382 static const value_string lmp_status_vals[] = {
386 { 0xFF, "Unsupported" },
390 static const value_string iap_opcode_vals[] = {
392 { GET_INFO_BASE, "GetInfoBase" },
393 { GET_OBJECTS, "GetObjects" },
394 { GET_VALUE, "GetValue" },
395 { GET_VALUE_BY_CLASS, "GetValueByClass" },
396 { GET_OBJECT_INFO, "GetObjectInfo" },
397 { GET_ATTRIB_NAMES, "GetAttributeNames" },
401 static const value_string iap_return_vals[] = {
402 /* IrIAP Return-codes */
403 { IAS_SUCCESS, "Success" },
404 { IAS_CLASS_UNKNOWN, "Class/Object Unknown" },
405 { IAS_ATTRIB_UNKNOWN, "Attribute Unknown" },
406 { IAS_ATTR_TOO_LONG, "Attribute List Too Long" },
407 { IAS_DISCONNECT, "Disconnect (Linux-IrDA only)" },
408 { IAS_UNSUPPORTED, "Unsupported Optional Operation" },
412 static const value_string iap_attr_type_vals[] = {
413 /* LM-IAS Attribute types */
414 { IAS_MISSING, "Missing" },
415 { IAS_INTEGER, "Integer" },
416 { IAS_OCT_SEQ, "Octet Sequence" },
417 { IAS_STRING, "String" },
421 static ias_attr_dissector_t device_attr_dissector[] = {
422 /* Device attribute dissectors */
423 /* { "IrLMPSupport", xxx }, not implemented yet... */
427 /* IAS class dissectors */
428 static ias_class_dissector_t class_dissector[] = { CLASS_DISSECTORS };
432 * Dissect parameter tuple
434 unsigned dissect_param_tuple(tvbuff_t* tvb, proto_tree* tree, unsigned offset)
436 guint8 len = tvb_get_guint8(tvb, offset + 1);
439 proto_tree_add_item(tree, hf_param_pi, tvb, offset, 1, FALSE);
443 proto_tree_add_item(tree, hf_param_pl, tvb, offset, 1, FALSE);
449 proto_tree_add_item(tree, hf_param_pv, tvb, offset, len, FALSE);
460 static unsigned dissect_ttp(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root, gboolean data)
466 if (tvb_length(tvb) == 0)
469 /* Make entries in Protocol column on summary display */
470 if (check_col(pinfo->cinfo, COL_PROTOCOL))
471 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TTP");
473 head = tvb_get_guint8(tvb, offset);
475 if (check_col(pinfo->cinfo, COL_INFO))
480 sprintf(buf, ", Credit=%d", head & ~TTP_PARAMETERS);
481 col_append_str(pinfo->cinfo, COL_INFO, buf);
486 /* create display subtree for the protocol */
487 proto_item* ti = proto_tree_add_item(root, proto_ttp, tvb, 0, -1, FALSE);
488 proto_tree* tree = proto_item_add_subtree(ti, ett_ttp);
492 proto_tree_add_item(tree, hf_ttp_m, tvb, offset, 1, FALSE);
493 proto_tree_add_item(tree, hf_ttp_dcredit, tvb, offset, 1, FALSE);
498 proto_tree_add_item(tree, hf_ttp_p, tvb, offset, 1, FALSE);
499 proto_tree_add_item(tree, hf_ttp_icredit, tvb, offset, 1, FALSE);
502 proto_item_set_len(tree, offset);
512 * Dissect IAP request
514 static void dissect_iap_request(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root)
523 conversation_t* conv;
524 iap_conversation_t* iap_conv;
527 if (tvb_length(tvb) == 0)
530 /* Make entries in Protocol column on summary display */
531 if (check_col(pinfo->cinfo, COL_PROTOCOL))
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, (guint8*)class_name, offset + 1 + 1, clen);
592 class_name[clen] = 0;
593 tvb_memcpy(tvb, (guint8*)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, (guint8*)buf, offset + 1 + 1, clen);
618 memcpy(&buf[clen], "\" \"", 3);
619 tvb_memcpy(tvb, (guint8*)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 if (check_col(pinfo->cinfo, COL_PROTOCOL))
698 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IAP");
700 op = tvb_get_guint8(tvb, offset) & IAP_OP;
701 retcode = tvb_get_guint8(tvb, offset + 1);
703 src = pinfo->circuit_id ^ CMD_FRAME;
704 srcaddr.type = AT_NONE;
706 srcaddr.data = (guint8*)&src;
708 destaddr.type = AT_NONE;
710 destaddr.data = (guint8*)&pinfo->circuit_id;
712 /* Find result value dissector */
713 conv = find_conversation(pinfo->fd->num, &srcaddr, &destaddr, PT_NONE, pinfo->srcport, pinfo->destport, 0);
716 num = pinfo->fd->num;
718 iap_conv = (iap_conversation_t*)conversation_get_proto_data(conv, proto_iap);
719 while (iap_conv && (iap_conv->iap_query_frame >= num))
720 iap_conv = iap_conv->pnext;
724 cur_iap_conv = iap_conv->pnext;
727 if ((cur_iap_conv->iap_query_frame < num) &&
728 (cur_iap_conv->iap_query_frame > iap_conv->iap_query_frame))
730 iap_conv = cur_iap_conv;
733 cur_iap_conv = cur_iap_conv->pnext;
738 if (check_col(pinfo->cinfo, COL_INFO))
740 col_add_str(pinfo->cinfo, COL_INFO, "Result: ");
741 col_append_str(pinfo->cinfo, COL_INFO, val_to_str(retcode, iap_return_vals, "0x%02X"));
745 case GET_VALUE_BY_CLASS:
748 switch (tvb_get_guint8(tvb, offset + 6))
751 strcpy(buf, ", Missing");
755 sprintf(buf, ", Integer: %d", tvb_get_ntohl(tvb, offset + 7));
759 sprintf(buf, ", %d Octets", tvb_get_ntohs(tvb, offset + 7));
764 n = tvb_get_guint8(tvb, offset + 8);
765 tvb_memcpy(tvb, (guint8*)buf + 3, offset + 9, n);
766 strcpy(buf + 3 + n, "\"");
769 col_append_str(pinfo->cinfo, COL_INFO, buf);
770 if (tvb_get_ntohs(tvb, offset + 2) > 1)
771 col_append_str(pinfo->cinfo, COL_INFO, ", ...");
779 /* create display subtree for the protocol */
780 proto_item* ti = proto_tree_add_item(root, proto_iap, tvb, 0, -1, FALSE);
781 proto_tree* tree = proto_item_add_subtree(ti, ett_iap);
783 proto_tree* ctl_tree;
784 proto_tree* entry_tree;
787 ti = proto_tree_add_item(tree, hf_iap_ctl, tvb, offset, 1, FALSE);
788 ctl_tree = proto_item_add_subtree(ti, ett_iap_ctl);
789 proto_tree_add_item(ctl_tree, hf_iap_ctl_lst, tvb, offset, 1, FALSE);
790 proto_tree_add_item(ctl_tree, hf_iap_ctl_ack, tvb, offset, 1, FALSE);
791 proto_tree_add_item(ctl_tree, hf_iap_ctl_opcode, tvb, offset, 1, FALSE);
794 proto_tree_add_item(tree, hf_iap_return, tvb, offset, 1, FALSE);
799 case GET_VALUE_BY_CLASS:
802 list_len = tvb_get_ntohs(tvb, offset);
804 proto_tree_add_item(tree, hf_iap_list_len, tvb, offset, 2, FALSE);
807 while ((offset < len) && (n < list_len))
809 type = tvb_get_guint8(tvb, offset + 2);
817 attr_len = tvb_get_ntohs(tvb, offset + 2 + 1) + 2;
821 attr_len = tvb_get_guint8(tvb, offset + 2 + 1 + 1) + 2;
828 ti = proto_tree_add_item(tree, hf_iap_list_entry, tvb, offset, 2 + 1 + attr_len, FALSE);
829 g_snprintf(buf, sizeof(buf) - 1, "%d", n + 1);
830 proto_item_append_text(ti, buf);
831 entry_tree = proto_item_add_subtree(ti, ett_iap_entry[n]);
833 proto_tree_add_item(entry_tree, hf_iap_obj_id, tvb, offset, 2, FALSE);
836 proto_tree_add_item(entry_tree, hf_iap_attr_type, tvb, offset, 1, FALSE);
842 if (!iap_conv || !iap_conv->pattr_dissector ||
843 !iap_conv->pattr_dissector->value_dissector(tvb, offset, pinfo, entry_tree,
845 proto_tree_add_item(entry_tree, hf_iap_int, tvb, offset, 4, FALSE);
849 proto_tree_add_item(entry_tree, hf_iap_seq_len, tvb, offset, 2, FALSE);
850 if (!iap_conv || !iap_conv->pattr_dissector ||
851 !iap_conv->pattr_dissector->value_dissector(tvb, offset, pinfo, entry_tree,
853 proto_tree_add_item(entry_tree, hf_iap_oct_seq, tvb, offset + 2,
854 attr_len - 2, FALSE);
858 proto_tree_add_item(entry_tree, hf_iap_char_set, tvb, offset, 1, FALSE);
859 if (!iap_conv || !iap_conv->pattr_dissector ||
860 !iap_conv->pattr_dissector->value_dissector(tvb, offset, pinfo, entry_tree,
862 proto_tree_add_item(entry_tree, hf_iap_string, tvb, offset + 1, 1, FALSE);
878 case GET_VALUE_BY_CLASS:
886 type = tvb_get_guint8(tvb, offset);
893 if (iap_conv && iap_conv->pattr_dissector)
894 iap_conv->pattr_dissector->value_dissector(tvb, offset, pinfo, 0,
899 attr_len = tvb_get_ntohs(tvb, offset) + 2;
900 if (iap_conv && iap_conv->pattr_dissector)
901 iap_conv->pattr_dissector->value_dissector(tvb, offset, pinfo, 0,
906 attr_len = tvb_get_guint8(tvb, offset + 1) + 2;
907 if (iap_conv && iap_conv->pattr_dissector)
908 iap_conv->pattr_dissector->value_dissector(tvb, offset, pinfo, 0,
923 /* If any bytes remain, send it to the generic data dissector */
924 tvb = tvb_new_subset(tvb, offset, -1, -1);
925 call_dissector(data_handle, tvb, pinfo, root);
930 * Check if IAP result is octet sequence
932 gboolean check_iap_octet_result(tvbuff_t* tvb, proto_tree* tree, unsigned offset,
933 const char* attr_name, guint8 attr_type)
935 if (attr_type != IAS_OCT_SEQ)
939 proto_item* ti = proto_tree_add_item(tree, hf_iap_invaloctet, tvb, offset, 0, FALSE);
940 proto_item_append_text(ti, "%s", attr_name);
941 proto_item_append_text(ti, "\" attribute must be octet sequence!");
952 * Check if IAP result is correct LsapSel
954 guint8 check_iap_lsap_result(tvbuff_t* tvb, proto_tree* tree, unsigned offset,
955 const char* attr_name, guint8 attr_type)
960 if ((attr_type != IAS_INTEGER) || ((lsap = tvb_get_ntohl(tvb, offset)) < 0x01) ||
965 proto_item* ti = proto_tree_add_item(tree, hf_iap_invallsap, tvb, offset, 0, FALSE);
966 proto_item_append_text(ti, "%s", attr_name);
967 proto_item_append_text(ti, "\" attribute must be integer value between 0x01 and 0x6F!");
978 * Dissect IrDA application protocol
980 static void dissect_appl_proto(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root, pdu_type_t pdu_type)
986 conversation_t* conv;
987 lmp_conversation_t* cur_lmp_conv;
988 lmp_conversation_t* lmp_conv = NULL;
992 src = pinfo->circuit_id ^ CMD_FRAME;
993 srcaddr.type = AT_NONE;
995 srcaddr.data = (guint8*)&src;
997 destaddr.type = AT_NONE;
999 destaddr.data = (guint8*)&pinfo->circuit_id;
1001 /* Find result value dissector */
1002 conv = find_conversation(pinfo->fd->num, &srcaddr, &destaddr, PT_NONE, pinfo->srcport, pinfo->destport, 0);
1005 num = pinfo->fd->num;
1007 lmp_conv = (lmp_conversation_t*)conversation_get_proto_data(conv, proto_irlmp);
1008 while (lmp_conv && (lmp_conv->iap_result_frame >= num))
1009 lmp_conv = lmp_conv->pnext;
1013 cur_lmp_conv = lmp_conv->pnext;
1014 while (cur_lmp_conv)
1016 if ((cur_lmp_conv->iap_result_frame < num) &&
1017 (cur_lmp_conv->iap_result_frame > lmp_conv->iap_result_frame))
1019 lmp_conv = cur_lmp_conv;
1022 cur_lmp_conv = cur_lmp_conv->pnext;
1029 /*g_message("%x:%d->%x:%d = %p\n", src, pinfo->srcport, pinfo->circuit_id, pinfo->destport, lmp_conv); */
1030 /*g_message("->%d: %d %d %p\n", pinfo->fd->num, lmp_conv->iap_result_frame, lmp_conv->ttp, lmp_conv->proto_dissector); */
1031 if ((lmp_conv->ttp) && (pdu_type != DISCONNECT_PDU))
1033 offset += dissect_ttp(tvb, pinfo, root, (pdu_type == DATA_PDU));
1035 tvb = tvb_new_subset(tvb, offset, -1, -1);
1038 pinfo->private_data = (void *)pdu_type;
1040 lmp_conv->proto_dissector(tvb, pinfo, root);
1043 call_dissector(data_handle, tvb, pinfo, root);
1050 static void dissect_irlmp(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root)
1052 unsigned offset = 0;
1059 /* Make entries in Protocol column on summary display */
1060 if (check_col(pinfo->cinfo, COL_PROTOCOL))
1061 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IrLMP");
1063 dlsap = tvb_get_guint8(tvb, offset);
1064 cbit = dlsap & CONTROL_BIT;
1065 dlsap &= ~CONTROL_BIT;
1067 slsap = tvb_get_guint8(tvb, offset+1) & ~CONTROL_BIT;
1069 /* save Lsaps in pinfo */
1070 pinfo->srcport = slsap;
1071 pinfo->destport = dlsap;
1075 opcode = tvb_get_guint8(tvb, offset+2);
1077 if (check_col(pinfo->cinfo, COL_INFO))
1079 col_add_fstr(pinfo->cinfo, COL_INFO, "%d > %d, ", slsap, dlsap);
1080 col_append_str(pinfo->cinfo, COL_INFO, val_to_str(opcode, lmp_opcode_vals, "0x%02X"));
1081 if ((opcode == ACCESSMODE_CMD) || (opcode == ACCESSMODE_CNF))
1083 col_append_str(pinfo->cinfo, COL_INFO, " (");
1084 col_append_str(pinfo->cinfo, COL_INFO,
1085 val_to_str(tvb_get_guint8(tvb, offset+4), lmp_mode_vals, "0x%02X"));
1086 col_append_str(pinfo->cinfo, COL_INFO, ")");
1091 if (check_col(pinfo->cinfo, COL_INFO))
1092 col_add_fstr(pinfo->cinfo, COL_INFO, "%d > %d, Len=%d", slsap, dlsap,
1093 tvb_length(tvb) - 2);
1097 /* create display subtree for the protocol */
1098 proto_item* ti = proto_tree_add_item(root, proto_irlmp, tvb, 0, -1, FALSE);
1099 proto_tree* tree = proto_item_add_subtree(ti, ett_irlmp);
1101 proto_tree* dst_tree;
1102 proto_tree* src_tree;
1105 ti = proto_tree_add_item(tree, hf_lmp_dst, tvb, offset, 1, FALSE);
1106 dst_tree = proto_item_add_subtree(ti, ett_lmp_dst);
1107 proto_tree_add_item(dst_tree, hf_lmp_dst_control, tvb, offset, 1, FALSE);
1108 proto_tree_add_item(dst_tree, hf_lmp_dst_lsap, tvb, offset, 1, FALSE);
1111 ti = proto_tree_add_item(tree, hf_lmp_src, tvb, offset, 1, FALSE);
1112 src_tree = proto_item_add_subtree(ti, ett_lmp_src);
1113 proto_tree_add_item(src_tree, hf_lmp_src_r, tvb, offset, 1, FALSE);
1114 proto_tree_add_item(src_tree, hf_lmp_src_lsap, tvb, offset, 1, FALSE);
1119 proto_tree_add_item(tree, hf_lmp_opcode, tvb, offset, 1, FALSE);
1126 if (offset < tvb_length(tvb))
1128 proto_tree_add_item(tree, hf_lmp_rsvd, tvb, offset, 1, FALSE);
1134 proto_tree_add_item(tree, hf_lmp_reason, tvb, offset, 1, FALSE);
1138 case ACCESSMODE_CMD:
1139 proto_tree_add_item(tree, hf_lmp_rsvd, tvb, offset, 1, FALSE);
1142 proto_tree_add_item(tree, hf_lmp_mode, tvb, offset, 1, FALSE);
1146 case ACCESSMODE_CNF:
1147 proto_tree_add_item( tree, hf_lmp_status, tvb, offset, 1, FALSE);
1150 proto_tree_add_item(tree, hf_lmp_mode, tvb, offset, 1, FALSE);
1156 tvb = tvb_new_subset(tvb, offset, -1, -1);
1157 proto_item_set_len(tree, offset);
1170 if (offset < tvb_length(tvb))
1178 case ACCESSMODE_CMD:
1179 case ACCESSMODE_CNF:
1185 tvb = tvb_new_subset(tvb, offset, -1, -1);
1190 if (dlsap == LSAP_IAS)
1191 dissect_iap_request(tvb, pinfo, root);
1192 else if (slsap == LSAP_IAS)
1193 dissect_iap_result(tvb, pinfo, root);
1195 dissect_appl_proto(tvb, pinfo, root, DATA_PDU);
1199 if ((dlsap == LSAP_IAS) || (slsap == LSAP_IAS))
1200 call_dissector(data_handle, tvb, pinfo, root);
1206 dissect_appl_proto(tvb, pinfo, root, CONNECT_PDU);
1210 dissect_appl_proto(tvb, pinfo, root, DISCONNECT_PDU);
1214 call_dissector(data_handle, tvb, pinfo, root);
1221 * Add LMP conversation
1223 void add_lmp_conversation(packet_info* pinfo, guint8 dlsap, gboolean ttp, dissector_t proto_dissector)
1228 conversation_t* conv;
1229 lmp_conversation_t* lmp_conv = NULL;
1232 /*g_message("%d: add_lmp_conversation(%p, %d, %d, %p) = ", pinfo->fd->num, pinfo, dlsap, ttp, proto_dissector); */
1233 srcaddr.type = AT_NONE;
1235 srcaddr.data = (guint8*)&pinfo->circuit_id;
1237 dest = pinfo->circuit_id ^ CMD_FRAME;
1238 destaddr.type = AT_NONE;
1240 destaddr.data = (guint8*)&dest;
1242 conv = find_conversation(pinfo->fd->num, &destaddr, &srcaddr, PT_NONE, dlsap, 0, NO_PORT_B);
1245 lmp_conv = (lmp_conversation_t*)conversation_get_proto_data(conv, proto_irlmp);
1248 /* Does entry already exist? */
1249 if (lmp_conv->iap_result_frame == pinfo->fd->num)
1252 if (lmp_conv->pnext == NULL)
1254 lmp_conv->pnext = g_mem_chunk_alloc(lmp_conv_chunk);
1255 lmp_conv = lmp_conv->pnext;
1258 lmp_conv = lmp_conv->pnext;
1263 conv = conversation_new(pinfo->fd->num, &destaddr, &srcaddr, PT_NONE, dlsap, 0, NO_PORT_B);
1264 lmp_conv = g_mem_chunk_alloc(lmp_conv_chunk);
1265 conversation_add_proto_data(conv, proto_irlmp, (void*)lmp_conv);
1268 lmp_conv->pnext = NULL;
1269 lmp_conv->iap_result_frame = pinfo->fd->num;
1270 lmp_conv->ttp = ttp;
1271 lmp_conv->proto_dissector = proto_dissector;
1273 /*g_message("%p\n", lmp_conv); */
1278 * Dissect Negotiation Parameters
1280 static unsigned dissect_negotiation(tvbuff_t* tvb, proto_tree* tree, unsigned offset)
1288 while (tvb_reported_length_remaining(tvb, offset) > 0)
1290 guint8 p_len = tvb_get_guint8(tvb, offset + 1);
1294 ti = proto_tree_add_item(tree, hf_negotiation_param, tvb, offset, p_len + 2, FALSE);
1295 p_tree = proto_item_add_subtree(ti, ett_param[n]);
1297 pv = tvb_get_guint8(tvb, offset+2);
1300 switch (tvb_get_guint8(tvb, offset))
1303 proto_item_append_text(ti, ": Baud Rate (");
1306 strcat(buf, ", 2400");
1308 strcat(buf, ", 9600");
1310 strcat(buf, ", 19200");
1312 strcat(buf, ", 38400");
1314 strcat(buf, ", 57600");
1316 strcat(buf, ", 115200");
1318 strcat(buf, ", 576000");
1320 strcat(buf, ", 1152000");
1321 if ((p_len > 1) && (tvb_get_guint8(tvb, offset+3) & 0x01))
1322 strcat(buf, ", 4000000");
1324 strcat(buf, " bps)");
1326 proto_item_append_text(ti, buf+2);
1330 case PI_MAX_TURN_TIME:
1331 proto_item_append_text(ti, ": Maximum Turn Time (");
1334 strcat(buf, ", 500");
1336 strcat(buf, ", 250");
1338 strcat(buf, ", 100");
1340 strcat(buf, ", 50");
1342 strcat(buf, " ms)");
1344 proto_item_append_text(ti, buf+2);
1349 proto_item_append_text(ti, ": Data Size (");
1352 strcat(buf, ", 64");
1354 strcat(buf, ", 128");
1356 strcat(buf, ", 256");
1358 strcat(buf, ", 512");
1360 strcat(buf, ", 1024");
1362 strcat(buf, ", 2048");
1364 strcat(buf, " bytes)");
1366 proto_item_append_text(ti, buf+2);
1370 case PI_WINDOW_SIZE:
1371 proto_item_append_text(ti, ": Window Size (");
1388 strcat(buf, " frame window)");
1390 proto_item_append_text(ti, buf+2);
1395 proto_item_append_text(ti, ": Additional BOFs (");
1398 strcat(buf, ", 48");
1400 strcat(buf, ", 24");
1402 strcat(buf, ", 12");
1414 strcat(buf, " additional BOFs at 115200)");
1416 proto_item_append_text(ti, buf+2);
1420 case PI_MIN_TURN_TIME:
1421 proto_item_append_text(ti, ": Minimum Turn Time (");
1424 strcat(buf, ", 10");
1430 strcat(buf, ", 0.5");
1432 strcat(buf, ", 0.1");
1434 strcat(buf, ", 0.05");
1436 strcat(buf, ", 0.01");
1440 strcat(buf, " ms)");
1442 proto_item_append_text(ti, buf+2);
1447 proto_item_append_text(ti, ": Link Disconnect/Threshold Time (");
1450 strcat(buf, ", 3/0");
1452 strcat(buf, ", 8/3");
1454 strcat(buf, ", 12/3");
1456 strcat(buf, ", 16/3");
1458 strcat(buf, ", 20/3");
1460 strcat(buf, ", 25/3");
1462 strcat(buf, ", 30/3");
1464 strcat(buf, ", 40/3");
1468 proto_item_append_text(ti, buf+2);
1473 proto_item_append_text(ti, ": unknown");
1478 offset = dissect_param_tuple(tvb, p_tree, offset);
1487 * Dissect XID packet
1489 static void dissect_xid(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root, proto_tree* lap_tree, gboolean is_command)
1492 proto_item* ti = NULL;
1493 proto_tree* i_tree = NULL;
1494 proto_tree* flags_tree;
1495 guint32 saddr, daddr;
1497 proto_tree* lmp_tree = NULL;
1501 ti = proto_tree_add_item(lap_tree, hf_lap_i, tvb, offset, -1, FALSE);
1502 i_tree = proto_item_add_subtree(ti, ett_lap_i);
1504 proto_tree_add_item(i_tree, hf_xid_ident, tvb, offset, 1, FALSE);
1508 saddr = tvb_get_letohl(tvb, offset);
1509 if (check_col(pinfo->cinfo, COL_DEF_SRC))
1510 col_add_fstr(pinfo->cinfo, COL_DEF_SRC, "0x%08X", saddr);
1512 proto_tree_add_uint(i_tree, hf_xid_saddr, tvb, offset, 4, saddr);
1515 daddr = tvb_get_letohl(tvb, offset);
1516 if (check_col(pinfo->cinfo, COL_DEF_DST))
1517 col_add_fstr(pinfo->cinfo, COL_DEF_DST, "0x%08X", daddr);
1519 proto_tree_add_uint(i_tree, hf_xid_daddr, tvb, offset, 4, daddr);
1524 ti = proto_tree_add_item(i_tree, hf_xid_flags, tvb, offset, 1, FALSE);
1525 flags_tree = proto_item_add_subtree(ti, ett_xid_flags);
1526 proto_tree_add_item(flags_tree, hf_xid_s, tvb, offset, 1, FALSE);
1527 proto_tree_add_item(flags_tree, hf_xid_conflict, tvb, offset, 1, FALSE);
1533 s = tvb_get_guint8(tvb, offset);
1534 if (check_col(pinfo->cinfo, COL_INFO))
1537 col_append_str(pinfo->cinfo, COL_INFO, ", s=final");
1539 col_append_fstr(pinfo->cinfo, COL_INFO, ", s=%u", s);
1543 ti = proto_tree_add_uint(i_tree, hf_xid_slotnr, tvb, offset, 1, s);
1545 proto_item_append_text(ti, " (final)");
1551 proto_tree_add_item(i_tree, hf_xid_version, tvb, offset, 1, FALSE);
1556 proto_item_set_end(lap_tree, tvb, offset);
1557 proto_item_set_end(i_tree, tvb, offset);
1560 if (tvb_reported_length_remaining(tvb, offset) > 0)
1568 ti = proto_tree_add_item(root, proto_irlmp, tvb, offset, -1, FALSE);
1569 lmp_tree = proto_item_add_subtree(ti, ett_irlmp);
1572 for (hints_len = 0;;)
1574 guint8 hint = tvb_get_guint8(tvb, offset + hints_len++);
1578 else if (hints_len == 2)
1581 if ((hint & 0x80) == 0)
1587 ti = proto_tree_add_item(lmp_tree, hf_lmp_xid_hints, tvb, offset, hints_len, FALSE);
1588 if ((hint1 | hint2) != 0)
1590 char service_hints[256];
1592 service_hints[0] = 0;
1595 strcat(service_hints, ", PnP Compatible");
1597 strcat(service_hints, ", PDA/Palmtop");
1599 strcat(service_hints, ", Computer");
1601 strcat(service_hints, ", Printer");
1603 strcat(service_hints, ", Modem");
1605 strcat(service_hints, ", Fax");
1607 strcat(service_hints, ", LAN Access");
1609 strcat(service_hints, ", Telephony");
1611 strcat(service_hints, ", File Server");
1613 strcat(service_hints, ", IrCOMM");
1615 strcat(service_hints, ", OBEX");
1617 strcat(service_hints, ")");
1618 service_hints[0] = ' ';
1619 service_hints[1] = '(';
1621 proto_item_append_text(ti, service_hints);
1624 offset += hints_len;
1626 if (tvb_reported_length_remaining(tvb, offset) > 0)
1631 cset = tvb_get_guint8(tvb, offset);
1633 proto_tree_add_uint(lmp_tree, hf_lmp_xid_charset, tvb, offset, 1, cset);
1635 name_len = tvb_reported_length_remaining(tvb, offset);
1640 if (check_col(pinfo->cinfo, COL_INFO))
1646 tvb_memcpy(tvb, (guint8*)buf, offset, name_len);
1648 col_append_str(pinfo->cinfo, COL_INFO, ", \"");
1649 col_append_str(pinfo->cinfo, COL_INFO, buf);
1650 col_append_str(pinfo->cinfo, COL_INFO, "\"");
1653 proto_tree_add_item(lmp_tree, hf_lmp_xid_name, tvb, offset,
1659 proto_tree_add_item(lmp_tree, hf_lmp_xid_name_no_ascii, tvb, offset,
1669 * Dissect Log Messages
1671 static void dissect_log(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root)
1673 /* Make entries in Protocol column on summary display */
1674 if (check_col(pinfo->cinfo, COL_PROTOCOL))
1675 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Log");
1677 /* missed messages? */
1678 if (pinfo->pseudo_header->irda.pkttype == IRDA_MISSED_MSG)
1680 if (check_col(pinfo->cinfo, COL_INFO))
1681 col_set_str(pinfo->cinfo, COL_INFO,
1682 "WARNING: Missed one or more messages while capturing!");
1684 else if (check_col(pinfo->cinfo, COL_INFO))
1690 length = tvb_length(tvb);
1691 if (length > sizeof(buf)-1)
1692 length = sizeof(buf)-1;
1693 tvb_memcpy(tvb, (guint8*)buf, 0, length);
1695 if (buf[length-1] == '\n')
1697 else if (buf[length-2] == '\n')
1700 col_add_str(pinfo->cinfo, COL_INFO, buf);
1705 proto_item* ti = proto_tree_add_item(root, proto_log, tvb, 0, -1, FALSE);
1706 proto_tree* tree = proto_item_add_subtree(ti, ett_log);
1708 if (pinfo->pseudo_header->irda.pkttype == IRDA_MISSED_MSG)
1709 proto_tree_add_item(tree, hf_log_missed, tvb, 0, 0, FALSE);
1711 proto_tree_add_item(tree, hf_log_msg, tvb, 0, -1, FALSE);
1719 static void dissect_irlap(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root)
1723 gboolean is_response;
1725 proto_item* ti = NULL;
1726 proto_tree* tree = NULL;
1727 proto_tree* i_tree = NULL;
1728 guint32 saddr, daddr;
1731 /* Make entries in Protocol column on summary display */
1732 if (check_col(pinfo->cinfo, COL_PROTOCOL))
1733 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IrLAP");
1735 /* Clear Info column */
1736 if (check_col(pinfo->cinfo, COL_INFO))
1737 col_clear(pinfo->cinfo, COL_INFO);
1739 /* set direction column */
1740 if (check_col(pinfo->cinfo, COL_IF_DIR))
1742 switch (pinfo->pseudo_header->irda.pkttype)
1745 col_set_str(pinfo->cinfo, COL_IF_DIR, "Out");
1749 col_set_str(pinfo->cinfo, COL_IF_DIR, "In");
1754 /* decode values used for demuxing */
1755 a = tvb_get_guint8(tvb, 0);
1757 /* save connection address field in pinfo */
1758 pinfo->circuit_id = a;
1760 /* initially set address columns to connection address */
1761 g_snprintf(addr, sizeof(addr)-1, "0x%02X", a >> 1);
1762 if (check_col(pinfo->cinfo, COL_DEF_SRC))
1763 col_add_str(pinfo->cinfo, COL_DEF_SRC, addr);
1764 if (check_col(pinfo->cinfo, COL_DEF_DST))
1765 col_add_str(pinfo->cinfo, COL_DEF_DST, addr);
1770 proto_item* addr_item;
1772 /* create display subtree for the protocol */
1773 ti = proto_tree_add_item(root, proto_irlap, tvb, 0, -1, FALSE);
1774 tree = proto_item_add_subtree(ti, ett_irlap);
1776 /* create subtree for the address field */
1777 ti = proto_tree_add_item(tree, hf_lap_a, tvb, offset, 1, FALSE);
1778 a_tree = proto_item_add_subtree(ti, ett_lap_a);
1779 proto_tree_add_item(a_tree, hf_lap_a_cr, tvb, offset, 1, FALSE);
1780 addr_item = proto_tree_add_item(a_tree, hf_lap_a_address, tvb, offset, 1, FALSE);
1781 switch (a & ~CMD_FRAME)
1784 proto_item_append_text(addr_item, " (NULL Address)");
1787 proto_item_append_text(addr_item, " (Broadcast)");
1791 is_response = ((a & CMD_FRAME) == 0);
1794 /* process the control field */
1795 c = dissect_xdlc_control(tvb, 1, pinfo, tree, hf_lap_c,
1796 ett_lap_c, &irlap_cf_items, NULL, lap_c_u_cmd_abbr_vals,
1797 lap_c_u_rsp_abbr_vals, is_response, FALSE, FALSE);
1800 if ((c & XDLC_I_MASK) == XDLC_I) {
1802 proto_item_set_len(tree, offset);
1803 tvb = tvb_new_subset(tvb, offset, -1, -1);
1804 dissect_irlmp(tvb, pinfo, root);
1808 if ((c & 0x03) == XDLC_U) {
1810 switch (c & XDLC_U_MODIFIER_MASK)
1815 ti = proto_tree_add_item(tree, hf_lap_i, tvb, offset, -1, FALSE);
1816 i_tree = proto_item_add_subtree(ti, ett_lap_i);
1819 saddr = tvb_get_letohl(tvb, offset);
1822 if (check_col(pinfo->cinfo, COL_DEF_SRC))
1823 col_add_fstr(pinfo->cinfo, COL_DEF_SRC, "0x%08X", saddr);
1826 proto_tree_add_uint(i_tree, hf_snrm_saddr, tvb, offset, 4, saddr);
1829 daddr = tvb_get_letohl(tvb, offset);
1832 if (check_col(pinfo->cinfo, COL_DEF_DST))
1833 col_add_fstr(pinfo->cinfo, COL_DEF_DST, "0x%08X", daddr);
1836 proto_tree_add_uint(i_tree, hf_snrm_daddr, tvb, offset, 4, daddr);
1839 ca = tvb_get_guint8(tvb, offset);
1842 if (check_col(pinfo->cinfo, COL_INFO))
1843 col_append_fstr(pinfo->cinfo, COL_INFO, ", ca=0x%02X",
1847 proto_tree_add_uint(i_tree, hf_snrm_ca, tvb, offset, 1, ca >> 1);
1850 offset = dissect_negotiation(tvb, i_tree, offset);
1852 proto_item_set_end(ti, tvb, offset);
1856 tvb = tvb_new_subset(tvb, offset, -1, -1);
1857 dissect_xid(tvb, pinfo, root, tree, TRUE);
1861 if (tvb_reported_length_remaining(tvb, offset) > 0)
1865 ti = proto_tree_add_item(tree, hf_lap_i, tvb, offset, -1, FALSE);
1866 i_tree = proto_item_add_subtree(ti, ett_lap_i);
1869 saddr = tvb_get_letohl(tvb, offset);
1870 if (check_col(pinfo->cinfo, COL_DEF_SRC))
1871 col_add_fstr(pinfo->cinfo, COL_DEF_SRC, "0x%08X", saddr);
1873 proto_tree_add_uint(i_tree, hf_ua_saddr, tvb, offset, 4, saddr);
1876 daddr = tvb_get_letohl(tvb, offset);
1877 if (check_col(pinfo->cinfo, COL_DEF_DST))
1878 col_add_fstr(pinfo->cinfo, COL_DEF_DST, "0x%08X", daddr);
1880 proto_tree_add_uint(i_tree, hf_ua_daddr, tvb, offset, 4, daddr);
1883 offset = dissect_negotiation(tvb, i_tree, offset);
1885 proto_item_set_end(ti, tvb, offset);
1890 tvb = tvb_new_subset(tvb, offset, -1, -1);
1891 dissect_xid(tvb, pinfo, root, tree, FALSE);
1896 /* If any bytes remain, send it to the generic data dissector */
1897 if (tvb_reported_length_remaining(tvb, offset) > 0)
1899 tvb = tvb_new_subset(tvb, offset, -1, -1);
1900 call_dissector(data_handle, tvb, pinfo, root);
1906 * Dissect IrDA protocol
1908 static void dissect_irda(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root)
1910 /* load the display labels */
1911 pinfo->current_proto = "IrDA";
1913 /* check if log message */
1914 if ((pinfo->pseudo_header->irda.pkttype & IRDA_CLASS_MASK) == IRDA_CLASS_LOG)
1916 dissect_log(tvb, pinfo, root);
1921 dissect_irlap(tvb, pinfo, root);
1926 * Re-initialize the IrDA dissector
1928 static void init_irda(void)
1931 g_mem_chunk_destroy(iap_conv_chunk);
1933 g_mem_chunk_destroy(lmp_conv_chunk);
1935 iap_conv_chunk = g_mem_chunk_new("iap_conversation", sizeof(iap_conversation_t),
1936 10 * sizeof(iap_conversation_t), G_ALLOC_AND_FREE);
1937 lmp_conv_chunk = g_mem_chunk_new("lmp_conversation", sizeof(lmp_conversation_t),
1938 10 * sizeof(lmp_conversation_t), G_ALLOC_AND_FREE);
1943 * Register the protocol with Wireshark
1944 * This format is required because a script is used to build the C function
1945 * that calls all the protocol registrations.
1947 void proto_register_irda(void)
1951 /* Setup list of header fields */
1952 static hf_register_info hf_lap[] = {
1954 { "Address Field", "irlap.a",
1955 FT_UINT8, BASE_HEX, NULL, 0,
1958 { "C/R", "irlap.a.cr",
1959 FT_BOOLEAN, 8, TFS(&lap_cr_vals), CMD_FRAME,
1961 { &hf_lap_a_address,
1962 { "Address", "irlap.a.address",
1963 FT_UINT8, BASE_HEX, NULL, ~CMD_FRAME,
1966 { "Control Field", "irlap.c",
1967 FT_UINT8, BASE_HEX, NULL, 0,
1970 { "N(R)", "irlap.c.n_r",
1971 FT_UINT8, BASE_DEC, NULL, XDLC_N_R_MASK,
1974 { "N(S)", "irlap.c.n_s",
1975 FT_UINT8, BASE_DEC, NULL, XDLC_N_S_MASK,
1978 { "Poll", "irlap.c.p",
1979 FT_BOOLEAN, 8, TFS(&set_notset), XDLC_P_F,
1982 { "Final", "irlap.c.f",
1983 FT_BOOLEAN, 8, TFS(&set_notset), XDLC_P_F,
1986 { "Supervisory frame type", "irlap.c.s_ftype",
1987 FT_UINT8, BASE_HEX, VALS(lap_c_s_vals), XDLC_S_FTYPE_MASK,
1990 { "Command", "irlap.c.u_modifier_cmd",
1991 FT_UINT8, BASE_HEX, VALS(lap_c_u_cmd_vals), XDLC_U_MODIFIER_MASK,
1994 { "Response", "irlap.c.u_modifier_resp",
1995 FT_UINT8, BASE_HEX, VALS(lap_c_u_rsp_vals), XDLC_U_MODIFIER_MASK,
1998 { "Frame Type", "irlap.c.ftype",
1999 FT_UINT8, BASE_HEX, VALS(lap_c_ftype_vals), XDLC_I_MASK,
2002 { "Frame Type", "irlap.c.ftype",
2003 FT_UINT8, BASE_HEX, VALS(lap_c_ftype_vals), XDLC_S_U_MASK,
2006 { "Information Field", "irlap.i",
2007 FT_NONE, BASE_NONE, NULL, 0,
2010 { "Source Device Address", "irlap.snrm.saddr",
2011 FT_UINT32, BASE_HEX, NULL, 0,
2014 { "Destination Device Address", "irlap.snrm.daddr",
2015 FT_UINT32, BASE_HEX, NULL, 0,
2018 { "Connection Address", "irlap.snrm.ca",
2019 FT_UINT8, BASE_HEX, NULL, 0,
2021 { &hf_negotiation_param,
2022 { "Negotiation Parameter", "irlap.negotiation",
2023 FT_NONE, BASE_NONE, NULL, 0,
2026 { "Parameter Identifier", "irlap.pi",
2027 FT_UINT8, BASE_HEX, NULL, 0,
2030 { "Parameter Length", "irlap.pl",
2031 FT_UINT8, BASE_HEX, NULL, 0,
2034 { "Parameter Value", "irlap.pv",
2035 FT_BYTES, BASE_HEX, NULL, 0,
2038 { "Source Device Address", "irlap.ua.saddr",
2039 FT_UINT32, BASE_HEX, NULL, 0,
2042 { "Destination Device Address", "irlap.ua.daddr",
2043 FT_UINT32, BASE_HEX, NULL, 0,
2046 { "Format Identifier", "irlap.xid.fi",
2047 FT_UINT8, BASE_HEX, NULL, 0,
2050 { "Source Device Address", "irlap.xid.saddr",
2051 FT_UINT32, BASE_HEX, NULL, 0,
2054 { "Destination Device Address", "irlap.xid.daddr",
2055 FT_UINT32, BASE_HEX, NULL, 0,
2058 { "Discovery Flags", "irlap.xid.flags",
2059 FT_UINT8, BASE_HEX, NULL, 0,
2062 { "Number of Slots", "irlap.xid.s",
2063 FT_UINT8, BASE_DEC, VALS(&xid_slot_numbers), S_MASK,
2066 { "Conflict", "irlap.xid.conflict",
2067 FT_BOOLEAN, 8, TFS(&set_notset), CONFLICT,
2070 { "Slot Number", "irlap.xid.slotnr",
2071 FT_UINT8, BASE_DEC, NULL, 0,
2074 { "Version Number", "irlap.xid.version",
2075 FT_UINT8, BASE_HEX, NULL, 0,
2079 static hf_register_info hf_log[] = {
2081 { "Message", "log.msg",
2082 FT_STRING, BASE_NONE, NULL, 0,
2085 { "WARNING: Missed one or more messages while capturing!", "log.missed",
2086 FT_NONE, BASE_NONE, NULL, 0,
2090 static hf_register_info hf_lmp[] = {
2091 { &hf_lmp_xid_hints,
2092 { "Service Hints", "irlmp.xid.hints",
2093 FT_BYTES, BASE_HEX, NULL, 0,
2095 { &hf_lmp_xid_charset,
2096 { "Character Set", "irlmp.xid.charset",
2097 FT_UINT8, BASE_HEX, NULL, 0,
2100 { "Device Nickname", "irlmp.xid.name",
2101 FT_STRING, BASE_NONE, NULL, 0,
2103 { &hf_lmp_xid_name_no_ascii,
2104 { "Device Nickname (unsupported character set)", "irlmp.xid.name",
2105 FT_BYTES, BASE_NONE, NULL, 0,
2108 { "Destination", "irlmp.dst",
2109 FT_UINT8, BASE_HEX, NULL, 0,
2111 { &hf_lmp_dst_control,
2112 { "Control Bit", "irlmp.dst.c",
2113 FT_BOOLEAN, 8, TFS(&set_notset), CONTROL_BIT,
2116 { "Destination LSAP", "irlmp.dst.lsap",
2117 FT_UINT8, BASE_DEC, NULL, ~CONTROL_BIT,
2120 { "Source", "irlmp.src",
2121 FT_UINT8, BASE_HEX, NULL, 0,
2124 { "reserved", "irlmp.src.r",
2125 FT_UINT8, BASE_DEC, NULL, RESERVED_BIT,
2128 { "Source LSAP", "irlmp.src.lsap",
2129 FT_UINT8, BASE_DEC, NULL, ~RESERVED_BIT,
2132 { "Opcode", "irlmp.opcode",
2133 FT_UINT8, BASE_HEX, VALS(lmp_opcode_vals), 0x0,
2136 { "Reserved", "irlmp.rsvd",
2137 FT_UINT8, BASE_HEX, NULL, 0x0,
2140 { "Reason", "irlmp.reason",
2141 FT_UINT8, BASE_HEX, VALS(lmp_reason_vals), 0x0,
2144 { "Mode", "irlmp.mode",
2145 FT_UINT8, BASE_HEX, VALS(lmp_mode_vals), 0x0,
2148 { "Status", "irlmp.status",
2149 FT_UINT8, BASE_HEX, VALS(lmp_status_vals), 0x0,
2153 static hf_register_info hf_iap[] = {
2155 { "Control Field", "iap.ctl",
2156 FT_UINT8, BASE_HEX, NULL, 0,
2159 { "Last Frame", "iap.ctl.lst",
2160 FT_BOOLEAN, 8, TFS(&set_notset), IAP_LST,
2163 { "Acknowledge", "iap.ctl.ack",
2164 FT_BOOLEAN, 8, TFS(&set_notset), IAP_ACK,
2166 { &hf_iap_ctl_opcode,
2167 { "Opcode", "iap.ctl.opcode",
2168 FT_UINT8, BASE_HEX, VALS(iap_opcode_vals), IAP_OP,
2170 { &hf_iap_class_name,
2171 { "Class Name", "iap.classname",
2172 FT_UINT_STRING, BASE_NONE, NULL, 0x0,
2174 { &hf_iap_attr_name,
2175 { "Attribute Name", "iap.attrname",
2176 FT_UINT_STRING, BASE_NONE, NULL, 0x0,
2179 { "Return", "iap.return",
2180 FT_UINT8, BASE_HEX, VALS(iap_return_vals), 0x0,
2183 { "List Length", "iap.listlen",
2184 FT_UINT16, BASE_DEC, NULL, 0x0,
2186 { &hf_iap_list_entry,
2187 { "List Entry ", "iap.listentry",
2188 FT_NONE, BASE_NONE, NULL, 0x0,
2191 { "Object Identifier", "iap.objectid",
2192 FT_UINT16, BASE_HEX, NULL, 0x0,
2194 { &hf_iap_attr_type,
2195 { "Type", "iap.attrtype",
2196 FT_UINT8, BASE_DEC, VALS(iap_attr_type_vals), 0x0,
2199 { "Value", "iap.int",
2200 FT_INT32, BASE_DEC, NULL, 0x0,
2203 { "Sequence Length", "iap.seqlen",
2204 FT_UINT16, BASE_DEC, NULL, 0x0,
2207 { "Sequence", "iap.octseq",
2208 FT_BYTES, BASE_HEX, NULL, 0x0,
2211 { "Character Set", "iap.charset",
2212 FT_UINT8, BASE_HEX, NULL, 0x0,
2215 { "String", "iap.string",
2216 FT_UINT_STRING, BASE_NONE, NULL, 0x0,
2218 { &hf_iap_invaloctet,
2219 { "Mailformed IAP result: \"", "iap.invaloctet",
2220 FT_NONE, BASE_NONE, NULL, 0,
2222 { &hf_iap_invallsap,
2223 { "Mailformed IAP result: \"", "iap.invallsap",
2224 FT_NONE, BASE_NONE, NULL, 0,
2228 static hf_register_info hf_ttp[] = {
2230 { "Parameter Bit", "ttp.p",
2231 FT_BOOLEAN, 8, TFS(&set_notset), TTP_PARAMETERS,
2234 { "Initial Credit", "ttp.icredit",
2235 FT_UINT8, BASE_DEC, NULL, ~TTP_PARAMETERS,
2238 { "More Bit", "ttp.m",
2239 FT_BOOLEAN, 8, TFS(&set_notset), TTP_MORE,
2242 { "Delta Credit", "ttp.dcredit",
2243 FT_UINT8, BASE_DEC, NULL, ~TTP_MORE,
2247 /* Setup protocol subtree arrays */
2248 static gint* ett[] = {
2263 static gint* ett_p[MAX_PARAMETERS];
2264 static gint* ett_iap_e[MAX_IAP_ENTRIES];
2267 /* Register re-init routine */
2268 register_init_routine(init_irda);
2270 /* Register protocol names and descriptions */
2271 proto_irlap = proto_register_protocol("IrDA Link Access Protocol", "IrLAP", "irlap");
2272 proto_log = proto_register_protocol("Log Message", "Log", "log");
2273 proto_irlmp = proto_register_protocol("IrDA Link Management Protocol", "IrLMP", "irlmp");
2274 proto_iap = proto_register_protocol("Information Access Protocol", "IAP", "iap");
2275 proto_ttp = proto_register_protocol("Tiny Transport Protocol", "TTP", "ttp");
2277 /* Register the dissector */
2278 register_dissector("irda", dissect_irda, proto_irlap);
2280 /* Required function calls to register the header fields */
2281 proto_register_field_array(proto_irlap, hf_lap, array_length(hf_lap));
2282 proto_register_field_array(proto_log, hf_log, array_length(hf_log));
2283 proto_register_field_array(proto_irlmp, hf_lmp, array_length(hf_lmp));
2284 proto_register_field_array(proto_iap, hf_iap, array_length(hf_iap));
2285 proto_register_field_array(proto_ttp, hf_ttp, array_length(hf_ttp));
2287 /* Register subtrees */
2288 proto_register_subtree_array(ett, array_length(ett));
2289 for (i = 0; i < MAX_PARAMETERS; i++)
2292 ett_p[i] = &ett_param[i];
2294 proto_register_subtree_array(ett_p, MAX_PARAMETERS);
2295 for (i = 0; i < MAX_IAP_ENTRIES; i++)
2297 ett_iap_entry[i] = -1;
2298 ett_iap_e[i] = &ett_iap_entry[i];
2300 proto_register_subtree_array(ett_iap_e, MAX_IAP_ENTRIES);
2304 /* If this dissector uses sub-dissector registration add a registration routine.
2305 This format is required because a script is used to find these routines and
2306 create the code that calls these routines.
2309 void proto_reg_handoff_irda(void)
2311 dissector_handle_t irda_handle;
2313 irda_handle = find_dissector("irda");
2314 dissector_add("wtap_encap", WTAP_ENCAP_IRDA, irda_handle);
2315 data_handle = find_dissector("data");