diff options
author | Anders Broman <anders.broman@ericsson.com> | 2012-11-29 13:21:10 +0000 |
---|---|---|
committer | Anders Broman <anders.broman@ericsson.com> | 2012-11-29 13:21:10 +0000 |
commit | 900b884f55f988391a965b6e06298f57e82ecf27 (patch) | |
tree | d3d2c7e2706b4f485190daabf4ba2641a105f777 /epan/dissectors | |
parent | cec78c65186b99ac294e1936000072f6f23939c5 (diff) |
From Michal Labedzki:
Bluetooth: Add support for source/destination addresses
Within resolving devices names. Also make header file more generic,
packet-hci_h4.h renamed to packet-bluetooth-hci.h.
Part of:
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=5032
svn path=/trunk/; revision=46278
Diffstat (limited to 'epan/dissectors')
-rw-r--r-- | epan/dissectors/Makefile.common | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-bluetooth-hci.h (renamed from epan/dissectors/packet-hci_h4.h) | 53 | ||||
-rw-r--r-- | epan/dissectors/packet-bthci_acl.c | 158 | ||||
-rw-r--r-- | epan/dissectors/packet-bthci_cmd.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-bthci_evt.c | 271 | ||||
-rw-r--r-- | epan/dissectors/packet-bthci_sco.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-hci_h1.c | 31 | ||||
-rw-r--r-- | epan/dissectors/packet-hci_h4.c | 40 |
8 files changed, 484 insertions, 75 deletions
diff --git a/epan/dissectors/Makefile.common b/epan/dissectors/Makefile.common index 1deb9bca71..18d1675f1e 100644 --- a/epan/dissectors/Makefile.common +++ b/epan/dissectors/Makefile.common @@ -1229,6 +1229,7 @@ DISSECTOR_INCLUDES = \ packet-bacapp.h \ packet-ber.h \ packet-bfd.h \ + packet-bluetooth_hci.h \ packet-bpq.h \ packet-bssap.h \ packet-bssgp.h \ @@ -1341,7 +1342,6 @@ DISSECTOR_INCLUDES = \ packet-h264.h \ packet-h323.h \ packet-h450-ros.h \ - packet-hci_h4.h \ packet-hclnfsd.h \ packet-hdcp.h \ packet-hpext.h \ diff --git a/epan/dissectors/packet-hci_h4.h b/epan/dissectors/packet-bluetooth-hci.h index cf1b3e7a51..244e432c8a 100644 --- a/epan/dissectors/packet-hci_h4.h +++ b/epan/dissectors/packet-bluetooth-hci.h @@ -1,4 +1,4 @@ -/* packet-hci_h4.h +/* packet-bluetooth-hci.h * * $Id$ * @@ -21,8 +21,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef __PACKET_HCI_H4_H__ -#define __PACKET_HCI_H4_H__ +#ifndef __PACKET_BLUETOOTH_HCI_H__ +#define __PACKET_BLUETOOTH_HCI__H__ #define HCI_H4_TYPE_CMD 0x01 #define HCI_H4_TYPE_ACL 0x02 @@ -59,4 +59,49 @@ extern const value_string bthci_cmd_page_scan_repetition_modes[]; extern const value_string bthci_cmd_page_scan_period_modes[]; extern const value_string bthci_cmd_notification_types[]; -#endif + +#define HCI_INTERFACE_H1 0 +#define HCI_INTERFACE_H4 1 +#define HCI_INTERFACE_USB 2 + +#define HCI_ADAPTER_DEFAULT 0 + +/* chandle_to_bdaddr_table: interface_id + adapter_id + connection_handle + frame_number -> bd_addr[6] */ +/* bdaddr_to_name_table: bd_addr[6] + frame_number -> name */ +/* localhost_bdaddr: interface_id + adapter_id + frame_number -> bd_addr[6] */ +/* localhost_name: interface_id + adapter_id + frame_number -> name */ +typedef struct _hci_data_t { + guint32 interface_id; + guint32 adapter_id; + emem_tree_t *chandle_to_bdaddr_table; + emem_tree_t *bdaddr_to_name_table; + emem_tree_t *localhost_bdaddr; + emem_tree_t *localhost_name; +} hci_data_t; + +typedef struct _remote_bdaddr_t { + guint32 interface_id; + guint32 adapter_id; + guint16 chandle; + guint8 bd_addr[6]; +} remote_bdaddr_t; + +typedef struct _device_name_t { + guint32 bd_addr_oui; + guint32 bd_addr_id; + gchar *name; +} device_name_t; + +typedef struct _localhost_bdaddr_entry_t { + guint32 interface_id; + guint32 adapter_id; + guint8 bd_addr[6]; +} localhost_bdaddr_entry_t; + +typedef struct _localhost_name_entry_t { + guint32 interface_id; + guint32 adapter_id; + gchar *name; +} localhost_name_entry_t; + +#endif
\ No newline at end of file diff --git a/epan/dissectors/packet-bthci_acl.c b/epan/dissectors/packet-bthci_acl.c index b382d4b9c8..b4f4b9e4c5 100644 --- a/epan/dissectors/packet-bthci_acl.c +++ b/epan/dissectors/packet-bthci_acl.c @@ -34,7 +34,7 @@ #include <epan/packet.h> #include <epan/prefs.h> -#include "packet-hci_h4.h" +#include "packet-bluetooth-hci.h" #include "packet-bthci_acl.h" /* Initialize the protocol and registered fields */ @@ -88,16 +88,31 @@ static const value_string bc_flag_vals[] = { static void dissect_bthci_acl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { - proto_item *ti = NULL; - proto_tree *bthci_acl_tree = NULL; - guint16 flags, length; - gboolean fragmented; - int offset = 0; - guint16 pb_flag, l2cap_length = 0; - tvbuff_t *next_tvb; - bthci_acl_data_t *acl_data; - chandle_data_t *chandle_data; - void* pd_save; + proto_item *ti = NULL; + proto_tree *bthci_acl_tree = NULL; + guint16 flags; + guint16 length; + gboolean fragmented; + int offset = 0; + guint16 pb_flag, l2cap_length = 0; + tvbuff_t *next_tvb; + bthci_acl_data_t *acl_data; + chandle_data_t *chandle_data; + void *pd_save; + hci_data_t *hci_data; + emem_tree_key_t key[5]; + guint32 k_connection_handle; + guint32 k_frame_number; + guint32 k_interface_id; + guint32 k_adapter_id; + remote_bdaddr_t *remote_bdaddr; + gchar *localhost_name; + guint8 localhost_bdaddr[6]; + gchar *localhost_ether_addr; + gchar *localhost_addr_name; + gint localhost_length; + localhost_bdaddr_entry_t *localhost_bdaddr_entry; + localhost_name_entry_t *localhost_name_entry; col_set_str(pinfo->cinfo, COL_PROTOCOL, "HCI_ACL"); @@ -113,11 +128,132 @@ dissect_bthci_acl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) proto_tree_add_item(bthci_acl_tree, hf_bthci_acl_bc_flag, tvb, offset, 2, ENC_LITTLE_ENDIAN); offset += 2; + hci_data = (hci_data_t *) pinfo->private_data; + acl_data = ep_alloc(sizeof(bthci_acl_data_t)); acl_data->chandle = flags&0x0fff; pd_save = pinfo->private_data; pinfo->private_data = acl_data; + k_interface_id = hci_data->interface_id; + k_adapter_id = hci_data->adapter_id; + k_connection_handle = flags & 0x0fff; + k_frame_number = pinfo->fd->num; + + key[0].length = 1; + key[0].key = &k_interface_id; + key[1].length = 1; + key[1].key = &k_adapter_id; + key[2].length = 1; + key[2].key = &k_connection_handle; + key[3].length = 1; + key[3].key = &k_frame_number; + key[4].length = 0; + key[4].key = NULL; + + /* remote bdaddr and name */ + remote_bdaddr = se_tree_lookup32_array_le(hci_data->chandle_to_bdaddr_table, key); + if (remote_bdaddr && remote_bdaddr->interface_id == k_interface_id && + remote_bdaddr->adapter_id == k_adapter_id && + remote_bdaddr->chandle == (flags & 0x0fff)) { + guint32 k_bd_addr_oui; + guint32 k_bd_addr_id; + guint32 k_frame_number; + guint32 bd_addr_oui; + guint32 bd_addr_id; + device_name_t *device_name; + gchar *remote_name; + gchar *remote_ether_addr; + gchar *remote_addr_name; + gint remote_length; + + bd_addr_oui = remote_bdaddr->bd_addr[0] << 16 | remote_bdaddr->bd_addr[1] << 8 | remote_bdaddr->bd_addr[2]; + bd_addr_id = remote_bdaddr->bd_addr[3] << 16 | remote_bdaddr->bd_addr[4] << 8 | remote_bdaddr->bd_addr[5]; + k_bd_addr_oui = bd_addr_oui; + k_bd_addr_id = bd_addr_id; + + key[0].length = 1; + key[0].key = &k_bd_addr_id; + key[1].length = 1; + key[1].key = &k_bd_addr_oui; + key[2].length = 1; + key[2].key = &k_frame_number; + key[3].length = 0; + key[3].key = NULL; + + device_name = se_tree_lookup32_array_le(hci_data->bdaddr_to_name_table, key); + if (device_name && device_name->bd_addr_oui == bd_addr_oui && device_name->bd_addr_id == bd_addr_id) + remote_name = device_name->name; + else + remote_name = ""; + + remote_ether_addr = get_ether_name(remote_bdaddr->bd_addr); + remote_length = strlen(remote_ether_addr) + 3 + strlen(remote_name) + 1; + remote_addr_name = ep_alloc(remote_length); + + g_snprintf(remote_addr_name, remote_length, "%s (%s)", remote_ether_addr, remote_name); + + if (pinfo->p2p_dir == P2P_DIR_RECV) { + SET_ADDRESS(&pinfo->net_src, AT_STRINGZ, strlen(remote_name), remote_name); + SET_ADDRESS(&pinfo->dl_src, AT_ETHER, 6, remote_bdaddr->bd_addr); + SET_ADDRESS(&pinfo->src, AT_STRINGZ, strlen(remote_addr_name), remote_addr_name); + } else if (pinfo->p2p_dir == P2P_DIR_SENT) { + SET_ADDRESS(&pinfo->net_dst, AT_STRINGZ, strlen(remote_name), remote_name); + SET_ADDRESS(&pinfo->dl_dst, AT_ETHER, 6, remote_bdaddr->bd_addr); + SET_ADDRESS(&pinfo->dst, AT_STRINGZ, strlen(remote_addr_name), remote_addr_name); + } + } else { + if (pinfo->p2p_dir == P2P_DIR_RECV) { + SET_ADDRESS(&pinfo->net_src, AT_STRINGZ, 0, ""); + SET_ADDRESS(&pinfo->dl_src, AT_STRINGZ, 0, ""); + SET_ADDRESS(&pinfo->src, AT_STRINGZ, 0, ""); + } else if (pinfo->p2p_dir == P2P_DIR_SENT) { + SET_ADDRESS(&pinfo->net_dst, AT_STRINGZ, 0, ""); + SET_ADDRESS(&pinfo->dl_dst, AT_STRINGZ, 0, ""); + SET_ADDRESS(&pinfo->dst, AT_STRINGZ, 0, ""); + } + } + + /* localhost bdaddr and name */ + key[0].length = 1; + key[0].key = &k_interface_id; + key[1].length = 1; + key[1].key = &k_adapter_id; + key[2].length = 1; + key[2].key = &k_frame_number; + key[3].length = 0; + key[3].key = NULL; + + + localhost_bdaddr_entry = se_tree_lookup32_array_le(hci_data->localhost_bdaddr, key); + if (localhost_bdaddr_entry && localhost_bdaddr_entry->interface_id == k_interface_id && + localhost_bdaddr_entry->adapter_id == k_adapter_id) + localhost_ether_addr = get_ether_name(localhost_bdaddr_entry->bd_addr); + else + localhost_ether_addr = "localhost"; + + localhost_name_entry = se_tree_lookup32_array_le(hci_data->localhost_name, key); + if (localhost_name_entry && localhost_name_entry->interface_id == k_interface_id && + localhost_name_entry->adapter_id == k_adapter_id) + localhost_name = localhost_name_entry->name; + else + localhost_name =""; + + localhost_length = strlen(localhost_ether_addr) + 3 + strlen(localhost_name) + 1; + localhost_addr_name = ep_alloc(localhost_length); + + g_snprintf(localhost_addr_name, localhost_length, "%s (%s)", localhost_ether_addr, localhost_name); + + if (pinfo->p2p_dir == P2P_DIR_RECV) { + SET_ADDRESS(&pinfo->net_dst, AT_STRINGZ, strlen(localhost_name), localhost_name); + SET_ADDRESS(&pinfo->dl_dst, AT_ETHER, 6, localhost_bdaddr); + SET_ADDRESS(&pinfo->dst, AT_STRINGZ, strlen(localhost_addr_name), localhost_addr_name); + } else if (pinfo->p2p_dir == P2P_DIR_SENT) { + SET_ADDRESS(&pinfo->net_src, AT_STRINGZ, strlen(localhost_name), localhost_name); + SET_ADDRESS(&pinfo->dl_src, AT_ETHER, 6, localhost_bdaddr); + SET_ADDRESS(&pinfo->src, AT_STRINGZ, strlen(localhost_addr_name), localhost_addr_name); + } + /* find the chandle_data structure associated with this chandle */ chandle_data = se_tree_lookup32(chandle_tree, acl_data->chandle); if (!chandle_data) { diff --git a/epan/dissectors/packet-bthci_cmd.c b/epan/dissectors/packet-bthci_cmd.c index 92cd1e5af5..129a21fdc9 100644 --- a/epan/dissectors/packet-bthci_cmd.c +++ b/epan/dissectors/packet-bthci_cmd.c @@ -37,7 +37,7 @@ #include <epan/packet.h> #include <epan/addr_resolv.h> -#include "packet-hci_h4.h" +#include "packet-bluetooth-hci.h" /* Initialize the protocol and registered fields */ static int proto_bthci_cmd = -1; diff --git a/epan/dissectors/packet-bthci_evt.c b/epan/dissectors/packet-bthci_evt.c index 0f7f07f5cd..fd66f52de4 100644 --- a/epan/dissectors/packet-bthci_evt.c +++ b/epan/dissectors/packet-bthci_evt.c @@ -37,7 +37,7 @@ #include <epan/packet.h> #include <epan/addr_resolv.h> -#include "packet-hci_h4.h" +#include "packet-bluetooth-hci.h" static dissector_handle_t bthci_com_handle; @@ -850,8 +850,9 @@ static const value_string evt_master_clock_accuray[] = { { 0, NULL } }; -static int -dissect_bthci_evt_bd_addr(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) +static int +dissect_bthci_evt_bd_addr(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, + proto_tree *tree, guint8 *bdaddr) { guint8 i, bd_addr[6]; proto_item *handle_item; @@ -859,6 +860,9 @@ dissect_bthci_evt_bd_addr(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, pro for(i=6; i; i--) bd_addr[6-i] = tvb_get_guint8(tvb, offset+i-1); + if (bdaddr) + memcpy(bdaddr, bd_addr, 6); + handle_item = proto_tree_add_item(tree, hf_bthci_evt_bd_addr, tvb, offset, 6, ENC_NA); proto_item_append_text(handle_item, "%02x%02x:%02x:%02x%02x%02x (%s)", bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5], @@ -920,15 +924,57 @@ dissect_bthci_evt_inq_complete(tvbuff_t *tvb, int offset, packet_info *pinfo _U_ } static int -dissect_bthci_evt_conn_complete(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) +dissect_bthci_evt_conn_complete(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) { + guint16 connection_handle; + guint8 bd_addr[6]; + guint8 status; + hci_data_t *hci_data; + proto_tree_add_item(tree, hf_bthci_evt_status, tvb, offset, 1, ENC_LITTLE_ENDIAN); + status = tvb_get_guint8(tvb, offset); offset++; + connection_handle = tvb_get_letohs(tvb, offset) & 0x0FFF; proto_tree_add_item(tree, hf_bthci_evt_connection_handle, tvb, offset, 2, ENC_LITTLE_ENDIAN); offset+=2; - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, bd_addr); + if (!pinfo->fd->flags.visited && status == 0x00) { + emem_tree_key_t key[5]; + guint32 k_interface_id; + guint32 k_adapter_id; + guint32 k_connection_handle; + guint32 k_frame_number; + remote_bdaddr_t *remote_bdaddr; + + hci_data = (hci_data_t *) pinfo->private_data; + + k_interface_id = hci_data->interface_id; + k_adapter_id = hci_data->adapter_id; + k_connection_handle = connection_handle; + k_frame_number = pinfo->fd->num; + + key[0].length = 1; + key[0].key = &k_interface_id; + key[1].length = 1; + key[1].key = &k_adapter_id; + key[2].length = 1; + key[2].key = &k_connection_handle; + key[3].length = 1; + key[3].key = &k_frame_number; + key[4].length = 0; + key[4].key = NULL; + + remote_bdaddr = se_alloc(sizeof(remote_bdaddr_t)); + remote_bdaddr->interface_id = hci_data->interface_id; + remote_bdaddr->adapter_id = hci_data->adapter_id; + remote_bdaddr->chandle = connection_handle; + memcpy(remote_bdaddr->bd_addr, bd_addr, 6); + + se_tree_insert32_array(hci_data->chandle_to_bdaddr_table, key, remote_bdaddr); + } + proto_tree_add_item(tree, hf_bthci_evt_link_type, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; @@ -942,7 +988,7 @@ dissect_bthci_evt_conn_complete(tvbuff_t *tvb, int offset, packet_info *pinfo _U static int dissect_bthci_evt_conn_request(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) { - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); offset = dissect_bthci_evt_cod(tvb, offset, pinfo, tree); @@ -1067,7 +1113,7 @@ dissect_bthci_evt_lmp_features(tvbuff_t *tvb, int offset, packet_info *pinfo _U_ static int dissect_bthci_evt_pin_code_request(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) { - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); return offset; } @@ -1075,7 +1121,7 @@ dissect_bthci_evt_pin_code_request(tvbuff_t *tvb, int offset, packet_info *pinfo static int dissect_bthci_evt_link_key_request(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) { - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); return offset; } @@ -1083,7 +1129,7 @@ dissect_bthci_evt_link_key_request(tvbuff_t *tvb, int offset, packet_info *pinfo static int dissect_bthci_evt_link_key_notification(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) { - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); proto_tree_add_item(tree, hf_bthci_evt_link_key, tvb, offset, 16, ENC_NA); offset+=16; @@ -1104,7 +1150,7 @@ dissect_bthci_evt_return_link_keys(tvbuff_t *tvb, int offset, packet_info *pinfo offset++; while(evt_num_keys--){ - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); proto_tree_add_item(tree, hf_bthci_evt_link_key, tvb, offset, 16, ENC_NA); offset+=16; @@ -1129,15 +1175,50 @@ dissect_bthci_evt_read_remote_support_features_complete(tvbuff_t *tvb, int offse } static int -dissect_bthci_evt_remote_name_req_complete(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) +dissect_bthci_evt_remote_name_req_complete(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) { + guint8 bd_addr[6]; + proto_tree_add_item(tree, hf_bthci_evt_status, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, bd_addr); proto_tree_add_item(tree, hf_bthci_evt_remote_name, tvb, offset, 248, ENC_ASCII|ENC_NA); - offset+=248; + if (!pinfo->fd->flags.visited) { + hci_data_t *hci_data; + emem_tree_key_t key[4]; + guint32 k_bd_addr_oui; + guint32 k_bd_addr_id; + guint32 k_frame_number; + gchar *name; + device_name_t *device_name; + + hci_data = (hci_data_t *) pinfo->private_data; + + name = tvb_get_ephemeral_string(tvb, offset, 248); + + k_frame_number = pinfo->fd->num; + k_bd_addr_oui = bd_addr[0] << 16 | bd_addr[1] << 8 | bd_addr[2]; + k_bd_addr_id = bd_addr[3] << 16 | bd_addr[4] << 8 | bd_addr[5]; + + key[0].length = 1; + key[0].key = &k_bd_addr_id; + key[1].length = 1; + key[1].key = &k_bd_addr_oui; + key[2].length = 1; + key[2].key = &k_frame_number; + key[3].length = 0; + key[3].key = NULL; + + device_name = se_alloc(sizeof(device_name_t)); + device_name->bd_addr_oui = bd_addr[0] << 16 | bd_addr[1] << 8 | bd_addr[2]; + device_name->bd_addr_id = bd_addr[3] << 16 | bd_addr[4] << 8 | bd_addr[5]; + device_name->name = se_strdup(name); + + se_tree_insert32_array(hci_data->bdaddr_to_name_table, key, device_name); + } + offset += 248; return offset; } @@ -1220,7 +1301,7 @@ dissect_bthci_evt_role_change(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree_add_item(tree, hf_bthci_evt_status, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); proto_tree_add_item(tree, hf_bthci_evt_role, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; @@ -1401,7 +1482,7 @@ dissect_bthci_evt_command_status(tvbuff_t *tvb, int offset, packet_info *pinfo, static int dissect_bthci_evt_page_scan_mode_change(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) { - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); proto_tree_add_item(tree, hf_bthci_evt_page_scan_mode, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; @@ -1412,7 +1493,7 @@ dissect_bthci_evt_page_scan_mode_change(tvbuff_t *tvb, int offset, packet_info * static int dissect_bthci_evt_page_scan_repetition_mode_change(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) { - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); proto_tree_add_item(tree, hf_bthci_evt_page_scan_repetition_mode, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; @@ -1421,7 +1502,8 @@ dissect_bthci_evt_page_scan_repetition_mode_change(tvbuff_t *tvb, int offset, pa } static int -dissect_bthci_evt_inq_result_with_rssi(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) +dissect_bthci_evt_inq_result_with_rssi(tvbuff_t *tvb, int offset, + packet_info *pinfo, proto_tree *tree, guint8 *bd_addr) { guint8 num, evt_num_responses; @@ -1429,8 +1511,8 @@ dissect_bthci_evt_inq_result_with_rssi(tvbuff_t *tvb, int offset, packet_info *p proto_tree_add_item(tree, hf_bthci_evt_num_responses, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; - for(num=0;num<evt_num_responses;num++){ - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + for(num = 0; num < evt_num_responses; num++) { + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, (num == 0) ? bd_addr : NULL); proto_tree_add_item(tree, hf_bthci_evt_page_scan_repetition_mode, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; @@ -1441,7 +1523,7 @@ dissect_bthci_evt_inq_result_with_rssi(tvbuff_t *tvb, int offset, packet_info *p offset = dissect_bthci_evt_cod(tvb, offset, pinfo, tree); proto_tree_add_item(tree, hf_bthci_evt_clock_offset, tvb, offset, 2, ENC_LITTLE_ENDIAN); - offset+=2; + offset += 2; proto_tree_add_item(tree, hf_bthci_evt_rssi, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; @@ -1452,7 +1534,8 @@ dissect_bthci_evt_inq_result_with_rssi(tvbuff_t *tvb, int offset, packet_info *p } static int -dissect_bthci_evt_eir_ad_data(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, guint8 size) +dissect_bthci_evt_eir_ad_data(tvbuff_t *tvb, int offset, packet_info *pinfo, + proto_tree *tree, guint8 size, guint8 *bd_addr) { guint16 i, j; guint8 length, type; @@ -1530,6 +1613,39 @@ dissect_bthci_evt_eir_ad_data(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, case 0x09: /* Device Name, full */ proto_tree_add_item(ti_eir_struct_subtree, hf_bthci_evt_device_name, tvb, offset+i+2, length-1, ENC_ASCII|ENC_NA); proto_item_append_text(ti_eir_struct,": %s", tvb_format_text(tvb,offset+i+2,length-1)); + if (!pinfo->fd->flags.visited && bd_addr) { + hci_data_t *hci_data; + emem_tree_key_t key[4]; + guint32 k_bd_addr_oui; + guint32 k_bd_addr_id; + guint32 k_frame_number; + gchar *name; + device_name_t *device_name; + + hci_data = (hci_data_t *) pinfo->private_data; + + name = tvb_get_ephemeral_string(tvb, offset+i+2, length-1); + + k_frame_number = pinfo->fd->num; + k_bd_addr_oui = bd_addr[0] << 16 | bd_addr[1] << 8 | bd_addr[2]; + k_bd_addr_id = bd_addr[3] << 16 | bd_addr[4] << 8 | bd_addr[5]; + + key[0].length = 1; + key[0].key = &k_bd_addr_id; + key[1].length = 1; + key[1].key = &k_bd_addr_oui; + key[2].length = 1; + key[2].key = &k_frame_number; + key[3].length = 0; + key[3].key = NULL; + + device_name = se_alloc(sizeof(device_name_t)); + device_name->bd_addr_oui = bd_addr[0] << 16 | bd_addr[1] << 8 | bd_addr[2]; + device_name->bd_addr_id = bd_addr[3] << 16 | bd_addr[4] << 8 | bd_addr[5]; + device_name->name = se_strdup(name); + + se_tree_insert32_array(hci_data->bdaddr_to_name_table, key, device_name); + } break; case 0x0A: /* Tx Power Level */ proto_tree_add_item(ti_eir_struct_subtree, hf_bthci_evt_transmit_power_level, tvb, offset+i+2, 1, ENC_LITTLE_ENDIAN); @@ -1570,7 +1686,7 @@ dissect_bthci_evt_eir_ad_data(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, j=0; while(j<(guint8)(length-1)) { - dissect_bthci_evt_bd_addr(tvb, offset+i+j+2, pinfo, ti_eir_struct_subtree); + dissect_bthci_evt_bd_addr(tvb, offset+i+j+2, pinfo, ti_eir_struct_subtree, NULL); j+=6; } break; @@ -1599,7 +1715,7 @@ dissect_bthci_evt_eir_ad_data(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, static int dissect_bthci_evt_io_capability_request(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) { - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); return offset; } @@ -1607,7 +1723,7 @@ dissect_bthci_evt_io_capability_request(tvbuff_t *tvb, int offset, packet_info * static int dissect_bthci_evt_io_capability_response(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) { - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); proto_tree_add_item(tree, hf_bthci_evt_io_capability, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; @@ -1624,7 +1740,7 @@ dissect_bthci_evt_io_capability_response(tvbuff_t *tvb, int offset, packet_info static int dissect_bthci_evt_user_confirmation_request(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) { - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); proto_tree_add_item(tree, hf_bthci_evt_numeric_value, tvb, offset, 4, ENC_LITTLE_ENDIAN); offset+=4; @@ -1635,7 +1751,7 @@ dissect_bthci_evt_user_confirmation_request(tvbuff_t *tvb, int offset, packet_in static int dissect_bthci_evt_user_passkey_request(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) { - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); return offset; } @@ -1643,7 +1759,7 @@ dissect_bthci_evt_user_passkey_request(tvbuff_t *tvb, int offset, packet_info *p static int dissect_bthci_evt_remote_oob_data_request(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) { - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); return offset; } @@ -1654,7 +1770,7 @@ dissect_bthci_evt_simple_pairing_complete(tvbuff_t *tvb, int offset, packet_info proto_tree_add_item(tree, hf_bthci_evt_status, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); return offset; } @@ -1662,7 +1778,7 @@ dissect_bthci_evt_simple_pairing_complete(tvbuff_t *tvb, int offset, packet_info static int dissect_bthci_evt_user_passkey_notification(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) { - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); proto_tree_add_item(tree, hf_bthci_evt_passkey, tvb, offset, 4, ENC_LITTLE_ENDIAN); offset+=4; @@ -1673,7 +1789,7 @@ dissect_bthci_evt_user_passkey_notification(tvbuff_t *tvb, int offset, packet_in static int dissect_bthci_evt_keypress_notification(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) { - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); proto_tree_add_item(tree, hf_bthci_evt_notification_type, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; @@ -1684,7 +1800,7 @@ dissect_bthci_evt_keypress_notification(tvbuff_t *tvb, int offset, packet_info * static int dissect_bthci_evt_remote_host_sup_feat_notification(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) { - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); proto_tree_add_item(tree, hf_bthci_evt_ext_lmp_features, tvb, offset, 8, ENC_LITTLE_ENDIAN); offset+=8; @@ -1715,7 +1831,7 @@ dissect_bthci_evt_le_meta(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, pro offset++; proto_tree_add_item(tree, hf_bthci_evt_le_peer_address_type, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); item = proto_tree_add_item(tree, hf_bthci_evt_le_con_interval, tvb, offset, 2, ENC_LITTLE_ENDIAN); proto_item_append_text(item, " (%g msec)", tvb_get_letohs(tvb, offset)*1.25); offset+=2; @@ -1740,11 +1856,11 @@ dissect_bthci_evt_le_meta(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, pro offset++; proto_tree_add_item(tree, hf_bthci_evt_le_peer_address_type, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); length = tvb_get_guint8(tvb, offset); proto_tree_add_item(tree, hf_bthci_evt_data_length, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; - offset=dissect_bthci_evt_eir_ad_data(tvb, offset, pinfo, tree, length); + offset=dissect_bthci_evt_eir_ad_data(tvb, offset, pinfo, tree, length, NULL); proto_tree_add_item(tree, hf_bthci_evt_rssi, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; } @@ -1941,7 +2057,7 @@ dissect_bthci_evt_amp_status_change(tvbuff_t *tvb, int offset, packet_info *pinf } static int -dissect_bthci_evt_command_complete(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) +dissect_bthci_evt_command_complete(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) { proto_item *ti_opcode=NULL; proto_tree *opcode_tree=NULL; @@ -1950,6 +2066,8 @@ dissect_bthci_evt_command_complete(tvbuff_t *tvb, int offset, packet_info *pinfo guint8 num8, i; guint16 com_opcode; guint32 accuracy; + guint8 bd_addr[6]; + gboolean local_addr = FALSE; proto_tree_add_item(tree, hf_bthci_evt_num_command_packets, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; @@ -2036,6 +2154,8 @@ dissect_bthci_evt_command_complete(tvbuff_t *tvb, int offset, packet_info *pinfo break; /* This is a list of Commands that all return status and BD_ADDR */ + case 0x1009: /* Read BD_ADDR */ + local_addr = TRUE; case 0x0408: /* Create Connection Cancel */ case 0x040b: /* Link Key Request Reply */ case 0x040c: /* Link Key Request Negative Reply */ @@ -2051,11 +2171,39 @@ dissect_bthci_evt_command_complete(tvbuff_t *tvb, int offset, packet_info *pinfo case 0x0430: /* Remote OOB Data Request Reply */ case 0x0433: /* Remote OOB Data Request Negative Reply */ case 0x0c60: /* Send Keypress Notification */ - case 0x1009: /* Read BD_ADDR */ proto_tree_add_item(tree, hf_bthci_evt_status, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, bd_addr); + if (!pinfo->fd->flags.visited && local_addr) { + hci_data_t *hci_data; + emem_tree_key_t key[4]; + guint32 k_interface_id; + guint32 k_adapter_id; + guint32 k_frame_number; + localhost_bdaddr_entry_t *localhost_bdaddr_entry; + + hci_data = (hci_data_t *) pinfo->private_data; + + k_interface_id = hci_data->interface_id; + k_adapter_id = hci_data->adapter_id; + k_frame_number = pinfo->fd->num; + + key[0].length = 1; + key[0].key = &k_interface_id; + key[1].length = 1; + key[1].key = &k_adapter_id; + key[2].length = 1; + key[2].key = &k_frame_number; + key[3].length = 0; + key[3].key = NULL; + + localhost_bdaddr_entry = se_alloc(sizeof(localhost_bdaddr_entry_t)); + localhost_bdaddr_entry->interface_id = k_interface_id; + localhost_bdaddr_entry->adapter_id = k_adapter_id; + memcpy(localhost_bdaddr_entry->bd_addr, bd_addr, 6); + se_tree_insert32_array(hci_data->localhost_bdaddr, key, localhost_bdaddr_entry); + } break; @@ -2228,7 +2376,40 @@ dissect_bthci_evt_command_complete(tvbuff_t *tvb, int offset, packet_info *pinfo offset++; proto_tree_add_item(tree, hf_bthci_evt_device_name, tvb, offset, 248, ENC_ASCII|ENC_NA); - offset+=248; + if (!pinfo->fd->flags.visited) { + hci_data_t *hci_data; + emem_tree_key_t key[4]; + guint32 k_interface_id; + guint32 k_adapter_id; + guint32 k_frame_number; + gchar *name; + localhost_name_entry_t *localhost_name_entry; + + hci_data = (hci_data_t *) pinfo->private_data; + + k_interface_id = hci_data->interface_id; + k_adapter_id = hci_data->adapter_id; + k_frame_number = pinfo->fd->num; + + name = tvb_get_ephemeral_string(tvb, offset, 248); + + key[0].length = 1; + key[0].key = &k_interface_id; + key[1].length = 1; + key[1].key = &k_adapter_id; + key[2].length = 1; + key[2].key = &k_frame_number; + key[3].length = 0; + key[3].key = NULL; + + localhost_name_entry = se_alloc(sizeof(localhost_name_entry_t)); + localhost_name_entry->interface_id = k_interface_id; + localhost_name_entry->adapter_id = k_adapter_id; + localhost_name_entry->name = se_strdup(name); + + se_tree_insert32_array(hci_data->localhost_name, key, localhost_name_entry); + } + offset += 248; break; @@ -2390,7 +2571,7 @@ dissect_bthci_evt_command_complete(tvbuff_t *tvb, int offset, packet_info *pinfo proto_tree_add_item(tree, hf_bthci_evt_fec_required, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; - offset=dissect_bthci_evt_eir_ad_data(tvb, offset, pinfo, tree, 240); + offset=dissect_bthci_evt_eir_ad_data(tvb, offset, pinfo, tree, 240, NULL); break; case 0x0c55: /* Read Simple Pairing Mode */ @@ -2964,7 +3145,7 @@ dissect_bthci_evt_sync_connection_complete(tvbuff_t *tvb, int offset, packet_inf proto_tree_add_item(tree, hf_bthci_evt_connection_handle, tvb, offset, 2, ENC_LITTLE_ENDIAN); offset+=2; - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); proto_tree_add_item(tree, hf_bthci_evt_sync_link_type, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; @@ -3126,7 +3307,7 @@ dissect_bthci_evt_inq_result(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, offset++; for(num=0;num<evt_num_responses;num++){ - offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree); + offset = dissect_bthci_evt_bd_addr(tvb, offset, pinfo, tree, NULL); proto_tree_add_item(tree, hf_bthci_evt_page_scan_repetition_mode, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; @@ -3154,6 +3335,7 @@ dissect_bthci_evt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *dat proto_item *ti; proto_tree *bthci_evt_tree = NULL; guint8 param_length, evt_code; + guint8 bd_addr[6]; int offset = 0; if(tree){ @@ -3310,7 +3492,7 @@ dissect_bthci_evt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *dat break; case 0x22: /* Inquiry Result with RSSI */ - offset=dissect_bthci_evt_inq_result_with_rssi(tvb, offset, pinfo, bthci_evt_tree); + offset=dissect_bthci_evt_inq_result_with_rssi(tvb, offset, pinfo, bthci_evt_tree, NULL); break; case 0x23: /* Read Remote Extended Features Complete */ @@ -3330,8 +3512,9 @@ dissect_bthci_evt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *dat break; case 0x2f: /* Extended Inquiry Result */ - offset=dissect_bthci_evt_inq_result_with_rssi(tvb, offset, pinfo, bthci_evt_tree); - offset =dissect_bthci_evt_eir_ad_data(tvb, offset, pinfo, bthci_evt_tree, 240); +/* TODO: Get bd_addr from first and pass to second*/ + offset = dissect_bthci_evt_inq_result_with_rssi(tvb, offset, pinfo, bthci_evt_tree, bd_addr); + offset = dissect_bthci_evt_eir_ad_data(tvb, offset, pinfo, bthci_evt_tree, 240, bd_addr); break; case 0x30: /* Encryption Key Refresh Complete */ diff --git a/epan/dissectors/packet-bthci_sco.c b/epan/dissectors/packet-bthci_sco.c index f683d739db..2d22feb5ba 100644 --- a/epan/dissectors/packet-bthci_sco.c +++ b/epan/dissectors/packet-bthci_sco.c @@ -30,7 +30,7 @@ #include <epan/packet.h> -#include "packet-hci_h4.h" +#include "packet-bluetooth-hci.h" /* Initialize the protocol and registered fields */ static int proto_bthci_sco = -1; diff --git a/epan/dissectors/packet-hci_h1.c b/epan/dissectors/packet-hci_h1.c index 84c1bbeeb7..c08fb87ab9 100644 --- a/epan/dissectors/packet-hci_h1.c +++ b/epan/dissectors/packet-hci_h1.c @@ -26,7 +26,7 @@ #include <epan/packet.h> - +#include "packet-bluetooth-hci.h" static int proto_hci_h1 = -1; static int hf_hci_h1_type = -1; @@ -37,6 +37,10 @@ static gint ett_hci_h1 = -1; static dissector_table_t hci_h1_table; static dissector_handle_t data_handle; +static emem_tree_t *chandle_to_bdaddr_table = NULL; +static emem_tree_t *bdaddr_to_name_table = NULL; +static emem_tree_t *localhost_name = NULL; +static emem_tree_t *localhost_bdaddr = NULL; static const value_string hci_h1_type_vals[] = { {BTHCI_CHANNEL_COMMAND, "HCI Command"}, @@ -55,10 +59,12 @@ static const value_string hci_h1_direction_vals[] = { static void dissect_hci_h1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { - guint8 type; - tvbuff_t *next_tvb; + guint8 type; + tvbuff_t *next_tvb; proto_item *ti=NULL; - proto_tree *hci_h1_tree=NULL; + proto_tree *hci_h1_tree = NULL; + void *pd_save; + hci_data_t *hci_data; col_set_str(pinfo->cinfo, COL_PROTOCOL, "HCI"); @@ -99,6 +105,16 @@ dissect_hci_h1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) "Unknown 0x%02x")); } + pd_save = pinfo->private_data; + hci_data = ep_alloc(sizeof(hci_data_t)); + hci_data->interface_id = HCI_INTERFACE_H4; + hci_data->adapter_id = HCI_ADAPTER_DEFAULT; + hci_data->chandle_to_bdaddr_table = chandle_to_bdaddr_table; + hci_data->bdaddr_to_name_table = bdaddr_to_name_table; + hci_data->localhost_bdaddr = localhost_bdaddr; + hci_data->localhost_name = localhost_name; + pinfo->private_data = hci_data; + ti=proto_tree_add_int(hci_h1_tree, hf_hci_h1_direction, tvb, 0, 0, pinfo->p2p_dir); PROTO_ITEM_SET_GENERATED(ti); @@ -106,6 +122,8 @@ dissect_hci_h1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if(!dissector_try_uint(hci_h1_table, type, next_tvb, pinfo, tree)) { call_dissector(data_handle, next_tvb, pinfo, tree); } + + pinfo->private_data = pd_save; } @@ -139,6 +157,11 @@ proto_register_hci_h1(void) hci_h1_table = register_dissector_table("hci_h1.type", "HCI h1 pdu type", FT_UINT8, BASE_HEX); + + chandle_to_bdaddr_table = se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "hci adapter/chandle to bdaddr"); + bdaddr_to_name_table = se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "hci bdaddr to name"); + localhost_bdaddr = se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "hci adaper/frame to bdaddr"); + localhost_name = se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "hci adaper/frame to name"); } void diff --git a/epan/dissectors/packet-hci_h4.c b/epan/dissectors/packet-hci_h4.c index b4702aeb2c..418ff945bf 100644 --- a/epan/dissectors/packet-hci_h4.c +++ b/epan/dissectors/packet-hci_h4.c @@ -32,8 +32,7 @@ #include <epan/packet.h> -#include "packet-hci_h4.h" - +#include "packet-bluetooth-hci.h" static int proto_hci_h4 = -1; static int hf_hci_h4_type = -1; @@ -44,6 +43,10 @@ static gint ett_hci_h4 = -1; static dissector_table_t hci_h4_table; static dissector_handle_t data_handle; +static emem_tree_t *chandle_to_bdaddr_table = NULL; +static emem_tree_t *bdaddr_to_name_table = NULL; +static emem_tree_t *localhost_name = NULL; +static emem_tree_t *localhost_bdaddr = NULL; static const value_string hci_h4_type_vals[] = { {HCI_H4_TYPE_CMD, "HCI Command"}, @@ -62,10 +65,12 @@ static const value_string hci_h4_direction_vals[] = { static void dissect_hci_h4(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { - guint8 type; - tvbuff_t *next_tvb; - proto_item *ti=NULL; - proto_tree *hci_h4_tree=NULL; + guint8 type; + tvbuff_t *next_tvb; + proto_item *ti = NULL; + proto_tree *hci_h4_tree = NULL; + void *pd_save; + hci_data_t *hci_data; col_set_str(pinfo->cinfo, COL_PROTOCOL, "HCI H4"); switch (pinfo->p2p_dir) { @@ -83,7 +88,7 @@ dissect_hci_h4(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) default: col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown direction %d ", - pinfo->p2p_dir); + pinfo->p2p_dir); break; } @@ -94,6 +99,16 @@ dissect_hci_h4(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) hci_h4_tree = proto_item_add_subtree(ti, ett_hci_h4); } + pd_save = pinfo->private_data; + hci_data = ep_alloc(sizeof(hci_data_t)); + hci_data->interface_id = HCI_INTERFACE_H4; + hci_data->adapter_id = HCI_ADAPTER_DEFAULT; + hci_data->chandle_to_bdaddr_table = chandle_to_bdaddr_table; + hci_data->bdaddr_to_name_table = bdaddr_to_name_table; + hci_data->localhost_bdaddr = localhost_bdaddr; + hci_data->localhost_name = localhost_name; + pinfo->private_data = hci_data; + ti=proto_tree_add_uint(hci_h4_tree, hf_hci_h4_direction, tvb, 0, 0, pinfo->p2p_dir); PROTO_ITEM_SET_GENERATED(ti); @@ -106,6 +121,8 @@ dissect_hci_h4(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if(!dissector_try_uint(hci_h4_table, type, next_tvb, pinfo, tree)) { call_dissector(data_handle, next_tvb, pinfo, tree); } + + pinfo->private_data = pd_save; } @@ -119,7 +136,7 @@ proto_register_hci_h4(void) NULL, HFILL }}, { &hf_hci_h4_direction, - { "Direction", "hci_h4.direction", + { "Direction", "hci_h4.direction", FT_UINT8, BASE_HEX, VALS(hci_h4_direction_vals), 0x0, "HCI Packet Direction Sent/Rcvd", HFILL }}, @@ -130,7 +147,7 @@ proto_register_hci_h4(void) }; proto_hci_h4 = proto_register_protocol("Bluetooth HCI H4", - "HCI_H4", "hci_h4"); + "HCI_H4", "hci_h4"); register_dissector("hci_h4", dissect_hci_h4, proto_hci_h4); @@ -139,6 +156,11 @@ proto_register_hci_h4(void) hci_h4_table = register_dissector_table("hci_h4.type", "HCI H4 pdu type", FT_UINT8, BASE_HEX); + + chandle_to_bdaddr_table = se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "hci adapter/chandle to bdaddr"); + bdaddr_to_name_table = se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "hci bdaddr to name"); + localhost_bdaddr = se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "hci adaper/frame to bdaddr"); + localhost_name = se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "hci adaper/frame to name"); } void |