bluez 5.30: "Not enough free handles to register service" error in starting bluetoothd

Daniel picture Daniel · Apr 27, 2015 · Viewed 10.7k times · Source

What I have done correctly: in linux environment

  1. hciattach /dev/ttyUSB0 any 115200
  2. hciconfig hci0 up
  3. addgroup -S messagebus
  4. adduser -S messagebus -G messagebus
  5. dbus-daemon --system
  6. syslogd

    In executing /libexec/bluetooth/bluetoothd --plugin=time -d -E -n, The error Not enough free handles to register service happens as below:

    bluetoothd[756]: src/adapter.c:clear_uuids() sending clear uuids command for index 0  <br/>
    bluetoothd[756]: src/adapter.c:set_mode() sending set mode command for index 0 <br/>
    bluetoothd[756]: src/gatt-database.c:btd_gatt_database_new() GATT Manager registered for adapter: /org/bluez/hci0 <br/>
    bluetoothd[756]: src/adapter.c:adapter_service_add() /org/bluez/hci0 <br/>
    bluetoothd[756]: src/sdpd-service.c:add_record_to_server() Adding record with handle 0x10002 <br/>
    bluetoothd[756]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000007-0000-1000-8000-00805f9 <br/>
    bluetoothd[756]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000100-0000-1000-8000-00805f9 <br/>
    bluetoothd[756]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001002-0000-1000-8000-00805f9 <br/>
    bluetoothd[756]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001800-0000-1000-8000-00805f9 <br/>
    bluetoothd[756]: src/adapter.c:adapter_service_insert() /org/bluez/hci0 <br/>
    bluetoothd[756]: src/adapter.c:add_uuid() sending add uuid command for index 0 <br/>
    bluetoothd[756]: src/gatt-database.c:gatt_db_service_added() GATT Service added to local database <br/>
    bluetoothd[756]: Failed to obtain handles for "Service Changed"  characteristic <br/>
    bluetoothd[756]: src/adapter.c:adapter_service_add() /org/bluez/hci0 <br/>
    bluetoothd[756]: src/sdpd-service.c:add_record_to_server() Adding record with handle 0x10003 <br/>
    bluetoothd[756]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000007-0000-1000-8000-00805f9 <br/>
    bluetoothd[756]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000100-0000-1000-8000-00805f9 <br/>
    bluetoothd[756]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001002-0000-1000-8000-00805f9 <br/>
    bluetoothd[756]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001801-0000-1000-8000-00805f9 <br/>
    bluetoothd[756]: src/adapter.c:adapter_service_insert() /org/bluez/hci0 <br/>
    bluetoothd[756]: src/adapter.c:add_uuid() sending add uuid command for index 0 <br/>
    bluetoothd[756]: src/gatt-database.c:gatt_db_service_added() GATT Service added to local database <br/>
    bluetoothd[756]: src/advertising.c:btd_advertising_manager_new() LE Advertising Manager created for adapter: /org/bluez/hci0 <br/>
    bluetoothd[756]: profiles/time/server.c:time_server_init() path /org/bluez/hci0 <br/>
    bluetoothd[756]: src/attrib-server.c:attrib_db_find_avail() enter! <br/>
    bluetoothd[756]: src/attrib-server.c:attrib_db_find_avail() BT_UUID16! <br/>
    ***bluetoothd[756]: Not enough free handles to register service*** <br/>
    bluetoothd[756]: Current Time Service could not be registered <br/>
    bluetoothd[756]: gatt-time-server: Input/output error (5) <br/>
    

I dived into the code for debugging the issue a little bit. The attrib_db_find_avail(adapter, svc_uuid, size)[in function: gatt_service_add()] always return 0.

The root cause is the servers glist parameter is always NULL, which is in g_slist_find_custom(servers, adapter, adapter_cmp)[called from find_uuid16_avail()/find_uuid128_avail()].

I noticed there is the call: **btd_adapter_gatt_server_start**(struct btd_adapter *adapter)to be used to add a server into the servers glist. But the weird thing is no where it gets called through the whole bluez source code tree.

So shall I call btd_adapter_gatt_server_start() somewhere in my code? Or any other steps I should do to resolve the issue?

Answer

luislhl picture luislhl · Jan 15, 2016

I was having trouble with bluetooth as well. In my case I was receiving the following error messages several times a minute, as my device went up and down intermitently:

bluetoothd[3196]: Failed to obtain handles for "Service Changed" characteristic
bluetoothd[3196]: Endpoint registered: sender=:1.51 path=/MediaEndpoint/A2DPSource
bluetoothd[3196]: Endpoint registered: sender=:1.51 path=/MediaEndpoint/A2DPSink
bluetoothd[3196]: Failed to set mode: Failed (0x03)

After some research, I found out this thread, where some people fixed their bluetooth problems by deleting ~/.config/pulse. It also solved the problem for me.

I don't have a explanation for why this works, but I'm leaving this tip because it may solve other people's issues as well.