]> The Tcpdump Group git mirrors - libpcap/commitdiff
Fix building Bluetooth Linux Monitor support with BlueZ 5.1+
authorJakub Sitnicki <[email protected]>
Thu, 26 Mar 2015 21:35:29 +0000 (22:35 +0100)
committerFrancois-Xavier Le Bail <[email protected]>
Wed, 3 Jun 2015 12:42:51 +0000 (14:42 +0200)
Starting from version 5.1 BlueZ no longer exports the mgmt.h header
or any other header that declares the structure of packets passed
over HCI sockets set to use the HCI monitor channel.

Declare the structure locally and give it the same name as in the
Linux kernel 3.4+.

pcap-bt-monitor-linux.c

index f193e26362f04a957ce38f1e8490de9daf3635e3..b18bdcaed84f163edd697b89cbb8c5d7ba226d07 100644 (file)
 #endif
 
 #include <errno.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/hci.h>
-#include <bluetooth/mgmt.h>
 
 #include "pcap/bluetooth.h"
 #include "pcap-int.h"
 #define BT_CONTROL_SIZE 32
 #define INTERFACE_NAME "bluetooth-monitor"
 
+/*
+ * Fields and alignment must match the declaration in the Linux kernel 3.4+.
+ * See struct hci_mon_hdr in include/net/bluetooth/hci_mon.h.
+ */
+struct hci_mon_hdr {
+    uint16_t opcode;
+    uint16_t index;
+    uint16_t len;
+} __attribute__((packed));
+
 int
 bt_monitor_findalldevs(pcap_if_t **alldevsp, char *err_str)
 {
@@ -72,12 +82,12 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch
     ssize_t ret;
     struct pcap_pkthdr pkth;
     pcap_bluetooth_linux_monitor_header *bthdr;
-    struct mgmt_hdr hdr;
+    struct hci_mon_hdr hdr;
 
     bthdr = (pcap_bluetooth_linux_monitor_header*) &handle->buffer[handle->offset];
 
     iv[0].iov_base = &hdr;
-    iv[0].iov_len = MGMT_HDR_SIZE;
+    iv[0].iov_len = sizeof(hdr);
     iv[1].iov_base = &handle->buffer[handle->offset + sizeof(pcap_bluetooth_linux_monitor_header)];
     iv[1].iov_len = handle->snapshot;
 
@@ -103,7 +113,7 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch
         return -1;
     }
 
-    pkth.caplen = ret - MGMT_HDR_SIZE + sizeof(pcap_bluetooth_linux_monitor_header);
+    pkth.caplen = ret - sizeof(hdr) + sizeof(pcap_bluetooth_linux_monitor_header);
     pkth.len = pkth.caplen;
 
     for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) {