From df98800943e28b515854b384481428156527b21f Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 1 Jan 2014 21:21:34 -0800 Subject: [PATCH] shared: Use HCI filter for raw device access --- src/shared/hci.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/shared/hci.c b/src/shared/hci.c index d0305ac84..77d7b5ce9 100644 --- a/src/shared/hci.c +++ b/src/shared/hci.c @@ -51,6 +51,14 @@ struct sockaddr_hci { #define HCI_CHANNEL_RAW 0 #define HCI_CHANNEL_USER 1 +#define SOL_HCI 0 +#define HCI_FILTER 2 +struct hci_filter { + uint32_t type_mask; + uint32_t event_mask[2]; + uint16_t opcode; +}; + struct bt_hci { int ref_count; int fd; @@ -375,12 +383,23 @@ struct bt_hci *bt_hci_new_user_channel(uint16_t index) struct bt_hci *bt_hci_new_raw_device(uint16_t index) { struct bt_hci *hci; + struct hci_filter flt; int fd; fd = create_socket(index, HCI_CHANNEL_RAW); if (fd < 0) return NULL; + memset(&flt, 0, sizeof(flt)); + flt.type_mask = 1 << BT_H4_EVT_PKT; + flt.event_mask[0] = 0xffffffff; + flt.event_mask[1] = 0xffffffff; + + if (setsockopt(fd, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) { + close(fd); + return NULL; + } + hci = bt_hci_new(fd); if (!hci) { close(fd); -- 2.47.3