2006-05-27 06:10:52 +00:00
|
|
|
/* TODO mix direction bit into the chandle tree lookup so we can handle when fragments sent in both directions simultaneously on the same chandle */
|
|
|
|
|
2006-05-14 10:18:29 +00:00
|
|
|
/* packet-btacl_acl.c
|
|
|
|
* Routines for the Bluetooth ACL dissection
|
|
|
|
* Copyright 2002, Christoph Scholz <scholz@cs.uni-bonn.de>
|
|
|
|
* From: http://affix.sourceforge.net/archive/ethereal_affix-3.patch
|
|
|
|
*
|
2006-05-21 04:49:01 +00:00
|
|
|
* Refactored for wireshark checkin
|
2006-05-14 10:18:29 +00:00
|
|
|
* Ronnie Sahlberg 2006
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
2006-05-21 04:49:01 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2006-05-14 10:18:29 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2008-04-29 15:20:19 +00:00
|
|
|
*
|
2006-05-14 10:18:29 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2008-04-29 15:20:19 +00:00
|
|
|
*
|
2006-05-14 10:18:29 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <epan/packet.h>
|
2006-05-26 08:30:56 +00:00
|
|
|
#include <epan/emem.h>
|
2006-05-27 06:10:52 +00:00
|
|
|
#include <epan/prefs.h>
|
2006-05-14 10:18:29 +00:00
|
|
|
#include <etypes.h>
|
|
|
|
#include <packet-hci_h4.h>
|
2006-05-26 08:30:56 +00:00
|
|
|
#include <packet-bthci_acl.h>
|
2006-05-14 10:18:29 +00:00
|
|
|
|
|
|
|
/* Initialize the protocol and registered fields */
|
|
|
|
static int proto_btacl = -1;
|
|
|
|
static int hf_btacl_chandle = -1;
|
|
|
|
static int hf_btacl_pb_flag = -1;
|
|
|
|
static int hf_btacl_bc_flag = -1;
|
|
|
|
static int hf_btacl_length = -1;
|
|
|
|
static int hf_btacl_data = -1;
|
2006-05-27 06:10:52 +00:00
|
|
|
static int hf_btacl_continuation_to = -1;
|
|
|
|
static int hf_btacl_reassembled_in = -1;
|
2006-05-14 10:18:29 +00:00
|
|
|
|
|
|
|
/* Initialize the subtree pointers */
|
|
|
|
static gint ett_btacl = -1;
|
|
|
|
|
2006-12-07 20:34:08 +00:00
|
|
|
static dissector_handle_t btl2cap_handle=NULL;
|
2006-05-14 10:18:29 +00:00
|
|
|
|
2006-05-27 06:10:52 +00:00
|
|
|
static gboolean acl_reassembly = TRUE;
|
|
|
|
|
|
|
|
typedef struct _multi_fragment_pdu_t {
|
|
|
|
guint32 first_frame;
|
|
|
|
guint32 last_frame;
|
|
|
|
guint16 tot_len;
|
|
|
|
char *reassembled;
|
|
|
|
int cur_off; /* counter used by reassembly */
|
|
|
|
} multi_fragment_pdu_t;
|
|
|
|
|
|
|
|
typedef struct _chandle_data_t {
|
2006-08-14 08:29:29 +00:00
|
|
|
emem_tree_t *start_fragments; /* indexed by pinfo->fd->num */
|
2006-05-27 06:10:52 +00:00
|
|
|
} chandle_data_t;
|
|
|
|
|
2006-08-14 08:29:29 +00:00
|
|
|
static emem_tree_t *chandle_tree=NULL;
|
2006-05-27 06:10:52 +00:00
|
|
|
|
2006-05-14 10:18:29 +00:00
|
|
|
static const value_string pb_flag_vals[] = {
|
2009-11-05 07:36:02 +00:00
|
|
|
{0, "First Non-automatically Flushable Packet"},
|
|
|
|
{1, "Continuing Fragment"},
|
|
|
|
{2, "First Automatically Flushable Packet"},
|
2006-05-14 10:18:29 +00:00
|
|
|
{0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const value_string bc_flag_vals[] = {
|
|
|
|
{0, "Point-To-Point"},
|
|
|
|
{1, "Active Broadcast"},
|
|
|
|
{2, "Piconet Broadcast"},
|
|
|
|
{0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Code to actually dissect the packets */
|
2008-04-29 15:20:19 +00:00
|
|
|
static void
|
2006-05-14 10:18:29 +00:00
|
|
|
dissect_btacl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|
|
|
{
|
|
|
|
proto_item *ti=NULL;
|
|
|
|
proto_tree *btacl_tree=NULL;
|
|
|
|
guint16 flags, length;
|
|
|
|
gboolean fragmented;
|
|
|
|
int offset=0;
|
2006-05-27 06:10:52 +00:00
|
|
|
guint16 pb_flag, l2cap_length=0;
|
2006-05-14 10:18:29 +00:00
|
|
|
tvbuff_t *next_tvb;
|
2006-05-26 08:30:56 +00:00
|
|
|
bthci_acl_data_t *acl_data;
|
2006-05-27 06:10:52 +00:00
|
|
|
chandle_data_t *chandle_data;
|
2009-05-19 17:16:14 +00:00
|
|
|
void* pd_save;
|
2006-05-14 10:18:29 +00:00
|
|
|
|
2009-08-09 07:59:51 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "HCI_ACL");
|
2006-05-14 10:18:29 +00:00
|
|
|
|
|
|
|
if(tree){
|
2011-09-26 08:25:18 +00:00
|
|
|
ti=proto_tree_add_item(tree, proto_btacl, tvb, offset, -1, ENC_BIG_ENDIAN);
|
2006-05-14 10:18:29 +00:00
|
|
|
btacl_tree = proto_item_add_subtree(ti, ett_btacl);
|
|
|
|
}
|
|
|
|
|
|
|
|
flags=tvb_get_letohs(tvb, offset);
|
|
|
|
pb_flag = (flags & 0x3000) >> 12;
|
2011-09-26 08:25:18 +00:00
|
|
|
proto_tree_add_item(btacl_tree, hf_btacl_chandle, tvb, offset, 2, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(btacl_tree, hf_btacl_pb_flag, tvb, offset, 2, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(btacl_tree, hf_btacl_bc_flag, tvb, offset, 2, ENC_LITTLE_ENDIAN);
|
2006-05-14 10:18:29 +00:00
|
|
|
offset+=2;
|
|
|
|
|
2006-05-26 08:30:56 +00:00
|
|
|
acl_data=ep_alloc(sizeof(bthci_acl_data_t));
|
|
|
|
acl_data->chandle=flags&0x0fff;
|
2009-05-19 17:16:14 +00:00
|
|
|
pd_save = pinfo->private_data;
|
2006-05-27 06:10:52 +00:00
|
|
|
pinfo->private_data=acl_data;
|
2006-05-26 08:30:56 +00:00
|
|
|
|
2006-05-27 06:10:52 +00:00
|
|
|
/* find the chandle_data structure associated with this chandle */
|
|
|
|
chandle_data=se_tree_lookup32(chandle_tree, acl_data->chandle);
|
|
|
|
if(!chandle_data){
|
|
|
|
chandle_data=se_alloc(sizeof(chandle_data_t));
|
2006-08-14 08:29:29 +00:00
|
|
|
chandle_data->start_fragments=se_tree_create_non_persistent(EMEM_TREE_TYPE_RED_BLACK, "bthci_acl fragment starts");
|
2006-05-27 06:10:52 +00:00
|
|
|
se_tree_insert32(chandle_tree, acl_data->chandle, chandle_data);
|
|
|
|
}
|
2006-05-14 10:18:29 +00:00
|
|
|
|
|
|
|
length = tvb_get_letohs(tvb, offset);
|
2011-09-26 08:25:18 +00:00
|
|
|
proto_tree_add_item(btacl_tree, hf_btacl_length, tvb, offset, 2, ENC_LITTLE_ENDIAN);
|
2006-05-14 10:18:29 +00:00
|
|
|
offset+=2;
|
|
|
|
|
|
|
|
/* determine if packet is fragmented */
|
|
|
|
switch(pb_flag){
|
|
|
|
case 0x01: /* Continuation fragment */
|
|
|
|
fragmented = TRUE;
|
|
|
|
break;
|
2010-12-03 23:44:35 +00:00
|
|
|
case 0x00: /* First fragment/packet, non-auto flushable */
|
|
|
|
case 0x02: /* First fragment/packet, auto flushable */
|
2006-05-27 06:10:52 +00:00
|
|
|
l2cap_length=tvb_get_letohs(tvb, offset);
|
2008-04-29 15:20:19 +00:00
|
|
|
fragmented=((l2cap_length+4)!=length);
|
2006-05-14 10:18:29 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* unknown pb_flag */
|
|
|
|
fragmented = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-27 06:10:52 +00:00
|
|
|
if((!fragmented)
|
2010-12-03 23:44:35 +00:00
|
|
|
|| ((!acl_reassembly)&& !(pb_flag&0x01)) ){
|
2006-05-27 06:10:52 +00:00
|
|
|
/* call L2CAP dissector for PDUs that are not fragmented
|
|
|
|
* also for the first fragment if reassembly is disabled
|
|
|
|
*/
|
2006-05-14 10:18:29 +00:00
|
|
|
next_tvb=tvb_new_subset(tvb, offset, tvb_length_remaining(tvb, offset), length);
|
|
|
|
if(btl2cap_handle){
|
|
|
|
call_dissector(btl2cap_handle, next_tvb, pinfo, tree);
|
|
|
|
}
|
2009-05-19 17:16:14 +00:00
|
|
|
pinfo->private_data = pd_save;
|
2006-05-14 10:18:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-05-27 06:10:52 +00:00
|
|
|
if(fragmented && acl_reassembly){
|
|
|
|
multi_fragment_pdu_t *mfp=NULL;
|
2009-04-24 11:46:38 +00:00
|
|
|
gint len;
|
2006-05-27 06:10:52 +00:00
|
|
|
|
2010-12-03 23:44:35 +00:00
|
|
|
if(!(pb_flag&0x01)){ /* first fragment */
|
2006-05-27 06:10:52 +00:00
|
|
|
if(!pinfo->fd->flags.visited){
|
|
|
|
mfp=se_alloc(sizeof(multi_fragment_pdu_t));
|
|
|
|
mfp->first_frame=pinfo->fd->num;
|
|
|
|
mfp->last_frame=0;
|
|
|
|
mfp->tot_len=l2cap_length+4;
|
2008-04-29 15:20:19 +00:00
|
|
|
mfp->reassembled=se_alloc(mfp->tot_len);
|
2009-04-24 11:46:38 +00:00
|
|
|
len = tvb_length_remaining(tvb, offset);
|
|
|
|
if (len <= mfp->tot_len) {
|
|
|
|
tvb_memcpy(tvb, (guint8*)mfp->reassembled, offset, len);
|
|
|
|
mfp->cur_off=len;
|
|
|
|
se_tree_insert32(chandle_data->start_fragments, pinfo->fd->num, mfp);
|
|
|
|
}
|
2006-05-14 10:18:29 +00:00
|
|
|
} else {
|
2006-05-27 06:10:52 +00:00
|
|
|
mfp=se_tree_lookup32(chandle_data->start_fragments, pinfo->fd->num);
|
2006-05-14 10:18:29 +00:00
|
|
|
}
|
2011-02-17 23:00:34 +00:00
|
|
|
if(mfp != NULL && mfp->last_frame){
|
2006-05-27 06:10:52 +00:00
|
|
|
proto_item *item;
|
|
|
|
item=proto_tree_add_uint(btacl_tree, hf_btacl_reassembled_in, tvb, 0, 0, mfp->last_frame);
|
|
|
|
PROTO_ITEM_SET_GENERATED(item);
|
2011-09-26 08:25:18 +00:00
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, " [Reassembled in #%u]", mfp->last_frame);
|
2006-05-14 10:18:29 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-27 06:10:52 +00:00
|
|
|
if(pb_flag==0x01){ /* continuation fragment */
|
|
|
|
mfp=se_tree_lookup32_le(chandle_data->start_fragments, pinfo->fd->num);
|
|
|
|
if(!pinfo->fd->flags.visited){
|
2009-04-24 11:46:38 +00:00
|
|
|
len = tvb_length_remaining(tvb, offset);
|
2011-02-17 23:00:34 +00:00
|
|
|
if(mfp != NULL && !mfp->last_frame && (mfp->tot_len>=mfp->cur_off+len)){
|
2009-04-24 11:46:38 +00:00
|
|
|
tvb_memcpy(tvb, (guint8*)mfp->reassembled+mfp->cur_off, offset, len);
|
|
|
|
mfp->cur_off+=len;
|
2006-05-27 06:10:52 +00:00
|
|
|
if(mfp->cur_off==mfp->tot_len){
|
|
|
|
mfp->last_frame=pinfo->fd->num;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(mfp){
|
|
|
|
proto_item *item;
|
|
|
|
item=proto_tree_add_uint(btacl_tree, hf_btacl_continuation_to, tvb, 0, 0, mfp->first_frame);
|
|
|
|
PROTO_ITEM_SET_GENERATED(item);
|
2011-09-26 08:25:18 +00:00
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, " [Continuation to #%u]", mfp->first_frame);
|
2006-05-27 06:10:52 +00:00
|
|
|
}
|
2011-02-17 23:00:34 +00:00
|
|
|
if(mfp != NULL && mfp->last_frame==pinfo->fd->num){
|
2009-05-13 19:46:11 +00:00
|
|
|
next_tvb = tvb_new_child_real_data(tvb, (guint8*)mfp->reassembled, mfp->tot_len, mfp->tot_len);
|
2010-10-30 16:00:30 +00:00
|
|
|
add_new_data_source(pinfo, next_tvb, "Reassembled BTHCI ACL");
|
2006-05-27 06:10:52 +00:00
|
|
|
|
|
|
|
/* call L2CAP dissector */
|
|
|
|
if(btl2cap_handle){
|
|
|
|
call_dissector(btl2cap_handle, next_tvb, pinfo, tree);
|
2006-05-14 10:18:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-19 17:16:14 +00:00
|
|
|
pinfo->private_data = pd_save;
|
2006-05-14 10:18:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_register_btacl(void)
|
2008-04-29 15:20:19 +00:00
|
|
|
{
|
2006-05-14 10:18:29 +00:00
|
|
|
|
|
|
|
/* Setup list of header fields See Section 1.6.1 for details*/
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_btacl_chandle,
|
2011-10-18 00:49:16 +00:00
|
|
|
{ "Connection Handle", "bthci_acl.chandle",
|
2008-04-29 15:20:19 +00:00
|
|
|
FT_UINT16, BASE_HEX, NULL, 0x0FFF,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2006-05-14 10:18:29 +00:00
|
|
|
},
|
|
|
|
{ &hf_btacl_pb_flag,
|
2011-10-18 00:49:16 +00:00
|
|
|
{ "PB Flag", "bthci_acl.pb_flag",
|
2008-04-29 15:20:19 +00:00
|
|
|
FT_UINT16, BASE_DEC, VALS(pb_flag_vals), 0x3000,
|
2006-05-14 10:18:29 +00:00
|
|
|
"Packet Boundary Flag", HFILL }
|
|
|
|
},
|
|
|
|
{ &hf_btacl_bc_flag,
|
2011-10-18 00:49:16 +00:00
|
|
|
{ "BC Flag", "bthci_acl.bc_flag",
|
2008-04-29 15:20:19 +00:00
|
|
|
FT_UINT16, BASE_DEC, VALS(bc_flag_vals), 0xC000,
|
2006-05-14 10:18:29 +00:00
|
|
|
"Broadcast Flag", HFILL }
|
|
|
|
},
|
|
|
|
{ &hf_btacl_length,
|
2011-10-18 00:49:16 +00:00
|
|
|
{ "Data Total Length", "bthci_acl.length",
|
2008-04-29 15:20:19 +00:00
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2006-05-14 10:18:29 +00:00
|
|
|
},
|
|
|
|
{ &hf_btacl_data,
|
2011-10-18 00:49:16 +00:00
|
|
|
{ "Data", "bthci_acl.data",
|
2006-05-14 10:18:29 +00:00
|
|
|
FT_NONE, BASE_NONE, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2006-05-14 10:18:29 +00:00
|
|
|
},
|
2006-05-27 06:10:52 +00:00
|
|
|
{ &hf_btacl_continuation_to,
|
2011-10-18 00:49:16 +00:00
|
|
|
{ "This is a continuation to the PDU in frame", "bthci_acl.continuation_to", FT_FRAMENUM, BASE_NONE, NULL, 0x0,
|
2006-05-27 06:10:52 +00:00
|
|
|
"This is a continuation to the PDU in frame #", HFILL }},
|
|
|
|
{ &hf_btacl_reassembled_in,
|
2011-10-18 00:49:16 +00:00
|
|
|
{ "This PDU is reassembled in frame", "bthci_acl.reassembled_in", FT_FRAMENUM, BASE_NONE, NULL, 0x0,
|
2006-05-27 06:10:52 +00:00
|
|
|
"This PDU is reassembled in frame #", HFILL }},
|
2006-05-14 10:18:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Setup protocol subtree array */
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_btacl,
|
|
|
|
};
|
2006-05-27 06:10:52 +00:00
|
|
|
module_t *btacl_module;
|
2006-05-14 10:18:29 +00:00
|
|
|
|
|
|
|
/* Register the protocol name and description */
|
|
|
|
proto_btacl = proto_register_protocol("Bluetooth HCI ACL Packet", "HCI_ACL", "bthci_acl");
|
|
|
|
register_dissector("bthci_acl", dissect_btacl, proto_btacl);
|
|
|
|
|
|
|
|
/* Required function calls to register the header fields and subtrees used */
|
|
|
|
proto_register_field_array(proto_btacl, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
2006-05-27 06:10:52 +00:00
|
|
|
|
|
|
|
/* Register configuration preferences */
|
|
|
|
btacl_module = prefs_register_protocol(proto_btacl, NULL);
|
|
|
|
prefs_register_bool_preference(btacl_module, "btacl_reassembly",
|
|
|
|
"Reassemble ACL Fragments",
|
|
|
|
"Whether the ACL dissector should reassemble fragmented PDUs",
|
|
|
|
&acl_reassembly);
|
|
|
|
|
2006-08-14 08:29:29 +00:00
|
|
|
chandle_tree=se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "bthci_acl chandles");
|
2006-05-14 10:18:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_btacl(void)
|
|
|
|
{
|
|
|
|
dissector_handle_t bthci_acl_handle;
|
|
|
|
|
|
|
|
bthci_acl_handle = find_dissector("bthci_acl");
|
2010-12-20 05:35:29 +00:00
|
|
|
dissector_add_uint("hci_h4.type", HCI_H4_TYPE_ACL, bthci_acl_handle);
|
|
|
|
dissector_add_uint("hci_h1.type", BTHCI_CHANNEL_ACL, bthci_acl_handle);
|
2006-05-14 10:18:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
btl2cap_handle = find_dissector("btl2cap");
|
|
|
|
}
|
|
|
|
|
|
|
|
|