On Thu, Nov 12, 2020 at 02:53:05PM +0100, Emil Lenngren wrote: > > It's as Luiz said, you're mixing two different stacks and hence mixing > legacy advertising commands with extended ones. The HCI standard says: > > "If, since the last power-on or reset, the Host has ever issued a legacy > advertising command and then issues an extended advertising command, or > has ever issued an extended advertising command and then issues a legacy > advertising command, the Controller shall return the error code Command > Disallowed (0x0C)." > > After Reset, you can see "LE Set Extended Advertising Parameters" > during the `hciconfig` runs. Then later, when `python` runs, a "LE Set > Advertise Enable" is sent. This is disallowed behaviour. > > One solution is that your python program sends a "Reset" command as > the first thing, otherwise you don't know which state the controller > is in. The other solution is to use BlueZ only. > Thanks Emil, that did help and I was able to finally get a basic service working. I would be happy to use BlueZ but I was never able to get discovery / connection to work more than 10% of the time, so that's why I'm trying something else. I was also getting disconnects every 3 seconds from an unknown source. I think I fixed that with the module parameter enable_autosuspend=N. This was also a subsequent "Set Extended Advertising Parameters" command. These aren't sent from my program and nothing running on my system seems to be talking to bluetooth. Is this part of the BlueZ stack that's running in the kernel? Can it be disabled? This is the last command received: > HCI Event: LE Meta Event (0x3e) plen 10 #413 [hci0] 1319.142290 LE Connection Update Complete (0x03) Status: Success (0x00) Handle: 3585 Connection interval: 45.00 msec (0x0024) Connection latency: 0 (0x0000) Supervision timeout: 5000 msec (0x01f4) Then after 3 seconds (consistently): < HCI Command: Disconnect (0x01|0x0006) plen 3 #414 [hci0] 1322.227590 Handle: 3585 Reason: Remote User Terminated Connection (0x13) > HCI Event: Command Status (0x0f) plen 4 #415 [hci0] 1322.346055 Disconnect (0x01|0x0006) ncmd 1 Status: Success (0x00) > HCI Event: Disconnect Complete (0x05) plen 4 #416 [hci0] 1322.472321 Status: Success (0x00) Handle: 3585 Reason: Connection Terminated By Local Host (0x16) @ MGMT Event: Device Disconnected (0x000c) plen 8 {0x0001} [hci0] 1322.472381 LE Address: 40:AD:0E:98:D7:F6 (Resolvable) Reason: Connection terminated by local host (0x02) < HCI Command: LE Set Advertise Enable (0x08|0x000a) plen 1 #417 [hci0] 1322.519512 Advertising: Enabled (0x01) > HCI Event: Command Complete (0x0e) plen 4 #418 [hci0] 1322.521048 LE Set Advertise Enable (0x08|0x000a) ncmd 2 Status: Success (0x00) < HCI Command: LE Set Extended Advertising Pa.. (0x08|0x0036) plen 25 #419 [hci0] 1322.521089 Handle: 0x00 Properties: 0x0013 Connectable Scannable Use legacy advertising PDUs: ADV_IND Min advertising interval: 1280.000 msec (0x0800) Max advertising interval: 1280.000 msec (0x0800) Channel map: 37, 38, 39 (0x07) Own address type: Public (0x00) Peer address type: Public (0x00) Peer address: 00:00:00:00:00:00 (OUI 00-00-00) Filter policy: Allow Scan Request from Any, Allow Connect Request from Any (0x00) TX power: 127 dbm (0x7f) Primary PHY: LE 1M (0x01) Secondary max skip: 0x00 Secondary PHY: LE 1M (0x01) SID: 0x00 Scan request notifications: Disabled (0x00) > HCI Event: Command Complete (0x0e) plen 5 #420 [hci0] 1322.522027 LE Set Extended Advertising Parameters (0x08|0x0036) ncmd 1 Status: Command Disallowed (0x0c) TX power (selected): 48 dbm (0x30) ~ Devin