Bluetooth: Fix interface_id

Interface ID should correspond to the Wireshark Interface Id
to avoid mixing data from various interfaces in dissectors.

Change-Id: Ibaa3ddab7f0ebd0985efea74439b94a5881145a7
Reviewed-on: https://code.wireshark.org/review/472
Reviewed-by: Evan Huus <eapache@gmail.com>
This commit is contained in:
Michal Labedzki 2014-03-03 08:51:04 +01:00 committed by Anders Broman
parent e2ed48a8d3
commit 248c284622
7 changed files with 63 additions and 23 deletions

View File

@ -84,14 +84,16 @@ extern const value_string bthci_cmd_notification_types[];
AVDTP, BNEP etc. RFCOMM channel has end-protocol like OBEX, HFP, etc.
Important note: correct payload decoding should store needed data using
key contain interface_id, adapter_id, ..., last_channel_type (for example
RFCOMM channel, transaction_id, frame number etc. ) */
#define HCI_INTERFACE_H1 0
#define HCI_INTERFACE_H4 1
#define HCI_INTERFACE_USB 2
#define HCI_INTERFACE_AMP 3
#define HCI_INTERFACE_MON 4
RFCOMM channel, transaction_id, frame number etc. )
#define HCI_ADAPTER_DEFAULT 0
interface_id - interface id provided by Wireshark, see "frame.interface_id",
in case where is only one interface id HCI_INTERFACE_DEFAULT
is used (for example open BTSNOOP file with HCI H4 protocol)
adapter_id - identified Bluetooth device (interface, for example Linux
hci0, hci1, etc.)
*/
#define HCI_INTERFACE_DEFAULT 0
#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 */

View File

