tinygo-org / bluetooth

Cross-platform Bluetooth API for Go and TinyGo. Supports Linux, macOS, Windows, and bare metal using Nordic SoftDevice or HCI
https://tinygo.org
Other
761 stars 138 forks source link

Advertisement registration failure on Linux platform after migration to version 0.9.0 #264

Closed Fllorent0D closed 1 month ago

Fllorent0D commented 7 months ago

While migrating a project from version 0.8.0 to 0.9.0, I noticed a change in the behavior of advertisement functionality on the Linux platform.

In version 0.8.0, sample projects functioned seamlessly, but in 0.9.0, I encountered issues on the hardware I was using. Specifically, I received the following error message:

panic: Failed to start advertisement: bluetooth: could not start advertisement: Failed to register advertisement

Upon investigation, I found that the default scanning mode for hci0 after reboot was set to PSCAN mode only. In version 0.8.0, the scanning mode could be set to PSCAN ISCAN when starting the advertisement. However, in version 0.9.0, this behavior no longer occurs, resulting in the failure to register the advertisement.

Manually setting the correct scanning mode resolves the issue: hciconfig -a hci0 piscan.

My question is whether this is something that should be addressed manually before using the library, or if it constitutes unexpected behavior.

For reference, here are the Bluetoothd logs:

0.8.0

Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/agent.c:add_default_agent() Default agent set to :1.47 /agent/simple0
Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/adapter.c:set_mode() sending set mode command for index 0
Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/agent.c:agent_ref() 0xaaab1a48f650: ref=1
Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/agent.c:register_agent() agent :1.47
Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/adapter.c:new_settings_callback() Settings: 0x00000ad1
Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/adapter.c:settings_changed() Changed settings: 0x00000010
Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/adapter.c:settings_changed() Pending settings: 0x00000000
Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/gatt-database.c:manager_register_app() Registering application: :1.47:/hci0/apps/0
Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/gatt-database.c:proxy_added_cb() Object received: /hci0/apps/0/service0000f000/char2, iface: org.bluez.GattCharacteristic1
Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/gatt-database.c:proxy_added_cb() Object received: /hci0/apps/0/service0000f000/char3, iface: org.bluez.GattCharacteristic1
Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/gatt-database.c:proxy_added_cb() Object received: /hci0/apps/0/service0000f000/char4, iface: org.bluez.GattCharacteristic1
Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/gatt-database.c:proxy_added_cb() Object received: /hci0/apps/0/service0000f000/char5, iface: org.bluez.GattCharacteristic1
Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/gatt-database.c:proxy_added_cb() Object received: /hci0/apps/0/service0000f000, iface: org.bluez.GattService1
Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/gatt-database.c:proxy_added_cb() Object received: /hci0/apps/0/service0000f000/char0, iface: org.bluez.GattCharacteristic1
Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/gatt-database.c:proxy_added_cb() Object received: /hci0/apps/0/service0000f000/char1, iface: org.bluez.GattCharacteristic1
Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/gatt-database.c:database_add_service() handle 0x0013 UUID 0000f000-0000-1000-8000-00805f9b34fb
Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/gatt-database.c:database_add_chrc() handle 0x0015 UUID 0000f004-0000-1000-8000-00805f9b34fb
Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/gatt-database.c:database_add_ccc() Created CCC entry for characteristic
Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/gatt-database.c:database_add_chrc() handle 0x0017 UUID 0000f008-0000-1000-8000-00805f9b34fb
Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/gatt-database.c:database_add_chrc() handle 0x001a UUID 0000f009-0000-1000-8000-00805f9b34fb
Apr 14 08:27:31 azen-1234-1234 bluetoothd[515]: src/gatt-database.c:database_add_ccc() Created CCC entry for characteristic
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/gatt-database.c:database_add_chrc() handle 0x001c UUID 0000f010-0000-1000-8000-00805f9b34fb
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/gatt-database.c:database_add_ccc() Created CCC entry for characteristic
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/gatt-database.c:database_add_chrc() handle 0x001f UUID 0000f001-0000-1000-8000-00805f9b34fb
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/gatt-database.c:database_add_chrc() handle 0x0022 UUID 0000f003-0000-1000-8000-00805f9b34fb
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/gatt-database.c:gatt_db_service_added() GATT Service added to local database
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/adapter.c:adapter_service_add() /org/bluez/hci0
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/sdpd-service.c:add_record_to_server() Adding record with handle 0x1000a
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000007-0000-1000-8000-00805f9
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000100-0000-1000-8000-00805f9
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001002-0000-1000-8000-00805f9
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 0000f000-0000-1000-8000-00805f9
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/adapter.c:adapter_service_insert() /org/bluez/hci0
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/adapter.c:add_uuid() sending add uuid command for index 0
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/gatt-database.c:client_ready_cb() GATT application registered: :1.47:/hci0/apps/0
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/adapter.c:set_mode() sending set mode command for index 0
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/adapter.c:property_set_mode() sending Set Discoverable command for index 0
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/adapter.c:new_settings_callback() Settings: 0x00000ad3
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/adapter.c:settings_changed() Changed settings: 0x00000002
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/adapter.c:settings_changed() Pending settings: 0x00000008
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/adapter.c:property_set_mode_complete() Success (0x00)
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/adapter.c:new_settings_callback() Settings: 0x00000adb
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/adapter.c:settings_changed() Changed settings: 0x00000008
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/adapter.c:settings_changed() Pending settings: 0x00000000
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/adapter.c:set_discoverable() sending set mode command for index 0
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/adapter.c:set_mode() sending set mode command for index 0
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/advertising.c:register_advertisement() RegisterAdvertisement
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/advertising.c:client_create() Adding proxy for /go_bluetooth/hci0/advertisement/0
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/advertising.c:register_advertisement() Registered advertisement at path /go_bluetooth/hci0/advertisement/0
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/advertising.c:parse_service_uuids() Adding ServiceUUID: 0000f000-0000-1000-8000-00805f9b34fb
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/advertising.c:parse_discoverable() Adding Flags 0x00
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/advertising.c:refresh_adv() Refreshing advertisement: /go_bluetooth/hci0/advertisement/0
Apr 14 08:27:32 azen-1234-1234 bluetoothd[515]: src/advertising.c:add_adv_callback() Advertisement registered: /go_bluetooth/hci0/advertisement/0

