title: Raspberry Pi 3 B+ BLE Scanning Fails After Upgrade (Using Stretch)
body: <p>BLE scanning using a known working Python example fails on a brand new Raspberry Pi 3 B+ (metal can CPU) after doing an apt-get update/upgrade. To recreate, using NOOBS 2.8.2, set up the Pi and do apt-get update and upgrade, accepting all the suggested changes. Then use <a href="https://github.com/switchdoclabs/iBeacon-Scanner-" rel="nofollow noreferrer">this sample code</a> to scan for BLE devices. As part of diagnostic, the command: </p>
  
  <pre><code>hcitool lescan
  </code></pre>
  
  <p>was used to see if the hci0 device could be opened. This led to the error:</p>
  
  <pre><code>hcitool lescan Set scan parameters failed: Input/output error
  </code></pre>
  
  <p>This workaround succeeds around that error:</p>
  
  <pre><code>hciconfig hci0 down
  hciconfig hci0 up
  hcitool lescan
  </code></pre>
  
  <p>But only after the 'hcitool lescan' starts running successfully. It's not clear if we have to actually capture scanned devices in the whitelist for the scan to succeed <s>(goes by too fast to catch and stop)</s>.</p>
  
  <p>The sample code fails on these new system versions:</p>
  
  <pre><code>ii  bluez                           5.43-2+rpt2+deb9u2           armhf        Bluetooth tools and daemons
  ii  bluez-firmware                  1.2-3+rpt6                   all          Firmware for Bluetooth devices
  ii  bluez-hcidump                   5.43-2+rpt2+deb9u2           armhf        Analyses Bluetooth HCI packets
  ii  libbluetooth-dev                5.43-2+rpt2+deb9u2           armhf        Development files for using the BlueZ Linux Bluetooth library
  ii  libbluetooth3:armhf             5.43-2+rpt2+deb9u2           armhf        Library to use the BlueZ Linux Bluetooth stack
  ii  pi-bluetooth                    0.1.8                        all          Raspberry Pi 3 bluetooth
  ii  python-bluez                    0.22-1                       armhf        Python wrappers around BlueZ for rapid bluetooth development
  </code></pre>
  
  <p>But works on this system, one upgrade back:</p>
  
  <pre><code>ii  bluez                           5.43-2+rpt2+deb9u2           armhf        Bluetooth tools and daemons
  ii  bluez-firmware                  1.2-3+rpt5                   all          Firmware for Bluetooth devices
  ii  libbluetooth-dev                5.43-2+rpt2+deb9u2           armhf        Development files for using the BlueZ Linux Bluetooth library
  ii  libbluetooth3:armhf             5.43-2+rpt2+deb9u2           armhf        Library to use the BlueZ Linux Bluetooth stack
  ii  pi-bluetooth                    0.1.7                        all          Raspberry Pi 3 bluetooth
  ii  python-bluez                    0.22-1                       armhf        Python wrappers around BlueZ for rapid bluetooth development
  </code></pre>
  
  <p>EDIT: Output from btmon command (new non-working unit):</p>
  
  <pre><code>Bluetooth monitor ver 5.43
  = Note: Linux version 4.14.52-v7+ (armv7l)                                                                                         0.695265
  = Note: Bluetooth subsystem version 2.22                                                                                           0.695276
  = New Index: B8:27:EB:A0:39:EC (Primary,UART,hci0)                                                                          [hci0] 0.695279
  = Open Index: B8:27:EB:A0:39:EC                                                                                             [hci0] 0.695281
  = Index Info: B8:27:EB:A0:39:EC (Broadcom Corporation)                                                                      [hci0] 0.695284
  @ RAW Open: python (privileged) version 2.22                                                                       {0x0003} [hci0] 0.695289
  @ RAW Open: hcitool (privileged) version 2.22                                                                      {0x0002} [hci0] 0.695291
  @ MGMT Open: bluetoothd (privileged) version 1.14                                                                         {0x0001} 0.695294
  @ MGMT Open: btmon (privileged) version 1.14                                                                              {0x0004} 0.695367
  &gt; HCI Event: LE Meta Event (0x3e) plen 40                                                                                   [hci0] 2.692582
        LE Advertising Report (0x02)
          Num reports: 1
          Event type: Scannable undirected - ADV_SCAN_IND (0x02)
          Address type: Random (0x01)
          Address: 51:46:AD:CA:4C:2F (Resolvable)
          Data length: 28
          16-bit Service UUIDs (complete): 1 entry
            Google (0xfe9f)
          Service Data (UUID 0xfe9f): 0000000000000000000000000000000000000000
          RSSI: -84 dBm (0xac)
  </code></pre>
  
  <p>From older, working unit:</p>
  
  <pre><code>Bluetooth monitor ver 5.43
  = Note: Linux version 4.14.34-v7+ (armv7l)                                                                                         0.396738
  = Note: Bluetooth subsystem version 2.22                                                                                           0.396744
  = New Index: B8:27:EB:31:E6:62 (Primary,UART,hci0)                                                                          [hci0] 0.396746
  = Open Index: B8:27:EB:31:E6:62                                                                                             [hci0] 0.396748
  = Index Info: B8:27:EB:31:E6:62 (Broadcom Corporation)                                                                      [hci0] 0.396749
  @ RAW Open: python (privileged) version 2.22                                                                       {0x0002} [hci0] 0.396752
  @ MGMT Open: bluetoothd (privileged) version 1.14                                                                         {0x0001} 0.396753
  @ MGMT Open: btmon (privileged) version 1.14                                                                              {0x0003} 0.396800
  &gt; HCI Event: LE Meta Event (0x3e) plen 42                                                                                   [hci0] 0.534168
        LE Advertising Report (0x02)
          Num reports: 1
          Event type: Non connectable undirected - ADV_NONCONN_IND (0x03)
          Address type: Public (0x00)
          Address: 0C:F3:EE:B3:B8:53 (EM Microelectronic)
          Data length: 30
          Flags: 0x06
            LE General Discoverable Mode
            BR/EDR Not Supported
          Company: Apple, Inc. (76)
            Type: iBeacon (2)
            UUID: a6ffa91b-91f4-f2ad-0f4a-6dcf5444232f
            Version: 0.256
            TX power: -76 dB
          RSSI: -70 dBm (0xba)
  </code></pre>