TheCellule / python-bleson

Python Bluetooth LE Module
https://groups.google.com/group/python-bleson
MIT License
118 stars 24 forks source link

"LE Set Scan Enable" fails with "Command Disallowed (0x0c)" on some hardware #84

Closed tomuta closed 2 years ago

tomuta commented 3 years ago

Enabling BLE scanning silently fails on my Intel NUC7PJYH machine. btmon shows this:

< HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2                                                                                                                                       #101 [hci0] 65.077794
        Scanning: Enabled (0x01)
        Filter duplicates: Disabled (0x00)
> HCI Event: Command Complete (0x0e) plen 4                                                                                                                                                  #102 [hci0] 65.078745
      LE Set Scan Enable (0x08|0x000c) ncmd 1
        Status: Command Disallowed (0x0c)
< HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2                                                                                                                                       #103 [hci0] 66.027513
        Scanning: Disabled (0x00)
        Filter duplicates: Disabled (0x00)
> HCI Event: Command Complete (0x0e) plen 4                                                                                                                                                  #104 [hci0] 66.027756
      LE Set Scan Enable (0x08|0x000c) ncmd 1
        Status: Command Disallowed (0x0c)
< HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7                                                                                                                                   #105 [hci0] 66.027794
        Type: Active (0x01)
        Interval: 10.000 msec (0x0010)
        Window: 10.000 msec (0x0010)
        Own address type: Public (0x00)
        Filter policy: Accept all advertisement (0x00)
> HCI Event: Command Complete (0x0e) plen 4                                                                                                                                                  #106 [hci0] 66.028752
      LE Set Scan Parameters (0x08|0x000b) ncmd 1
        Status: Command Disallowed (0x0c)
< HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2                                                                                                                                       #107 [hci0] 66.028782
        Scanning: Enabled (0x01)
        Filter duplicates: Disabled (0x00)
> HCI Event: Command Complete (0x0e) plen 4                                                                                                                                                  #108 [hci0] 66.029749
      LE Set Scan Enable (0x08|0x000c) ncmd 1
        Status: Command Disallowed (0x0c)

However, BLE devices show up when scanning with bluetoothctl, which does this:

@ MGMT Command: Start Discovery (0x0023) plen 1                                                                                                                                         {0x0001} [hci0] 944.311994
        Address type: 0x07
          BR/EDR
          LE Public
          LE Random
< HCI Command: LE Set Random Address (0x08|0x0005) plen 6                                                                                                                                   #193 [hci0] 944.312398
        Address: 00:29:21:B2:1D:3B (Non-Resolvable)
> HCI Event: Command Complete (0x0e) plen 4                                                                                                                                                 #194 [hci0] 944.426695
      LE Set Random Address (0x08|0x0005) ncmd 1
        Status: Success (0x00)
< HCI Command: LE Set Extended Scan Parameters (0x08|0x0041) plen 8                                                                                                                         #195 [hci0] 944.426865
        Own address type: Random (0x01)
        Filter policy: Accept all advertisement (0x00)
        PHYs: 0x01
        Entry 0: LE 1M
          Type: Active (0x01)
          Interval: 11.250 msec (0x0012)
          Window: 11.250 msec (0x0012)
> HCI Event: Command Complete (0x0e) plen 4                                                                                                                                                 #196 [hci0] 944.427496
      LE Set Extended Scan Parameters (0x08|0x0041) ncmd 1
        Status: Success (0x00)
< HCI Command: LE Set Extended Scan Enable (0x08|0x0042) plen 6                                                                                                                             #197 [hci0] 944.427572
        Extended scan: Enabled (0x01)
        Filter duplicates: Enabled (0x01)
        Duration: 0 msec (0x0000)
        Period: 0.00 sec (0x0000)
> HCI Event: Command Complete (0x0e) plen 4                                                                                                                                                 #198 [hci0] 944.429497
      LE Set Extended Scan Enable (0x08|0x0042) ncmd 2
        Status: Success (0x00)
@ MGMT Event: Command Complete (0x0001) plen 4                                                                                                                                          {0x0001} [hci0] 944.429590
      Start Discovery (0x0023) plen 1
        Status: Success (0x00)
        Address type: 0x07
          BR/EDR
          LE Public
          LE Random

I think bleson needs to implement this in order for this to work properly: https://github.com/custom-components/ble_monitor/issues/61#issuecomment-724203486