@ -32,6 +32,7 @@
#include <epan/expert.h>
#include <epan/wmem/wmem.h>
#include <epan/decode_as.h>
#include <wiretap/wtap.h>
#include "packet-bluetooth-hci.h"
#include "packet-bthci_acl.h"
@ -577,7 +578,10 @@ dissect_connrequest(tvbuff_t *tvb, int offset, packet_info *pinfo,
guint32 chandle;
psm_data_t *psm_data;
interface_id = (acl_data) ? acl_data->interface_id : HCI_INTERFACE_AMP;
if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->phdr->interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
chandle = (acl_data) ? acl_data->chandle : 0;
@ -810,7 +814,10 @@ dissect_configrequest(tvbuff_t *tvb, int offset, packet_info *pinfo,
guint32 chandle;
guint32 cid;
interface_id = (acl_data) ? acl_data->interface_id : HCI_INTERFACE_AMP;
if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->phdr->interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
chandle = (acl_data) ? acl_data->chandle : 0;
cid = dcid | ((pinfo->p2p_dir == P2P_DIR_RECV) ? 0x00000000 : 0x80000000);
@ -1000,7 +1007,10 @@ dissect_configresponse(tvbuff_t *tvb, int offset, packet_info *pinfo,
guint32 chandle;
guint32 cid;
interface_id = (acl_data) ? acl_data->interface_id : HCI_INTERFACE_AMP;
if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->phdr->interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
chandle = (acl_data) ? acl_data->chandle : 0;
cid = scid | ((pinfo->p2p_dir == P2P_DIR_RECV) ? 0x00000000 : 0x80000000);
@ -1085,7 +1095,10 @@ dissect_connresponse(tvbuff_t *tvb, int offset, packet_info *pinfo,
guint32 chandle;
guint32 cid;
interface_id = (acl_data) ? acl_data->interface_id : HCI_INTERFACE_AMP;
if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->phdr->interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
chandle = (acl_data) ? acl_data->chandle : 0;
cid = scid | ((pinfo->p2p_dir == P2P_DIR_RECV) ? 0x00000000 : 0x80000000);
@ -1276,7 +1289,10 @@ dissect_disconnrequestresponse(tvbuff_t *tvb, int offset, packet_info *pinfo,
guint32 key_scid;
guint32 key_dcid;
interface_id = (acl_data) ? acl_data->interface_id : HCI_INTERFACE_AMP;
if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->phdr->interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
chandle = (acl_data) ? acl_data->chandle : 0;
key_dcid = dcid | ((pinfo->p2p_dir == P2P_DIR_RECV) ? 0x00000000 : 0x80000000);
@ -1651,7 +1667,10 @@ dissect_btl2cap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
l2cap_data = wmem_new(wmem_packet_scope(), btl2cap_data_t);
l2cap_data->interface_id = (acl_data) ? acl_data->interface_id : HCI_INTERFACE_AMP;
if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID)
l2cap_data->interface_id = pinfo->phdr->interface_id;
else
l2cap_data->interface_id = HCI_INTERFACE_DEFAULT;
l2cap_data->adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
l2cap_data->chandle = (acl_data) ? acl_data->chandle : 0;
l2cap_data->cid = cid;
@ -1857,7 +1876,10 @@ dissect_btl2cap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
guint32 chandle;
guint32 key_cid;
interface_id = (acl_data) ? acl_data->interface_id : HCI_INTERFACE_AMP;
if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->phdr->interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
chandle = (acl_data) ? acl_data->chandle : 0;
key_cid = cid | ((pinfo->p2p_dir == P2P_DIR_RECV) ? 0x00000000 : 0x80000000);

View File

@ -221,6 +221,7 @@ dissect_btle(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_
gint offset = 0;
guint32 access_address;
guint8 length;
guint32 interface_id;
tvbuff_t *next_tvb;
col_set_str(pinfo->cinfo, COL_PROTOCOL, "LE LL");
@ -245,6 +246,11 @@ dissect_btle(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_
access_address = tvb_get_letohl(tvb, offset);
offset += 4;
if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->phdr->interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
if (access_address == ACCESS_ADDRESS_ADVERTISING) {
proto_item *advertising_header_item;
proto_tree *advertising_header_tree;
@ -411,7 +417,7 @@ dissect_btle(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_
col_append_str(pinfo->cinfo, COL_INFO, "L2CAP Data");
/* TODO: Temporary solution while chandle source/bd_addrs is unknown */
acl_data = wmem_new(wmem_packet_scope(), bthci_acl_data_t);
acl_data->interface_id = HCI_INTERFACE_USB;
acl_data->interface_id = interface_id;
acl_data->adapter_id = 0;
acl_data->chandle = 0;
acl_data->remote_bd_addr_oui = 0;

View File

@ -25,6 +25,7 @@
#include <epan/packet.h>
#include <wiretap/wtap.h>
#include <epan/wmem/wmem.h>
#include <wiretap/wtap.h>
#include "packet-bluetooth-hci.h"
@ -106,7 +107,10 @@ dissect_hci_h1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _
"Unknown 0x%02x"));
hci_data = wmem_new(wmem_packet_scope(), hci_data_t);
hci_data->interface_id = HCI_INTERFACE_H4;
if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID)
hci_data->interface_id = pinfo->phdr->interface_id;
else
hci_data->interface_id = HCI_INTERFACE_DEFAULT;
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;

View File

@ -31,6 +31,7 @@
#include <epan/packet.h>
#include <wiretap/wtap.h>
#include <epan/wmem/wmem.h>
#include <wiretap/wtap.h>
#include "packet-bluetooth-hci.h"
@ -102,7 +103,10 @@ dissect_hci_h4(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _
}
hci_data = (hci_data_t *) wmem_new(wmem_packet_scope(), hci_data_t);
hci_data->interface_id = HCI_INTERFACE_H4;
if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID)
hci_data->interface_id = pinfo->phdr->interface_id;
else
hci_data->interface_id = HCI_INTERFACE_DEFAULT;
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;

View File

@ -146,7 +146,10 @@ dissect_hci_mon(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data
adapter_id, val_to_str_ext_const(opcode, &opcode_vals_ext, "Unknown"));
hci_data = (hci_data_t *) wmem_new(wmem_packet_scope(), hci_data_t);
hci_data->interface_id = HCI_INTERFACE_MON;
if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID)
hci_data->interface_id = pinfo->phdr->interface_id;
else
hci_data->interface_id = HCI_INTERFACE_DEFAULT;
hci_data->adapter_id = adapter_id;
hci_data->chandle_to_bdaddr_table = chandle_to_bdaddr_table;
hci_data->bdaddr_to_name_table = bdaddr_to_name_table;

View File

@ -28,6 +28,7 @@
#include <epan/prefs.h>
#include <epan/reassemble.h>
#include <epan/wmem/wmem.h>
#include <wiretap/wtap.h>
#include "packet-usb.h"
#include "packet-bluetooth-hci.h"
@ -170,12 +171,10 @@ dissect_hci_usb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
session_id = usb_conv_info->bus_id << 16 | usb_conv_info->device_address << 8 | ((pinfo->p2p_dir == P2P_DIR_RECV) ? 1 : 0 ) << 7 | usb_conv_info->endpoint;
hci_data = (hci_data_t *) wmem_new(wmem_packet_scope(), hci_data_t);
if (usb_conv_info->device_protocol == 0xE00104)
hci_data->interface_id = HCI_INTERFACE_AMP;
if (pinfo->phdr->presence_flags & WTAP_HAS_INTERFACE_ID)
hci_data->interface_id = pinfo->phdr->interface_id;
else
hci_data->interface_id = HCI_INTERFACE_USB;
hci_data->interface_id = HCI_INTERFACE_DEFAULT;
hci_data->adapter_id = usb_conv_info->bus_id << 8 | usb_conv_info->device_address;
hci_data->chandle_to_bdaddr_table = chandle_to_bdaddr_table;
hci_data->bdaddr_to_name_table = bdaddr_to_name_table;