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.
37 #include <epan/packet.h>
38 #include <epan/conversation.h>
39 #include <epan/emem.h>
40 #include <epan/xdlc.h>
42 #include "irda-appl.h"
43 #include <epan/dissectors/packet-sll.h>
46 * This plugin dissects infrared data transmissions as defined by the IrDA
47 * specification (www.irda.org). See
49 * http://www.irda.org/standards/specifications.asp
51 * for various IrDA specifications.
53 * The plugin operates both offline with libpcap files and online on supported
54 * platforms. Live dissection is currently available for Linux-IrDA
55 * (irda.sourceforge.net) and for Windows if the Linux-IrDA port IrCOMM2k
56 * (www.ircomm2k.de) is installed.
63 /* Frame types and templates */
67 * XXX - the IrDA spec gives XID as 0x2c; HDLC (and other HDLC-derived
68 * protocolc) use 0xAC.
70 #define IRDA_XID_CMD 0x2c /* Exchange Station Identification */
72 #define CMD_FRAME 0x01
73 #define RSP_FRAME 0x00
79 /* Negotiation Parameters */
80 #define PI_BAUD_RATE 0x01
81 #define PI_MAX_TURN_TIME 0x82
82 #define PI_DATA_SIZE 0x83
83 #define PI_WINDOW_SIZE 0x84
84 #define PI_ADD_BOFS 0x85
85 #define PI_MIN_TURN_TIME 0x86
86 #define PI_LINK_DISC 0x08
93 /* IrLMP frame opcodes */
94 #define CONNECT_CMD 0x01
95 #define CONNECT_CNF 0x81
96 #define DISCONNECT 0x02
97 #define ACCESSMODE_CMD 0x03
98 #define ACCESSMODE_CNF 0x83
100 #define CONTROL_BIT 0x80
101 #define RESERVED_BIT 0x80
104 #define LSAP_MASK 0x7f
105 #define LSAP_IAS 0x00
106 #define LSAP_ANY 0xff
107 #define LSAP_MAX 0x6f /* 0x70-0x7f are reserved */
108 #define LSAP_CONNLESS 0x70 /* Connectionless LSAP, mostly used for Ultra */
116 #define GET_INFO_BASE 0x01
117 #define GET_OBJECTS 0x02
118 #define GET_VALUE 0x03
119 #define GET_VALUE_BY_CLASS 0x04
120 #define GET_OBJECT_INFO 0x05
121 #define GET_ATTRIB_NAMES 0x06
127 #define IAS_SUCCESS 0
128 #define IAS_CLASS_UNKNOWN 1
129 #define IAS_ATTRIB_UNKNOWN 2
130 #define IAS_ATTR_TOO_LONG 3
131 #define IAS_DISCONNECT 10
132 #define IAS_UNSUPPORTED 0xFF
139 #define TTP_PARAMETERS 0x80
140 #define TTP_MORE 0x80
142 static dissector_handle_t data_handle;
144 /* Initialize the protocol and registered fields */
145 static int proto_irlap = -1;
146 static int hf_lap_a = -1;
147 static int hf_lap_a_cr = -1;
148 static int hf_lap_a_address = -1;
149 static int hf_lap_c = -1;
150 static int hf_lap_c_nr = -1;
151 static int hf_lap_c_ns = -1;
152 static int hf_lap_c_p = -1;
153 static int hf_lap_c_f = -1;
154 static int hf_lap_c_s = -1;
155 static int hf_lap_c_u_cmd = -1;
156 static int hf_lap_c_u_rsp = -1;
157 static int hf_lap_c_i = -1;
158 static int hf_lap_c_s_u = -1;
159 static int hf_lap_i = -1;
160 static int hf_snrm_saddr = -1;
161 static int hf_snrm_daddr = -1;
162 static int hf_snrm_ca = -1;
163 static int hf_ua_saddr = -1;
164 static int hf_ua_daddr = -1;
165 static int hf_negotiation_param = -1;
166 static int hf_param_pi = -1;
167 static int hf_param_pl = -1;
168 static int hf_param_pv = -1;
169 static int hf_xid_ident = -1;
170 static int hf_xid_saddr = -1;
171 static int hf_xid_daddr = -1;
172 static int hf_xid_flags = -1;
173 static int hf_xid_s = -1;
174 static int hf_xid_conflict = -1;
175 static int hf_xid_slotnr = -1;
176 static int hf_xid_version = -1;
178 static int proto_irlmp = -1;
179 static int hf_lmp_xid_hints = -1;
180 static int hf_lmp_xid_charset = -1;
181 static int hf_lmp_xid_name = -1;
182 static int hf_lmp_xid_name_no_ascii = -1;
183 static int hf_lmp_dst = -1;
184 static int hf_lmp_dst_control = -1;
185 static int hf_lmp_dst_lsap = -1;
186 static int hf_lmp_src = -1;
187 static int hf_lmp_src_r = -1;
188 static int hf_lmp_src_lsap = -1;
189 static int hf_lmp_opcode = -1;
190 static int hf_lmp_rsvd = -1;
191 static int hf_lmp_reason = -1;
192 static int hf_lmp_mode = -1;
193 static int hf_lmp_status = -1;
195 static int proto_iap = -1;
196 static int hf_iap_ctl = -1;
197 static int hf_iap_ctl_lst = -1;
198 static int hf_iap_ctl_ack = -1;
199 static int hf_iap_ctl_opcode = -1;
200 static int hf_iap_class_name = -1;
201 static int hf_iap_attr_name = -1;
202 static int hf_iap_return = -1;
203 static int hf_iap_list_len = -1;
204 static int hf_iap_list_entry = -1;
205 static int hf_iap_obj_id = -1;
206 static int hf_iap_attr_type = -1;
207 static int hf_iap_int = -1;
208 static int hf_iap_seq_len = -1;
209 static int hf_iap_oct_seq = -1;
210 static int hf_iap_char_set = -1;
211 static int hf_iap_string = -1;
212 static int hf_iap_invaloctet = -1;
213 static int hf_iap_invallsap = -1;
215 static int proto_ttp = -1;
216 static int hf_ttp_p = -1;
217 static int hf_ttp_icredit = -1;
218 static int hf_ttp_m = -1;
219 static int hf_ttp_dcredit = -1;
221 static int proto_log = -1;
222 static int hf_log_msg = -1;
223 static int hf_log_missed = -1;
225 /* Initialize the subtree pointers */
226 static gint ett_irlap = -1;
227 static gint ett_lap_a = -1;
228 static gint ett_lap_c = -1;
229 static gint ett_lap_i = -1;
230 static gint ett_xid_flags = -1;
231 static gint ett_log = -1;
232 static gint ett_irlmp = -1;
233 static gint ett_lmp_dst = -1;
234 static gint ett_lmp_src = -1;
235 static gint ett_iap = -1;
236 static gint ett_iap_ctl = -1;
237 static gint ett_ttp = -1;
239 #define MAX_PARAMETERS 32
240 static gint ett_param[MAX_PARAMETERS];
242 static gint ett_iap_entry[MAX_IAP_ENTRIES];
244 static const xdlc_cf_items irlap_cf_items = {
256 /* IAP conversation type */
257 typedef struct iap_conversation {
258 struct iap_conversation* pnext;
259 guint32 iap_query_frame;
260 ias_attr_dissector_t* pattr_dissector;
261 } iap_conversation_t;
263 /* IrLMP conversation type */
264 typedef struct lmp_conversation {
265 struct lmp_conversation* pnext;
266 guint32 iap_result_frame;
268 dissector_t proto_dissector;
269 } lmp_conversation_t;
271 static const true_false_string lap_cr_vals = {
276 static const true_false_string set_notset = {
281 static const value_string lap_c_ftype_vals[] = {
282 { XDLC_I, "Information frame" },
283 { XDLC_S, "Supervisory frame" },
284 { XDLC_U, "Unnumbered frame" },
288 static const value_string lap_c_u_cmd_abbr_vals[] = {
289 { XDLC_SNRM, "SNRM" },
290 { XDLC_DISC, "DISC" },
292 { IRDA_XID_CMD, "XID" },
293 { XDLC_TEST, "TEST" },
297 static const value_string lap_c_u_rsp_abbr_vals[] = {
298 { XDLC_SNRM, "RNRM" },
300 { XDLC_FRMR, "FRMR" },
305 { XDLC_TEST, "TEST" },
309 static const value_string lap_c_u_cmd_vals[] = {
310 { XDLC_SNRM>>2, "Set Normal Response Mode" },
311 { XDLC_DISC>>2, "Disconnect" },
312 { XDLC_UI>>2, "Unnumbered Information" },
313 { IRDA_XID_CMD>>2, "Exchange Station Identification" },
314 { XDLC_TEST>>2, "Test" },
318 static const value_string lap_c_u_rsp_vals[] = {
319 { XDLC_SNRM>>2, "Request Normal Response Mode" },
320 { XDLC_UA>>2, "Unnumbered Acknowledge" },
321 { XDLC_FRMR>>2, "Frame Reject" },
322 { XDLC_DM>>2, "Disconnect Mode" },
323 { XDLC_RD>>2, "Request Disconnect" },
324 { XDLC_UI>>2, "Unnumbered Information" },
325 { XDLC_XID>>2, "Exchange Station Identification" },
326 { XDLC_TEST>>2, "Test" },
330 static const value_string lap_c_s_vals[] = {
331 { XDLC_RR>>2, "Receiver ready" },
332 { XDLC_RNR>>2, "Receiver not ready" },
333 { XDLC_REJ>>2, "Reject" },
334 { XDLC_SREJ>>2, "Selective reject" },
338 static const value_string xid_slot_numbers[] = {
339 /* Number of XID slots */
347 static const value_string lmp_opcode_vals[] = {
348 /* IrLMP frame opcodes */
349 { CONNECT_CMD, "Connect Command" },
350 { CONNECT_CNF, "Connect Confirm" },
351 { DISCONNECT, "Disconnect" },
352 { ACCESSMODE_CMD, "Access Mode Command" },
353 { ACCESSMODE_CNF, "Access Mode Confirm" },
357 static const value_string lmp_reason_vals[] = {
358 /* IrLMP disconnect reasons */
359 { 0x01, "User Request" },
360 { 0x02, "Unexpected IrLAP Disconnect" },
361 { 0x03, "Failed to establish IrLAP connection" },
362 { 0x04, "IrLAP Reset" },
363 { 0x05, "Link Management Initiated Disconnect" },
364 { 0x06, "Data delivered on disconnected LSAP-Connection"},
365 { 0x07, "Non Responsive LM-MUX Client" },
366 { 0x08, "No available LM-MUX Client" },
367 { 0x09, "Connection Half Open" },
368 { 0x0A, "Illegal Source Address" },
369 { 0xFF, "Unspecified Disconnect Reason" },
373 static const value_string lmp_mode_vals[] = {
375 { 0x00, "Multiplexed" },
376 { 0x01, "Exclusive" },
380 static const value_string lmp_status_vals[] = {
384 { 0xFF, "Unsupported" },
388 static const value_string iap_opcode_vals[] = {
390 { GET_INFO_BASE, "GetInfoBase" },
391 { GET_OBJECTS, "GetObjects" },
392 { GET_VALUE, "GetValue" },
393 { GET_VALUE_BY_CLASS, "GetValueByClass" },
394 { GET_OBJECT_INFO, "GetObjectInfo" },
395 { GET_ATTRIB_NAMES, "GetAttributeNames" },
399 static const value_string iap_return_vals[] = {
400 /* IrIAP Return-codes */
401 { IAS_SUCCESS, "Success" },
402 { IAS_CLASS_UNKNOWN, "Class/Object Unknown" },
403 { IAS_ATTRIB_UNKNOWN, "Attribute Unknown" },
404 { IAS_ATTR_TOO_LONG, "Attribute List Too Long" },
405 { IAS_DISCONNECT, "Disconnect (Linux-IrDA only)" },
406 { IAS_UNSUPPORTED, "Unsupported Optional Operation" },
410 static const value_string iap_attr_type_vals[] = {
411 /* LM-IAS Attribute types */
412 { IAS_MISSING, "Missing" },
413 { IAS_INTEGER, "Integer" },
414 { IAS_OCT_SEQ, "Octet Sequence" },
415 { IAS_STRING, "String" },
419 static ias_attr_dissector_t device_attr_dissector[] = {
420 /* Device attribute dissectors */
421 /* { "IrLMPSupport", xxx }, not implemented yet... */
425 /* IAS class dissectors */
426 static ias_class_dissector_t class_dissector[] = { CLASS_DISSECTORS };
430 * Dissect parameter tuple
432 unsigned dissect_param_tuple(tvbuff_t* tvb, proto_tree* tree, unsigned offset)
434 guint8 len = tvb_get_guint8(tvb, offset + 1);
437 proto_tree_add_item(tree, hf_param_pi, tvb, offset, 1, ENC_BIG_ENDIAN);
441 proto_tree_add_item(tree, hf_param_pl, tvb, offset, 1, ENC_BIG_ENDIAN);
447 proto_tree_add_item(tree, hf_param_pv, tvb, offset, len, ENC_NA);
458 static unsigned dissect_ttp(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root, gboolean data)
464 if (tvb_length(tvb) == 0)
467 /* Make entries in Protocol column on summary display */
468 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TTP");
470 head = tvb_get_guint8(tvb, offset);
472 g_snprintf(buf, 128, ", Credit=%d", head & ~TTP_PARAMETERS);
473 col_append_str(pinfo->cinfo, COL_INFO, buf);
477 /* create display subtree for the protocol */
478 proto_item* ti = proto_tree_add_item(root, proto_ttp, tvb, 0, -1, FALSE);
479 proto_tree* tree = proto_item_add_subtree(ti, ett_ttp);
483 proto_tree_add_item(tree, hf_ttp_m, tvb, offset, 1, ENC_BIG_ENDIAN);
484 proto_tree_add_item(tree, hf_ttp_dcredit, tvb, offset, 1, FALSE);
489 proto_tree_add_item(tree, hf_ttp_p, tvb, offset, 1, ENC_BIG_ENDIAN);
490 proto_tree_add_item(tree, hf_ttp_icredit, tvb, offset, 1, FALSE);
493 proto_item_set_len(tree, offset);
503 * Dissect IAP request
505 static void dissect_iap_request(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root)
514 conversation_t* conv;
515 iap_conversation_t* iap_conv;
518 if (tvb_length(tvb) == 0)
521 /* Make entries in Protocol column on summary display */
522 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IAP");
524 op = tvb_get_guint8(tvb, offset) & IAP_OP;
528 case GET_VALUE_BY_CLASS:
529 clen = MIN(tvb_get_guint8(tvb, offset + 1), 60);
530 alen = MIN(tvb_get_guint8(tvb, offset + 1 + 1 + clen), 60);
532 /* create conversation entry */
533 src = pinfo->circuit_id ^ CMD_FRAME;
534 srcaddr.type = AT_NONE;
536 srcaddr.data = (guint8*)&src;
538 destaddr.type = AT_NONE;
540 destaddr.data = (guint8*)&pinfo->circuit_id;
542 conv = find_conversation(pinfo->fd->num, &srcaddr, &destaddr, PT_NONE, pinfo->srcport, pinfo->destport, 0);
545 iap_conv = (iap_conversation_t*)conversation_get_proto_data(conv, proto_iap);
548 if (iap_conv->iap_query_frame == pinfo->fd->num)
553 if (iap_conv->pnext == NULL)
555 iap_conv->pnext = se_alloc(sizeof(iap_conversation_t));
556 iap_conv = iap_conv->pnext;
559 iap_conv = iap_conv->pnext;
564 conv = conversation_new(pinfo->fd->num, &srcaddr, &destaddr, PT_NONE, pinfo->srcport, pinfo->destport, 0);
565 iap_conv = se_alloc(sizeof(iap_conversation_t));
566 conversation_add_proto_data(conv, proto_iap, (void*)iap_conv);
569 /* Dissect IAP query if it is new */
573 char class_name[256];
577 iap_conv->pnext = NULL;
578 iap_conv->iap_query_frame = pinfo->fd->num;
579 iap_conv->pattr_dissector = NULL;
581 tvb_memcpy(tvb, class_name, offset + 1 + 1, clen);
582 class_name[clen] = 0;
583 tvb_memcpy(tvb, attr_name, offset + 1 + 1 + clen + 1, alen);
586 /* Find the attribute dissector */
587 for (i = 0; class_dissector[i].class_name != NULL; i++)
588 if (strcmp(class_name, class_dissector[i].class_name) == 0)
590 for (j = 0; class_dissector[i].pattr_dissector[j].attr_name != NULL; j++)
591 if (strcmp(attr_name, class_dissector[i].pattr_dissector[j].attr_name) == 0)
593 iap_conv->pattr_dissector = &class_dissector[i].pattr_dissector[j];
600 col_add_str(pinfo->cinfo, COL_INFO, "GetValueByClass: \"");
602 tvb_memcpy(tvb, buf, offset + 1 + 1, clen);
603 memcpy(&buf[clen], "\" \"", 3);
604 tvb_memcpy(tvb, buf + clen + 3, offset + 1 + 1 + clen + 1, alen);
605 buf[clen + 3 + alen] = '\"';
606 buf[clen + 3 + alen + 1] = 0;
607 col_append_str(pinfo->cinfo, COL_INFO, buf);
612 /* create display subtree for the protocol */
613 proto_item* ti = proto_tree_add_item(root, proto_iap, tvb, 0, -1, FALSE);
614 proto_tree* tree = proto_item_add_subtree(ti, ett_iap);
616 proto_tree* ctl_tree;
619 ti = proto_tree_add_item(tree, hf_iap_ctl, tvb, offset, 1, ENC_BIG_ENDIAN);
620 ctl_tree = proto_item_add_subtree(ti, ett_iap_ctl);
621 proto_tree_add_item(ctl_tree, hf_iap_ctl_lst, tvb, offset, 1, ENC_BIG_ENDIAN);
622 proto_tree_add_item(ctl_tree, hf_iap_ctl_ack, tvb, offset, 1, ENC_BIG_ENDIAN);
623 proto_tree_add_item(ctl_tree, hf_iap_ctl_opcode, tvb, offset, 1, ENC_BIG_ENDIAN);
628 case GET_VALUE_BY_CLASS:
629 proto_tree_add_item(tree, hf_iap_class_name, tvb, offset, 1, ENC_BIG_ENDIAN);
632 proto_tree_add_item(tree, hf_iap_attr_name, tvb, offset, 1, ENC_BIG_ENDIAN);
642 case GET_VALUE_BY_CLASS:
643 offset += 1 + clen + 1 + alen;
648 /* If any bytes remain, send it to the generic data dissector */
649 tvb = tvb_new_subset_remaining(tvb, offset);
650 call_dissector(data_handle, tvb, pinfo, root);
657 static void dissect_iap_result(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root)
660 unsigned len = tvb_length(tvb);
671 conversation_t* conv;
672 iap_conversation_t* cur_iap_conv;
673 iap_conversation_t* iap_conv = NULL;
677 if (tvb_length(tvb) == 0)
680 /* Make entries in Protocol column on summary display */
681 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IAP");
683 op = tvb_get_guint8(tvb, offset) & IAP_OP;
684 retcode = tvb_get_guint8(tvb, offset + 1);
686 src = pinfo->circuit_id ^ CMD_FRAME;
687 srcaddr.type = AT_NONE;
689 srcaddr.data = (guint8*)&src;
691 destaddr.type = AT_NONE;
693 destaddr.data = (guint8*)&pinfo->circuit_id;
695 /* Find result value dissector */
696 conv = find_conversation(pinfo->fd->num, &srcaddr, &destaddr, PT_NONE, pinfo->srcport, pinfo->destport, 0);
699 num = pinfo->fd->num;
701 iap_conv = (iap_conversation_t*)conversation_get_proto_data(conv, proto_iap);
702 while (iap_conv && (iap_conv->iap_query_frame >= num))
703 iap_conv = iap_conv->pnext;
707 cur_iap_conv = iap_conv->pnext;
710 if ((cur_iap_conv->iap_query_frame < num) &&
711 (cur_iap_conv->iap_query_frame > iap_conv->iap_query_frame))
713 iap_conv = cur_iap_conv;
716 cur_iap_conv = cur_iap_conv->pnext;
721 col_set_str(pinfo->cinfo, COL_INFO, "Result: ");
722 col_append_str(pinfo->cinfo, COL_INFO, val_to_str(retcode, iap_return_vals, "0x%02X"));
726 case GET_VALUE_BY_CLASS:
730 switch (tvb_get_guint8(tvb, offset + 6))
733 g_snprintf(buf, 300, ", Missing");
737 g_snprintf(buf, 300, ", Integer: %d", tvb_get_ntohl(tvb, offset + 7));
741 g_snprintf(buf, 300, ", %d Octets", tvb_get_ntohs(tvb, offset + 7));
745 n = tvb_get_guint8(tvb, offset + 8);
746 string = tvb_get_ephemeral_string(tvb, offset + 9, n);
747 g_snprintf(buf, 300, ", \"%s\"", string);
750 col_append_str(pinfo->cinfo, COL_INFO, buf);
751 if (tvb_get_ntohs(tvb, offset + 2) > 1)
752 col_append_str(pinfo->cinfo, COL_INFO, ", ...");
759 /* create display subtree for the protocol */
760 proto_item* ti = proto_tree_add_item(root, proto_iap, tvb, 0, -1, FALSE);
761 proto_tree* tree = proto_item_add_subtree(ti, ett_iap);
763 proto_tree* ctl_tree;
764 proto_tree* entry_tree;
767 ti = proto_tree_add_item(tree, hf_iap_ctl, tvb, offset, 1, ENC_BIG_ENDIAN);
768 ctl_tree = proto_item_add_subtree(ti, ett_iap_ctl);
769 proto_tree_add_item(ctl_tree, hf_iap_ctl_lst, tvb, offset, 1, ENC_BIG_ENDIAN);
770 proto_tree_add_item(ctl_tree, hf_iap_ctl_ack, tvb, offset, 1, ENC_BIG_ENDIAN);
771 proto_tree_add_item(ctl_tree, hf_iap_ctl_opcode, tvb, offset, 1, ENC_BIG_ENDIAN);
774 proto_tree_add_item(tree, hf_iap_return, tvb, offset, 1, ENC_BIG_ENDIAN);
779 case GET_VALUE_BY_CLASS:
782 list_len = tvb_get_ntohs(tvb, offset);
784 proto_tree_add_item(tree, hf_iap_list_len, tvb, offset, 2, ENC_BIG_ENDIAN);
787 while ((offset < len) && (n < list_len))
789 type = tvb_get_guint8(tvb, offset + 2);
797 attr_len = tvb_get_ntohs(tvb, offset + 2 + 1) + 2;
801 attr_len = tvb_get_guint8(tvb, offset + 2 + 1 + 1) + 2;
808 ti = proto_tree_add_item(tree, hf_iap_list_entry, tvb, offset, 2 + 1 + attr_len, ENC_NA);
809 proto_item_append_text(ti, "%d", n + 1);
810 entry_tree = proto_item_add_subtree(ti, ett_iap_entry[n]);
812 proto_tree_add_item(entry_tree, hf_iap_obj_id, tvb, offset, 2, ENC_BIG_ENDIAN);
815 proto_tree_add_item(entry_tree, hf_iap_attr_type, tvb, offset, 1, ENC_BIG_ENDIAN);
821 if (!iap_conv || !iap_conv->pattr_dissector ||
822 !iap_conv->pattr_dissector->value_dissector(tvb, offset, pinfo, entry_tree,
824 proto_tree_add_item(entry_tree, hf_iap_int, tvb, offset, 4, ENC_BIG_ENDIAN);
828 proto_tree_add_item(entry_tree, hf_iap_seq_len, tvb, offset, 2, ENC_BIG_ENDIAN);
829 if (!iap_conv || !iap_conv->pattr_dissector ||
830 !iap_conv->pattr_dissector->value_dissector(tvb, offset, pinfo, entry_tree,
832 proto_tree_add_item(entry_tree, hf_iap_oct_seq, tvb, offset + 2,
833 attr_len - 2, ENC_NA);
837 proto_tree_add_item(entry_tree, hf_iap_char_set, tvb, offset, 1, ENC_BIG_ENDIAN);
838 if (!iap_conv || !iap_conv->pattr_dissector ||
839 !iap_conv->pattr_dissector->value_dissector(tvb, offset, pinfo, entry_tree,
841 proto_tree_add_item(entry_tree, hf_iap_string, tvb, offset + 1, 1, ENC_BIG_ENDIAN);
857 case GET_VALUE_BY_CLASS:
865 type = tvb_get_guint8(tvb, offset);
872 if (iap_conv && iap_conv->pattr_dissector)
873 iap_conv->pattr_dissector->value_dissector(tvb, offset, pinfo, 0,
878 attr_len = tvb_get_ntohs(tvb, offset) + 2;
879 if (iap_conv && iap_conv->pattr_dissector)
880 iap_conv->pattr_dissector->value_dissector(tvb, offset, pinfo, 0,
885 attr_len = tvb_get_guint8(tvb, offset + 1) + 2;
886 if (iap_conv && iap_conv->pattr_dissector)
887 iap_conv->pattr_dissector->value_dissector(tvb, offset, pinfo, 0,
903 /* If any bytes remain, send it to the generic data dissector */
904 tvb = tvb_new_subset_remaining(tvb, offset);
905 call_dissector(data_handle, tvb, pinfo, root);
910 * Check if IAP result is octet sequence
912 gboolean check_iap_octet_result(tvbuff_t* tvb, proto_tree* tree, unsigned offset,
913 const char* attr_name, guint8 attr_type)
915 if (attr_type != IAS_OCT_SEQ)
919 proto_item* ti = proto_tree_add_item(tree, hf_iap_invaloctet, tvb, offset, 0, FALSE);
920 proto_item_append_text(ti, "%s", attr_name);
921 proto_item_append_text(ti, "\" attribute must be octet sequence!");
932 * Check if IAP result is correct LsapSel
934 guint8 check_iap_lsap_result(tvbuff_t* tvb, proto_tree* tree, unsigned offset,
935 const char* attr_name, guint8 attr_type)
940 if ((attr_type != IAS_INTEGER) || ((lsap = tvb_get_ntohl(tvb, offset)) < 0x01) ||
945 proto_item* ti = proto_tree_add_item(tree, hf_iap_invallsap, tvb, offset, 0, FALSE);
946 proto_item_append_text(ti, "%s", attr_name);
947 proto_item_append_text(ti, "\" attribute must be integer value between 0x01 and 0x6F!");
958 * Dissect IrDA application protocol
960 static void dissect_appl_proto(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root, pdu_type_t pdu_type)
966 conversation_t* conv;
967 lmp_conversation_t* cur_lmp_conv;
968 lmp_conversation_t* lmp_conv = NULL;
972 src = pinfo->circuit_id ^ CMD_FRAME;
973 srcaddr.type = AT_NONE;
975 srcaddr.data = (guint8*)&src;
977 destaddr.type = AT_NONE;
979 destaddr.data = (guint8*)&pinfo->circuit_id;
981 /* Find result value dissector */
982 conv = find_conversation(pinfo->fd->num, &srcaddr, &destaddr, PT_NONE, pinfo->srcport, pinfo->destport, 0);
985 num = pinfo->fd->num;
987 lmp_conv = (lmp_conversation_t*)conversation_get_proto_data(conv, proto_irlmp);
988 while (lmp_conv && (lmp_conv->iap_result_frame >= num))
989 lmp_conv = lmp_conv->pnext;
993 cur_lmp_conv = lmp_conv->pnext;
996 if ((cur_lmp_conv->iap_result_frame < num) &&
997 (cur_lmp_conv->iap_result_frame > lmp_conv->iap_result_frame))
999 lmp_conv = cur_lmp_conv;
1002 cur_lmp_conv = cur_lmp_conv->pnext;
1009 /*g_message("%x:%d->%x:%d = %p\n", src, pinfo->srcport, pinfo->circuit_id, pinfo->destport, lmp_conv); */
1010 /*g_message("->%d: %d %d %p\n", pinfo->fd->num, lmp_conv->iap_result_frame, lmp_conv->ttp, lmp_conv->proto_dissector); */
1011 if ((lmp_conv->ttp) && (pdu_type != DISCONNECT_PDU))
1013 offset += dissect_ttp(tvb, pinfo, root, (pdu_type == DATA_PDU));
1015 tvb = tvb_new_subset_remaining(tvb, offset);
1018 pinfo->private_data = (void *)pdu_type;
1020 lmp_conv->proto_dissector(tvb, pinfo, root);
1023 call_dissector(data_handle, tvb, pinfo, root);
1030 static void dissect_irlmp(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root)
1032 unsigned offset = 0;
1039 /* Make entries in Protocol column on summary display */
1040 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IrLMP");
1042 dlsap = tvb_get_guint8(tvb, offset);
1043 cbit = dlsap & CONTROL_BIT;
1044 dlsap &= ~CONTROL_BIT;
1046 slsap = tvb_get_guint8(tvb, offset+1) & ~CONTROL_BIT;
1048 /* save Lsaps in pinfo */
1049 pinfo->srcport = slsap;
1050 pinfo->destport = dlsap;
1054 opcode = tvb_get_guint8(tvb, offset+2);
1056 col_add_fstr(pinfo->cinfo, COL_INFO, "%d > %d, ", slsap, dlsap);
1057 col_append_str(pinfo->cinfo, COL_INFO, val_to_str(opcode, lmp_opcode_vals, "0x%02X"));
1058 if ((opcode == ACCESSMODE_CMD) || (opcode == ACCESSMODE_CNF))
1060 col_append_str(pinfo->cinfo, COL_INFO, " (");
1061 col_append_str(pinfo->cinfo, COL_INFO,
1062 val_to_str(tvb_get_guint8(tvb, offset+4), lmp_mode_vals, "0x%02X"));
1063 col_append_str(pinfo->cinfo, COL_INFO, ")");
1067 col_add_fstr(pinfo->cinfo, COL_INFO, "%d > %d, Len=%d", slsap, dlsap,
1068 tvb_length(tvb) - 2);
1072 /* create display subtree for the protocol */
1073 proto_item* ti = proto_tree_add_item(root, proto_irlmp, tvb, 0, -1, FALSE);
1074 proto_tree* tree = proto_item_add_subtree(ti, ett_irlmp);
1076 proto_tree* dst_tree;
1077 proto_tree* src_tree;
1080 ti = proto_tree_add_item(tree, hf_lmp_dst, tvb, offset, 1, ENC_BIG_ENDIAN);
1081 dst_tree = proto_item_add_subtree(ti, ett_lmp_dst);
1082 proto_tree_add_item(dst_tree, hf_lmp_dst_control, tvb, offset, 1, ENC_BIG_ENDIAN);
1083 proto_tree_add_item(dst_tree, hf_lmp_dst_lsap, tvb, offset, 1, FALSE);
1086 ti = proto_tree_add_item(tree, hf_lmp_src, tvb, offset, 1, ENC_BIG_ENDIAN);
1087 src_tree = proto_item_add_subtree(ti, ett_lmp_src);
1088 proto_tree_add_item(src_tree, hf_lmp_src_r, tvb, offset, 1, ENC_BIG_ENDIAN);
1089 proto_tree_add_item(src_tree, hf_lmp_src_lsap, tvb, offset, 1, FALSE);
1094 proto_tree_add_item(tree, hf_lmp_opcode, tvb, offset, 1, ENC_BIG_ENDIAN);
1101 if (offset < tvb_length(tvb))
1103 proto_tree_add_item(tree, hf_lmp_rsvd, tvb, offset, 1, ENC_BIG_ENDIAN);
1109 proto_tree_add_item(tree, hf_lmp_reason, tvb, offset, 1, ENC_BIG_ENDIAN);
1113 case ACCESSMODE_CMD:
1114 proto_tree_add_item(tree, hf_lmp_rsvd, tvb, offset, 1, ENC_BIG_ENDIAN);
1117 proto_tree_add_item(tree, hf_lmp_mode, tvb, offset, 1, ENC_BIG_ENDIAN);
1121 case ACCESSMODE_CNF:
1122 proto_tree_add_item( tree, hf_lmp_status, tvb, offset, 1, ENC_BIG_ENDIAN);
1125 proto_tree_add_item(tree, hf_lmp_mode, tvb, offset, 1, ENC_BIG_ENDIAN);
1131 tvb = tvb_new_subset_remaining(tvb, offset);
1132 proto_item_set_len(tree, offset);
1145 if (offset < tvb_length(tvb))
1153 case ACCESSMODE_CMD:
1154 case ACCESSMODE_CNF:
1160 tvb = tvb_new_subset_remaining(tvb, offset);
1165 if (dlsap == LSAP_IAS)
1166 dissect_iap_request(tvb, pinfo, root);
1167 else if (slsap == LSAP_IAS)
1168 dissect_iap_result(tvb, pinfo, root);
1170 dissect_appl_proto(tvb, pinfo, root, DATA_PDU);
1174 if ((dlsap == LSAP_IAS) || (slsap == LSAP_IAS))
1175 call_dissector(data_handle, tvb, pinfo, root);
1181 dissect_appl_proto(tvb, pinfo, root, CONNECT_PDU);
1185 dissect_appl_proto(tvb, pinfo, root, DISCONNECT_PDU);
1189 call_dissector(data_handle, tvb, pinfo, root);
1196 * Add LMP conversation
1198 void add_lmp_conversation(packet_info* pinfo, guint8 dlsap, gboolean ttp, dissector_t proto_dissector)
1203 conversation_t* conv;
1204 lmp_conversation_t* lmp_conv = NULL;
1207 /*g_message("%d: add_lmp_conversation(%p, %d, %d, %p) = ", pinfo->fd->num, pinfo, dlsap, ttp, proto_dissector); */
1208 srcaddr.type = AT_NONE;
1210 srcaddr.data = (guint8*)&pinfo->circuit_id;
1212 dest = pinfo->circuit_id ^ CMD_FRAME;
1213 destaddr.type = AT_NONE;
1215 destaddr.data = (guint8*)&dest;
1217 conv = find_conversation(pinfo->fd->num, &destaddr, &srcaddr, PT_NONE, dlsap, 0, NO_PORT_B);
1220 lmp_conv = (lmp_conversation_t*)conversation_get_proto_data(conv, proto_irlmp);
1223 /* Does entry already exist? */
1224 if (lmp_conv->iap_result_frame == pinfo->fd->num)
1227 if (lmp_conv->pnext == NULL)
1229 lmp_conv->pnext = se_alloc(sizeof(lmp_conversation_t));
1230 lmp_conv = lmp_conv->pnext;
1233 lmp_conv = lmp_conv->pnext;
1238 conv = conversation_new(pinfo->fd->num, &destaddr, &srcaddr, PT_NONE, dlsap, 0, NO_PORT_B);
1239 lmp_conv = se_alloc(sizeof(lmp_conversation_t));
1240 conversation_add_proto_data(conv, proto_irlmp, (void*)lmp_conv);
1243 lmp_conv->pnext = NULL;
1244 lmp_conv->iap_result_frame = pinfo->fd->num;
1245 lmp_conv->ttp = ttp;
1246 lmp_conv->proto_dissector = proto_dissector;
1248 /*g_message("%p\n", lmp_conv); */
1253 * Dissect Negotiation Parameters
1255 static unsigned dissect_negotiation(tvbuff_t* tvb, proto_tree* tree, unsigned offset)
1263 while (tvb_reported_length_remaining(tvb, offset) > 0)
1265 guint8 p_len = tvb_get_guint8(tvb, offset + 1);
1269 ti = proto_tree_add_item(tree, hf_negotiation_param, tvb, offset, p_len + 2, ENC_NA);
1270 p_tree = proto_item_add_subtree(ti, ett_param[n]);
1272 pv = tvb_get_guint8(tvb, offset+2);
1275 switch (tvb_get_guint8(tvb, offset))
1278 proto_item_append_text(ti, ": Baud Rate (");
1281 g_strlcat(buf, ", 2400", 256);
1283 g_strlcat(buf, ", 9600", 256);
1285 g_strlcat(buf, ", 19200", 256);
1287 g_strlcat(buf, ", 38400", 256);
1289 g_strlcat(buf, ", 57600", 256);
1291 g_strlcat(buf, ", 115200", 256);
1293 g_strlcat(buf, ", 576000", 256);
1295 g_strlcat(buf, ", 1152000", 256);
1296 if ((p_len > 1) && (tvb_get_guint8(tvb, offset+3) & 0x01))
1297 g_strlcat(buf, ", 4000000", 256);
1299 g_strlcat(buf, " bps)", 256);
1301 proto_item_append_text(ti, "%s", buf+2);
1305 case PI_MAX_TURN_TIME:
1306 proto_item_append_text(ti, ": Maximum Turn Time (");
1309 g_strlcat(buf, ", 500", 256);
1311 g_strlcat(buf, ", 250", 256);
1313 g_strlcat(buf, ", 100", 256);
1315 g_strlcat(buf, ", 50", 256);
1317 g_strlcat(buf, " ms)", 256);
1319 proto_item_append_text(ti, "%s", buf+2);
1324 proto_item_append_text(ti, ": Data Size (");
1327 g_strlcat(buf, ", 64", 256);
1329 g_strlcat(buf, ", 128", 256);
1331 g_strlcat(buf, ", 256", 256);
1333 g_strlcat(buf, ", 512", 256);
1335 g_strlcat(buf, ", 1024", 256);
1337 g_strlcat(buf, ", 2048", 256);
1339 g_strlcat(buf, " bytes)", 256);
1341 proto_item_append_text(ti, "%s", buf+2);
1345 case PI_WINDOW_SIZE:
1346 proto_item_append_text(ti, ": Window Size (");
1349 g_strlcat(buf, ", 1", 256);
1351 g_strlcat(buf, ", 2", 256);
1353 g_strlcat(buf, ", 3", 256);
1355 g_strlcat(buf, ", 4", 256);
1357 g_strlcat(buf, ", 5", 256);
1359 g_strlcat(buf, ", 6", 256);
1361 g_strlcat(buf, ", 7", 256);
1363 g_strlcat(buf, " frame window)", 256);
1365 proto_item_append_text(ti, "%s", buf+2);
1370 proto_item_append_text(ti, ": Additional BOFs (");
1373 g_strlcat(buf, ", 48", 256);
1375 g_strlcat(buf, ", 24", 256);
1377 g_strlcat(buf, ", 12", 256);
1379 g_strlcat(buf, ", 5", 256);
1381 g_strlcat(buf, ", 3", 256);
1383 g_strlcat(buf, ", 2", 256);
1385 g_strlcat(buf, ", 1", 256);
1387 g_strlcat(buf, ", 0", 256);
1389 g_strlcat(buf, " additional BOFs at 115200)", 256);
1391 proto_item_append_text(ti, "%s", buf+2);
1395 case PI_MIN_TURN_TIME:
1396 proto_item_append_text(ti, ": Minimum Turn Time (");
1399 g_strlcat(buf, ", 10", 256);
1401 g_strlcat(buf, ", 5", 256);
1403 g_strlcat(buf, ", 1", 256);
1405 g_strlcat(buf, ", 0.5", 256);
1407 g_strlcat(buf, ", 0.1", 256);
1409 g_strlcat(buf, ", 0.05", 256);
1411 g_strlcat(buf, ", 0.01", 256);
1413 g_strlcat(buf, ", 0", 256);
1415 g_strlcat(buf, " ms)", 256);
1417 proto_item_append_text(ti, "%s", buf+2);
1422 proto_item_append_text(ti, ": Link Disconnect/Threshold Time (");
1425 g_strlcat(buf, ", 3/0", 256);
1427 g_strlcat(buf, ", 8/3", 256);
1429 g_strlcat(buf, ", 12/3", 256);
1431 g_strlcat(buf, ", 16/3", 256);
1433 g_strlcat(buf, ", 20/3", 256);
1435 g_strlcat(buf, ", 25/3", 256);
1437 g_strlcat(buf, ", 30/3", 256);
1439 g_strlcat(buf, ", 40/3", 256);
1441 g_strlcat(buf, " s)", 256);
1443 proto_item_append_text(ti, "%s", buf+2);
1448 proto_item_append_text(ti, ": unknown");
1453 offset = dissect_param_tuple(tvb, p_tree, offset);
1462 * Dissect XID packet
1464 static void dissect_xid(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root, proto_tree* lap_tree, gboolean is_command)
1467 proto_item* ti = NULL;
1468 proto_tree* i_tree = NULL;
1469 proto_tree* flags_tree;
1470 guint32 saddr, daddr;
1472 proto_tree* lmp_tree = NULL;
1476 ti = proto_tree_add_item(lap_tree, hf_lap_i, tvb, offset, -1, ENC_NA);
1477 i_tree = proto_item_add_subtree(ti, ett_lap_i);
1479 proto_tree_add_item(i_tree, hf_xid_ident, tvb, offset, 1, ENC_BIG_ENDIAN);
1483 saddr = tvb_get_letohl(tvb, offset);
1484 col_add_fstr(pinfo->cinfo, COL_DEF_SRC, "0x%08X", saddr);
1486 proto_tree_add_uint(i_tree, hf_xid_saddr, tvb, offset, 4, saddr);
1489 daddr = tvb_get_letohl(tvb, offset);
1490 col_add_fstr(pinfo->cinfo, COL_DEF_DST, "0x%08X", daddr);
1492 proto_tree_add_uint(i_tree, hf_xid_daddr, tvb, offset, 4, daddr);
1497 ti = proto_tree_add_item(i_tree, hf_xid_flags, tvb, offset, 1, ENC_BIG_ENDIAN);
1498 flags_tree = proto_item_add_subtree(ti, ett_xid_flags);
1499 proto_tree_add_item(flags_tree, hf_xid_s, tvb, offset, 1, ENC_BIG_ENDIAN);
1500 proto_tree_add_item(flags_tree, hf_xid_conflict, tvb, offset, 1, ENC_BIG_ENDIAN);
1506 s = tvb_get_guint8(tvb, offset);
1508 col_append_str(pinfo->cinfo, COL_INFO, ", s=final");
1510 col_append_fstr(pinfo->cinfo, COL_INFO, ", s=%u", s);
1513 ti = proto_tree_add_uint(i_tree, hf_xid_slotnr, tvb, offset, 1, s);
1515 proto_item_append_text(ti, " (final)");
1521 proto_tree_add_item(i_tree, hf_xid_version, tvb, offset, 1, ENC_BIG_ENDIAN);
1526 proto_item_set_end(lap_tree, tvb, offset);
1527 proto_item_set_end(i_tree, tvb, offset);
1530 if (tvb_reported_length_remaining(tvb, offset) > 0)
1539 ti = proto_tree_add_item(root, proto_irlmp, tvb, offset, -1, FALSE);
1540 lmp_tree = proto_item_add_subtree(ti, ett_irlmp);
1543 for (hints_len = 0;;)
1545 guint8 hint = tvb_get_guint8(tvb, offset + hints_len++);
1549 else if (hints_len == 2)
1552 if ((hint & 0x80) == 0)
1558 ti = proto_tree_add_item(lmp_tree, hf_lmp_xid_hints, tvb, offset, hints_len, ENC_NA);
1559 if ((hint1 | hint2) != 0)
1561 char service_hints[256];
1563 service_hints[0] = 0;
1566 g_strlcat(service_hints, ", PnP Compatible", 256);
1568 g_strlcat(service_hints, ", PDA/Palmtop", 256);
1570 g_strlcat(service_hints, ", Computer", 256);
1572 g_strlcat(service_hints, ", Printer", 256);
1574 g_strlcat(service_hints, ", Modem", 256);
1576 g_strlcat(service_hints, ", Fax", 256);
1578 g_strlcat(service_hints, ", LAN Access", 256);
1580 g_strlcat(service_hints, ", Telephony", 256);
1582 g_strlcat(service_hints, ", File Server", 256);
1584 g_strlcat(service_hints, ", IrCOMM", 256);
1586 g_strlcat(service_hints, ", OBEX", 256);
1588 g_strlcat(service_hints, ")", 256);
1589 service_hints[0] = ' ';
1590 service_hints[1] = '(';
1592 proto_item_append_text(ti, "%s", service_hints);
1595 offset += hints_len;
1597 if (tvb_reported_length_remaining(tvb, offset) > 0)
1602 cset = tvb_get_guint8(tvb, offset);
1604 proto_tree_add_uint(lmp_tree, hf_lmp_xid_charset, tvb, offset, 1, cset);
1606 name_len = tvb_reported_length_remaining(tvb, offset);
1614 tvb_memcpy(tvb, buf, offset, name_len);
1616 col_append_str(pinfo->cinfo, COL_INFO, ", \"");
1617 col_append_str(pinfo->cinfo, COL_INFO, buf);
1618 col_append_str(pinfo->cinfo, COL_INFO, "\"");
1620 proto_tree_add_item(lmp_tree, hf_lmp_xid_name, tvb, offset,
1626 proto_tree_add_item(lmp_tree, hf_lmp_xid_name_no_ascii, tvb, offset,
1636 * Dissect Log Messages
1638 static void dissect_log(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root)
1640 /* Make entries in Protocol column on summary display */
1641 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Log");
1643 /* missed messages? */
1644 if (pinfo->pseudo_header->irda.pkttype == IRDA_MISSED_MSG)
1646 col_set_str(pinfo->cinfo, COL_INFO, "WARNING: Missed one or more messages while capturing!");
1654 length = tvb_length(tvb);
1655 if (length > sizeof(buf)-1)
1656 length = sizeof(buf)-1;
1657 tvb_memcpy(tvb, buf, 0, length);
1659 if (buf[length-1] == '\n')
1661 else if (buf[length-2] == '\n')
1664 col_add_str(pinfo->cinfo, COL_INFO, buf);
1669 proto_item* ti = proto_tree_add_item(root, proto_log, tvb, 0, -1, FALSE);
1670 proto_tree* tree = proto_item_add_subtree(ti, ett_log);
1672 if (pinfo->pseudo_header->irda.pkttype == IRDA_MISSED_MSG)
1673 proto_tree_add_item(tree, hf_log_missed, tvb, 0, 0, FALSE);
1675 proto_tree_add_item(tree, hf_log_msg, tvb, 0, -1, FALSE);
1683 static void dissect_irlap(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root)
1687 gboolean is_response;
1689 proto_item* ti = NULL;
1690 proto_tree* tree = NULL;
1691 proto_tree* i_tree = NULL;
1692 guint32 saddr, daddr;
1695 /* Make entries in Protocol column on summary display */
1696 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IrLAP");
1698 /* Clear Info column */
1699 col_clear(pinfo->cinfo, COL_INFO);
1701 /* set direction column */
1702 switch (pinfo->pseudo_header->irda.pkttype)
1705 col_set_str(pinfo->cinfo, COL_IF_DIR, "Out");
1709 col_set_str(pinfo->cinfo, COL_IF_DIR, "In");
1713 /* decode values used for demuxing */
1714 a = tvb_get_guint8(tvb, 0);
1716 /* save connection address field in pinfo */
1717 pinfo->circuit_id = a;
1719 /* initially set address columns to connection address */
1720 g_snprintf(addr, sizeof(addr)-1, "0x%02X", a >> 1);
1721 col_add_str(pinfo->cinfo, COL_DEF_SRC, addr);
1722 col_add_str(pinfo->cinfo, COL_DEF_DST, addr);
1727 proto_item* addr_item;
1729 /* create display subtree for the protocol */
1730 ti = proto_tree_add_item(root, proto_irlap, tvb, 0, -1, FALSE);
1731 tree = proto_item_add_subtree(ti, ett_irlap);
1733 /* create subtree for the address field */
1734 ti = proto_tree_add_item(tree, hf_lap_a, tvb, offset, 1, ENC_BIG_ENDIAN);
1735 a_tree = proto_item_add_subtree(ti, ett_lap_a);
1736 proto_tree_add_item(a_tree, hf_lap_a_cr, tvb, offset, 1, ENC_BIG_ENDIAN);
1737 addr_item = proto_tree_add_item(a_tree, hf_lap_a_address, tvb, offset, 1, FALSE);
1738 switch (a & ~CMD_FRAME)
1741 proto_item_append_text(addr_item, " (NULL Address)");
1744 proto_item_append_text(addr_item, " (Broadcast)");
1748 is_response = ((a & CMD_FRAME) == 0);
1751 /* process the control field */
1752 c = dissect_xdlc_control(tvb, 1, pinfo, tree, hf_lap_c,
1753 ett_lap_c, &irlap_cf_items, NULL, lap_c_u_cmd_abbr_vals,
1754 lap_c_u_rsp_abbr_vals, is_response, FALSE, FALSE);
1757 if ((c & XDLC_I_MASK) == XDLC_I) {
1759 proto_item_set_len(tree, offset);
1760 tvb = tvb_new_subset_remaining(tvb, offset);
1761 dissect_irlmp(tvb, pinfo, root);
1765 if ((c & 0x03) == XDLC_U) {
1767 switch (c & XDLC_U_MODIFIER_MASK)
1772 ti = proto_tree_add_item(tree, hf_lap_i, tvb, offset, -1, ENC_NA);
1773 i_tree = proto_item_add_subtree(ti, ett_lap_i);
1776 saddr = tvb_get_letohl(tvb, offset);
1779 col_add_fstr(pinfo->cinfo, COL_DEF_SRC, "0x%08X", saddr);
1782 proto_tree_add_uint(i_tree, hf_snrm_saddr, tvb, offset, 4, saddr);
1785 daddr = tvb_get_letohl(tvb, offset);
1788 col_add_fstr(pinfo->cinfo, COL_DEF_DST, "0x%08X", daddr);
1791 proto_tree_add_uint(i_tree, hf_snrm_daddr, tvb, offset, 4, daddr);
1794 ca = tvb_get_guint8(tvb, offset);
1797 col_append_fstr(pinfo->cinfo, COL_INFO, ", ca=0x%02X",
1801 proto_tree_add_uint(i_tree, hf_snrm_ca, tvb, offset, 1, ca >> 1);
1804 offset = dissect_negotiation(tvb, i_tree, offset);
1806 proto_item_set_end(ti, tvb, offset);
1810 tvb = tvb_new_subset_remaining(tvb, offset);
1811 dissect_xid(tvb, pinfo, root, tree, TRUE);
1815 if (tvb_reported_length_remaining(tvb, offset) > 0)
1819 ti = proto_tree_add_item(tree, hf_lap_i, tvb, offset, -1, ENC_NA);
1820 i_tree = proto_item_add_subtree(ti, ett_lap_i);
1823 saddr = tvb_get_letohl(tvb, offset);
1824 col_add_fstr(pinfo->cinfo, COL_DEF_SRC, "0x%08X", saddr);
1826 proto_tree_add_uint(i_tree, hf_ua_saddr, tvb, offset, 4, saddr);
1829 daddr = tvb_get_letohl(tvb, offset);
1830 col_add_fstr(pinfo->cinfo, COL_DEF_DST, "0x%08X", daddr);
1832 proto_tree_add_uint(i_tree, hf_ua_daddr, tvb, offset, 4, daddr);
1835 offset = dissect_negotiation(tvb, i_tree, offset);
1837 proto_item_set_end(ti, tvb, offset);
1842 tvb = tvb_new_subset_remaining(tvb, offset);
1843 dissect_xid(tvb, pinfo, root, tree, FALSE);
1848 /* If any bytes remain, send it to the generic data dissector */
1849 if (tvb_reported_length_remaining(tvb, offset) > 0)
1851 tvb = tvb_new_subset_remaining(tvb, offset);
1852 call_dissector(data_handle, tvb, pinfo, root);
1858 * Dissect IrDA protocol
1860 static void dissect_irda(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root)
1862 /* load the display labels */
1863 pinfo->current_proto = "IrDA";
1865 /* check if log message */
1866 if ((pinfo->pseudo_header->irda.pkttype & IRDA_CLASS_MASK) == IRDA_CLASS_LOG)
1868 dissect_log(tvb, pinfo, root);
1873 dissect_irlap(tvb, pinfo, root);
1878 * Register the protocol with Wireshark
1879 * This format is required because a script is used to build the C function
1880 * that calls all the protocol registrations.
1882 void proto_register_irda(void)
1886 /* Setup list of header fields */
1887 static hf_register_info hf_lap[] = {
1889 { "Address Field", "irlap.a",
1890 FT_UINT8, BASE_HEX, NULL, 0,
1893 { "C/R", "irlap.a.cr",
1894 FT_BOOLEAN, 8, TFS(&lap_cr_vals), CMD_FRAME,
1896 { &hf_lap_a_address,
1897 { "Address", "irlap.a.address",
1898 FT_UINT8, BASE_HEX, NULL, ~CMD_FRAME,
1901 { "Control Field", "irlap.c",
1902 FT_UINT8, BASE_HEX, NULL, 0,
1905 { "N(R)", "irlap.c.n_r",
1906 FT_UINT8, BASE_DEC, NULL, XDLC_N_R_MASK,
1909 { "N(S)", "irlap.c.n_s",
1910 FT_UINT8, BASE_DEC, NULL, XDLC_N_S_MASK,
1913 { "Poll", "irlap.c.p",
1914 FT_BOOLEAN, 8, TFS(&set_notset), XDLC_P_F,
1917 { "Final", "irlap.c.f",
1918 FT_BOOLEAN, 8, TFS(&set_notset), XDLC_P_F,
1921 { "Supervisory frame type", "irlap.c.s_ftype",
1922 FT_UINT8, BASE_HEX, VALS(lap_c_s_vals), XDLC_S_FTYPE_MASK,
1925 { "Command", "irlap.c.u_modifier_cmd",
1926 FT_UINT8, BASE_HEX, VALS(lap_c_u_cmd_vals), XDLC_U_MODIFIER_MASK,
1929 { "Response", "irlap.c.u_modifier_resp",
1930 FT_UINT8, BASE_HEX, VALS(lap_c_u_rsp_vals), XDLC_U_MODIFIER_MASK,
1933 { "Frame Type", "irlap.c.ftype",
1934 FT_UINT8, BASE_HEX, VALS(lap_c_ftype_vals), XDLC_I_MASK,
1937 { "Frame Type", "irlap.c.ftype",
1938 FT_UINT8, BASE_HEX, VALS(lap_c_ftype_vals), XDLC_S_U_MASK,
1941 { "Information Field", "irlap.i",
1942 FT_NONE, BASE_NONE, NULL, 0,
1945 { "Source Device Address", "irlap.snrm.saddr",
1946 FT_UINT32, BASE_HEX, NULL, 0,
1949 { "Destination Device Address", "irlap.snrm.daddr",
1950 FT_UINT32, BASE_HEX, NULL, 0,
1953 { "Connection Address", "irlap.snrm.ca",
1954 FT_UINT8, BASE_HEX, NULL, 0,
1956 { &hf_negotiation_param,
1957 { "Negotiation Parameter", "irlap.negotiation",
1958 FT_NONE, BASE_NONE, NULL, 0,
1961 { "Parameter Identifier", "irlap.pi",
1962 FT_UINT8, BASE_HEX, NULL, 0,
1965 { "Parameter Length", "irlap.pl",
1966 FT_UINT8, BASE_HEX, NULL, 0,
1969 { "Parameter Value", "irlap.pv",
1970 FT_BYTES, BASE_NONE, NULL, 0,
1973 { "Source Device Address", "irlap.ua.saddr",
1974 FT_UINT32, BASE_HEX, NULL, 0,
1977 { "Destination Device Address", "irlap.ua.daddr",
1978 FT_UINT32, BASE_HEX, NULL, 0,
1981 { "Format Identifier", "irlap.xid.fi",
1982 FT_UINT8, BASE_HEX, NULL, 0,
1985 { "Source Device Address", "irlap.xid.saddr",
1986 FT_UINT32, BASE_HEX, NULL, 0,
1989 { "Destination Device Address", "irlap.xid.daddr",
1990 FT_UINT32, BASE_HEX, NULL, 0,
1993 { "Discovery Flags", "irlap.xid.flags",
1994 FT_UINT8, BASE_HEX, NULL, 0,
1997 { "Number of Slots", "irlap.xid.s",
1998 FT_UINT8, BASE_DEC, VALS(xid_slot_numbers), S_MASK,
2001 { "Conflict", "irlap.xid.conflict",
2002 FT_BOOLEAN, 8, TFS(&set_notset), CONFLICT,
2005 { "Slot Number", "irlap.xid.slotnr",
2006 FT_UINT8, BASE_DEC, NULL, 0,
2009 { "Version Number", "irlap.xid.version",
2010 FT_UINT8, BASE_HEX, NULL, 0,
2014 static hf_register_info hf_log[] = {
2016 { "Message", "log.msg",
2017 FT_STRING, BASE_NONE, NULL, 0,
2020 { "WARNING: Missed one or more messages while capturing!", "log.missed",
2021 FT_NONE, BASE_NONE, NULL, 0,
2025 static hf_register_info hf_lmp[] = {
2026 { &hf_lmp_xid_hints,
2027 { "Service Hints", "irlmp.xid.hints",
2028 FT_BYTES, BASE_NONE, NULL, 0,
2030 { &hf_lmp_xid_charset,
2031 { "Character Set", "irlmp.xid.charset",
2032 FT_UINT8, BASE_HEX, NULL, 0,
2035 { "Device Nickname", "irlmp.xid.name",
2036 FT_STRING, BASE_NONE, NULL, 0,
2038 { &hf_lmp_xid_name_no_ascii,
2039 { "Device Nickname (unsupported character set)", "irlmp.xid.name",
2040 FT_BYTES, BASE_NONE, NULL, 0,
2043 { "Destination", "irlmp.dst",
2044 FT_UINT8, BASE_HEX, NULL, 0,
2046 { &hf_lmp_dst_control,
2047 { "Control Bit", "irlmp.dst.c",
2048 FT_BOOLEAN, 8, TFS(&set_notset), CONTROL_BIT,
2051 { "Destination LSAP", "irlmp.dst.lsap",
2052 FT_UINT8, BASE_DEC, NULL, ~CONTROL_BIT,
2055 { "Source", "irlmp.src",
2056 FT_UINT8, BASE_HEX, NULL, 0,
2059 { "reserved", "irlmp.src.r",
2060 FT_UINT8, BASE_DEC, NULL, RESERVED_BIT,
2063 { "Source LSAP", "irlmp.src.lsap",
2064 FT_UINT8, BASE_DEC, NULL, ~RESERVED_BIT,
2067 { "Opcode", "irlmp.opcode",
2068 FT_UINT8, BASE_HEX, VALS(lmp_opcode_vals), 0x0,
2071 { "Reserved", "irlmp.rsvd",
2072 FT_UINT8, BASE_HEX, NULL, 0x0,
2075 { "Reason", "irlmp.reason",
2076 FT_UINT8, BASE_HEX, VALS(lmp_reason_vals), 0x0,
2079 { "Mode", "irlmp.mode",
2080 FT_UINT8, BASE_HEX, VALS(lmp_mode_vals), 0x0,
2083 { "Status", "irlmp.status",
2084 FT_UINT8, BASE_HEX, VALS(lmp_status_vals), 0x0,
2088 static hf_register_info hf_iap[] = {
2090 { "Control Field", "iap.ctl",
2091 FT_UINT8, BASE_HEX, NULL, 0,
2094 { "Last Frame", "iap.ctl.lst",
2095 FT_BOOLEAN, 8, TFS(&set_notset), IAP_LST,
2098 { "Acknowledge", "iap.ctl.ack",
2099 FT_BOOLEAN, 8, TFS(&set_notset), IAP_ACK,
2101 { &hf_iap_ctl_opcode,
2102 { "Opcode", "iap.ctl.opcode",
2103 FT_UINT8, BASE_HEX, VALS(iap_opcode_vals), IAP_OP,
2105 { &hf_iap_class_name,
2106 { "Class Name", "iap.classname",
2107 FT_UINT_STRING, BASE_NONE, NULL, 0x0,
2109 { &hf_iap_attr_name,
2110 { "Attribute Name", "iap.attrname",
2111 FT_UINT_STRING, BASE_NONE, NULL, 0x0,
2114 { "Return", "iap.return",
2115 FT_UINT8, BASE_HEX, VALS(iap_return_vals), 0x0,
2118 { "List Length", "iap.listlen",
2119 FT_UINT16, BASE_DEC, NULL, 0x0,
2121 { &hf_iap_list_entry,
2122 { "List Entry", "iap.listentry",
2123 FT_NONE, BASE_NONE, NULL, 0x0,
2126 { "Object Identifier", "iap.objectid",
2127 FT_UINT16, BASE_HEX, NULL, 0x0,
2129 { &hf_iap_attr_type,
2130 { "Type", "iap.attrtype",
2131 FT_UINT8, BASE_DEC, VALS(iap_attr_type_vals), 0x0,
2134 { "Value", "iap.int",
2135 FT_INT32, BASE_DEC, NULL, 0x0,
2138 { "Sequence Length", "iap.seqlen",
2139 FT_UINT16, BASE_DEC, NULL, 0x0,
2142 { "Sequence", "iap.octseq",
2143 FT_BYTES, BASE_NONE, NULL, 0x0,
2146 { "Character Set", "iap.charset",
2147 FT_UINT8, BASE_HEX, NULL, 0x0,
2150 { "String", "iap.string",
2151 FT_UINT_STRING, BASE_NONE, NULL, 0x0,
2153 { &hf_iap_invaloctet,
2154 { "Malformed IAP result: \"", "iap.invaloctet",
2155 FT_NONE, BASE_NONE, NULL, 0,
2157 { &hf_iap_invallsap,
2158 { "Malformed IAP result: \"", "iap.invallsap",
2159 FT_NONE, BASE_NONE, NULL, 0,
2163 static hf_register_info hf_ttp[] = {
2165 { "Parameter Bit", "ttp.p",
2166 FT_BOOLEAN, 8, TFS(&set_notset), TTP_PARAMETERS,
2169 { "Initial Credit", "ttp.icredit",
2170 FT_UINT8, BASE_DEC, NULL, ~TTP_PARAMETERS,
2173 { "More Bit", "ttp.m",
2174 FT_BOOLEAN, 8, TFS(&set_notset), TTP_MORE,
2177 { "Delta Credit", "ttp.dcredit",
2178 FT_UINT8, BASE_DEC, NULL, ~TTP_MORE,
2182 /* Setup protocol subtree arrays */
2183 static gint* ett[] = {
2198 gint* ett_p[MAX_PARAMETERS];
2199 gint* ett_iap_e[MAX_IAP_ENTRIES];
2202 /* Register protocol names and descriptions */
2203 proto_irlap = proto_register_protocol("IrDA Link Access Protocol", "IrLAP", "irlap");
2204 proto_log = proto_register_protocol("Log Message", "Log", "log");
2205 proto_irlmp = proto_register_protocol("IrDA Link Management Protocol", "IrLMP", "irlmp");
2206 proto_iap = proto_register_protocol("Information Access Protocol", "IAP", "iap");
2207 proto_ttp = proto_register_protocol("Tiny Transport Protocol", "TTP", "ttp");
2209 /* Register the dissector */
2210 register_dissector("irda", dissect_irda, proto_irlap);
2212 /* Required function calls to register the header fields */
2213 proto_register_field_array(proto_irlap, hf_lap, array_length(hf_lap));
2214 proto_register_field_array(proto_log, hf_log, array_length(hf_log));
2215 proto_register_field_array(proto_irlmp, hf_lmp, array_length(hf_lmp));
2216 proto_register_field_array(proto_iap, hf_iap, array_length(hf_iap));
2217 proto_register_field_array(proto_ttp, hf_ttp, array_length(hf_ttp));
2219 /* Register subtrees */
2220 proto_register_subtree_array(ett, array_length(ett));
2221 for (i = 0; i < MAX_PARAMETERS; i++)
2224 ett_p[i] = &ett_param[i];
2226 proto_register_subtree_array(ett_p, MAX_PARAMETERS);
2227 for (i = 0; i < MAX_IAP_ENTRIES; i++)
2229 ett_iap_entry[i] = -1;
2230 ett_iap_e[i] = &ett_iap_entry[i];
2232 proto_register_subtree_array(ett_iap_e, MAX_IAP_ENTRIES);
2236 /* If this dissector uses sub-dissector registration add a registration routine.
2237 This format is required because a script is used to find these routines and
2238 create the code that calls these routines.
2241 void proto_reg_handoff_irda(void)
2243 dissector_handle_t irda_handle;
2245 irda_handle = find_dissector("irda");
2246 dissector_add_uint("wtap_encap", WTAP_ENCAP_IRDA, irda_handle);
2247 dissector_add_uint("sll.ltype", LINUX_SLL_P_IRDA_LAP, irda_handle);
2248 data_handle = find_dissector("data");