title: Details on HCI filter socket options?
body: <p>While I was testing some basic HCI commands using python's <code>socket</code> library, it seems that in order to get any socket traffic using <code>AF_BLUETOOTH</code> and <code>BTPROTO_HCI</code> a "pass all" filter needs to be set in the socket options:</p>
  
  <pre class="lang-python prettyprint-override"><code>from socket import socket, AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI, SOL_HCI, HCI_FILTER
  from struct import pack
  
  PASS_ALL = pack("IIIh2x", 0xffffffff, 0xffffffff, 0xffffffff, 0)
  
  def open_socket_with_hci(dev_id: int):
      hci = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)
      hci.bind((dev_id,))
      hci.setsockopt(SOL_HCI, HCI_FILTER, PASS_ALL)
      return hci
  </code></pre>
  
  <p>I found <a href="http://gbrault.github.io/gattclient/structhci__filter.html" rel="nofollow noreferrer">hci_filter</a> struct defined as: </p>
  
  <pre class="lang-c prettyprint-override"><code>struct hci_filter {
      uint32_t type_mask;
      uint32_t event_mask[2];
      uint16_t opcode;
  };
  </code></pre>
  
  <p>The opcode mask is straight forward enough. I'm assuming <code>type_mask</code> is a mask on values (code from <a href="https://github.com/torvalds/linux/blob/62393dbcbe0f3001691e4bd479a25beb5941f2ed/include/net/bluetooth/hci.h#L288" rel="nofollow noreferrer">hci.h</a>):</p>
  
  <pre class="lang-c prettyprint-override"><code>/* HCI data types */
  #define HCI_COMMAND_PKT     0x01
  #define HCI_ACLDATA_PKT     0x02
  #define HCI_SCODATA_PKT     0x03
  #define HCI_EVENT_PKT       0x04
  #define HCI_DIAG_PKT        0xf0
  #define HCI_VENDOR_PKT      0xff
  </code></pre>
  
  <p>But could someone please explain the 2x <code>event_mask</code>s? Is the 1st for HCI Event Type and the 2nd for Subevent Type (i.e. LE Meta Event)?</p>