0.9.0

Apr 14 08:29:31 azen-1234-1234 bluetoothd[516]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000003-0000-1000-8000-00805f9
Apr 14 08:29:31 azen-1234-1234 bluetoothd[516]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000100-0000-1000-8000-00805f9
Apr 14 08:29:31 azen-1234-1234 bluetoothd[516]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001002-0000-1000-8000-00805f9
Apr 14 08:29:31 azen-1234-1234 bluetoothd[516]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001108-0000-1000-8000-00805f9
Apr 14 08:29:31 azen-1234-1234 bluetoothd[516]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001131-0000-1000-8000-00805f9
Apr 14 08:29:31 azen-1234-1234 bluetoothd[516]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001203-0000-1000-8000-00805f9
Apr 14 08:29:31 azen-1234-1234 bluetoothd[516]: src/adapter.c:adapter_service_insert() /org/bluez/hci0
Apr 14 08:29:31 azen-1234-1234 bluetoothd[516]: src/adapter.c:add_uuid() sending add uuid command for index 0
Apr 14 08:29:31 azen-1234-1234 bluetoothd[516]: src/adapter.c:dev_class_changed_callback() Class: 0x0c0000
Apr 14 08:29:31 azen-1234-1234 bluetoothd[516]: src/adapter.c:dev_class_changed_callback() Class: 0x2c0000
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:manager_register_app() Registering application: :1.46:/org/tinygo/bluetooth/service1
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:proxy_added_cb() Object received: /org/tinygo/bluetooth/service1/char4, iface: org.bluez.GattCharacteristic1
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:proxy_added_cb() Object received: /org/tinygo/bluetooth/service1/char5, iface: org.bluez.GattCharacteristic1
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:proxy_added_cb() Object received: /org/tinygo/bluetooth/service1, iface: org.bluez.GattService1
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:proxy_added_cb() Object received: /org/tinygo/bluetooth/service1/char0, iface: org.bluez.GattCharacteristic1
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:proxy_added_cb() Object received: /org/tinygo/bluetooth/service1/char1, iface: org.bluez.GattCharacteristic1
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:proxy_added_cb() Object received: /org/tinygo/bluetooth/service1/char2, iface: org.bluez.GattCharacteristic1
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:proxy_added_cb() Object received: /org/tinygo/bluetooth/service1/char3, iface: org.bluez.GattCharacteristic1
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:database_add_service() handle 0x0013 UUID 0000f000-0000-1000-8000-00805f9b34fb
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:database_add_chrc() handle 0x0015 UUID 0000f009-0000-1000-8000-00805f9b34fb
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:database_add_ccc() Created CCC entry for characteristic
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:database_add_chrc() handle 0x0017 UUID 0000f010-0000-1000-8000-00805f9b34fb
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:database_add_ccc() Created CCC entry for characteristic
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:database_add_chrc() handle 0x001a UUID 0000f001-0000-1000-8000-00805f9b34fb
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:database_add_chrc() handle 0x001d UUID 0000f003-0000-1000-8000-00805f9b34fb
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:database_add_chrc() handle 0x001f UUID 0000f004-0000-1000-8000-00805f9b34fb
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:database_add_ccc() Created CCC entry for characteristic
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:database_add_chrc() handle 0x0021 UUID 0000f008-0000-1000-8000-00805f9b34fb
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:gatt_db_service_added() GATT Service added to local database
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/adapter.c:adapter_service_add() /org/bluez/hci0
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/sdpd-service.c:add_record_to_server() Adding record with handle 0x1000a
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000007-0000-1000-8000-00805f9
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000100-0000-1000-8000-00805f9
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001002-0000-1000-8000-00805f9
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 0000f000-0000-1000-8000-00805f9
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/adapter.c:adapter_service_insert() /org/bluez/hci0
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/adapter.c:add_uuid() sending add uuid command for index 0
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:client_ready_cb() GATT application registered: :1.46:/org/tinygo/bluetooth/service1
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/advertising.c:register_advertisement() RegisterAdvertisement
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/advertising.c:client_create() Adding proxy for /org/tinygo/bluetooth/advertisement1
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/advertising.c:register_advertisement() Registered advertisement at path /org/tinygo/bluetooth/advertisement1
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/advertising.c:parse_service_uuids() Adding ServiceUUID: 0000f000-0000-1000-8000-00805f9b34fb
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/advertising.c:refresh_adv() Refreshing advertisement: /org/tinygo/bluetooth/advertisement1
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/advertising.c:add_client_complete() Failed to add advertisement: Invalid Parameters (0x0d)
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:proxy_removed_cb() Proxy removed - removing service: /org/tinygo/bluetooth/service1
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:gatt_db_service_removed() Local GATT service removed
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/adapter.c:adapter_service_remove() /org/bluez/hci0
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/adapter.c:remove_uuid() sending remove uuid command for index 0
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/sdpd-service.c:remove_record_from_server() Removing record with handle 0x1000a
Apr 14 08:30:41 azen-1234-1234 bluetoothd[516]: src/gatt-database.c:client_disconnect_cb() Client disconnected

Fllorent0D commented 1 month ago

Seems fixed with CYW43439 implementation