Bluetooth LE active scanning causes connection problems on other machine
<p>I am having a problem where BLE active scanning on one machine causes connection problems on another machine.  I was wounder if anyone could explain why, and offer any suggestions on how to fix.</p>

<p>I have broken down a rough version of my what my code does into simple scripts.</p>

<p>on machine 1:</p>

<pre><code>sudo stdbuf -oL hcidump -X |tee hci.log &amp;
sudo hcitool lewlclr
sudo hcitool lewladd 68:C9:0B:xx:xx:01
sudo hcitool lewladd 68:C9:0B:xx:xx:02
sudo hcitool lewladd 68:C9:0B:xx:xx:03
sudo hcitool lewladd 68:C9:0B:xx:xx:04
sudo hcitool lewladd 68:C9:0B:xx:xx:05
sudo hcitool lewladd 68:C9:0B:xx:xx:06
while true; do sudo hcitool lecc --whitelist; if [ $? == 1 ] ; then sleep 20;  else sleep 1; sudo hcitool ledc 64 ; fi; done
</code></pre>

<p>The above will run with no problems </p>

<p>However after running the following on a different machine I get connection issues.</p>

<pre><code>sudo hcitool lescan --duplicates
</code></pre>

<p>from the hci logs a normal connecition looks like:</p>

<pre><code>&lt; HCI Command: LE Create Connection (0x08|0x000d) plen 25
    bdaddr 00:00:00:00:00:00 type 0
    interval 4 window 4 initiator_filter 1
    own_bdaddr_type 0 min_interval 15 max_interval 15
    latency 0 supervision_to 3200 min_ce 1 max_ce 1
&gt; HCI Event: Command Status (0x0f) plen 4
    LE Create Connection (0x08|0x000d) status 0x00 ncmd 1
&gt; HCI Event: LE Meta Event (0x3e) plen 19
    LE Connection Complete
      status 0x00 handle 64, role master
      bdaddr 68:C9:0B:xx:xx:xx (Public)
&lt; HCI Command: Disconnect (0x01|0x0006) plen 3
    handle 64 reason 0x13
    Reason: Remote User Terminated Connection
&gt; HCI Event: Command Status (0x0f) plen 4
    Disconnect (0x01|0x0006) status 0x00 ncmd 1
&gt; HCI Event: Disconn Complete (0x05) plen 4
    status 0x00 handle 64 reason 0x16
    Reason: Connection Terminated by Local Host
</code></pre>

<p>and a bad connection is as follows:</p>

<pre><code>&lt; HCI Command: LE Create Connection (0x08|0x000d) plen 25
    bdaddr 00:00:00:00:00:00 type 0
    interval 4 window 4 initiator_filter 1
    own_bdaddr_type 0 min_interval 15 max_interval 15
    latency 0 supervision_to 3200 min_ce 1 max_ce 1
&gt; HCI Event: Command Status (0x0f) plen 4
    LE Create Connection (0x08|0x000d) status 0x00 ncmd 1
&gt; HCI Event: LE Meta Event (0x3e) plen 19
    LE Connection Complete
      status 0x00 handle 64, role master
      bdaddr 68:C9:0B:xx:xx:xx (Public)
&gt; HCI Event: Disconn Complete (0x05) plen 4
    status 0x00 handle 64 reason 0x3e
    Reason: Connection Failed to be Established
&lt; HCI Command: Disconnect (0x01|0x0006) plen 3
    handle 64 reason 0x13
    Reason: Remote User Terminated Connection
&gt; HCI Event: Command Status (0x0f) plen 4
    Disconnect (0x01|0x0006) status 0x12 ncmd 1
    Error: Invalid HCI Command Parameters
</code></pre>

<p>Note: the last two entries (Invalid HCI Command Parameters) are because of the crudeness of the script, and only occur because of the failed connection.  </p>

<p>Of note, it looks like the connection is made, then it says in couldn't (Connection Failed to be Established). This seems a bit confusing to me.</p>

<p>I have tried this on different machines. (desktop PC and RPi3)</p>