title: bluez 5.30: "Not enough free handles to register service" error in starting bluetoothd
body: <h2><em>What I have done correctly: in linux environment</em></h2>
  
  <ol>
  <li><code>hciattach /dev/ttyUSB0 any 115200</code></li>
  <li><code>hciconfig hci0 up</code></li>
  <li><code>addgroup -S messagebus</code></li>
  <li><code>adduser -S messagebus -G messagebus</code></li>
  <li><code>dbus-daemon --system</code></li>
  <li><p><code>syslogd</code></p>
  
  <p>In executing <code>/libexec/bluetooth/bluetoothd --plugin=time -d -E -n</code>, The error <code>Not enough free handles to register service</code> happens as below:</p>
  
  <pre><code>bluetoothd[756]: src/adapter.c:clear_uuids() sending clear uuids command for index 0  &lt;br/&gt;
  bluetoothd[756]: src/adapter.c:set_mode() sending set mode command for index 0 &lt;br/&gt;
  bluetoothd[756]: src/gatt-database.c:btd_gatt_database_new() GATT Manager registered for adapter: /org/bluez/hci0 &lt;br/&gt;
  bluetoothd[756]: src/adapter.c:adapter_service_add() /org/bluez/hci0 &lt;br/&gt;
  bluetoothd[756]: src/sdpd-service.c:add_record_to_server() Adding record with handle 0x10002 &lt;br/&gt;
  bluetoothd[756]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000007-0000-1000-8000-00805f9 &lt;br/&gt;
  bluetoothd[756]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000100-0000-1000-8000-00805f9 &lt;br/&gt;
  bluetoothd[756]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001002-0000-1000-8000-00805f9 &lt;br/&gt;
  bluetoothd[756]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001800-0000-1000-8000-00805f9 &lt;br/&gt;
  bluetoothd[756]: src/adapter.c:adapter_service_insert() /org/bluez/hci0 &lt;br/&gt;
  bluetoothd[756]: src/adapter.c:add_uuid() sending add uuid command for index 0 &lt;br/&gt;
  bluetoothd[756]: src/gatt-database.c:gatt_db_service_added() GATT Service added to local database &lt;br/&gt;
  bluetoothd[756]: Failed to obtain handles for "Service Changed"  characteristic &lt;br/&gt;
  bluetoothd[756]: src/adapter.c:adapter_service_add() /org/bluez/hci0 &lt;br/&gt;
  bluetoothd[756]: src/sdpd-service.c:add_record_to_server() Adding record with handle 0x10003 &lt;br/&gt;
  bluetoothd[756]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000007-0000-1000-8000-00805f9 &lt;br/&gt;
  bluetoothd[756]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00000100-0000-1000-8000-00805f9 &lt;br/&gt;
  bluetoothd[756]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001002-0000-1000-8000-00805f9 &lt;br/&gt;
  bluetoothd[756]: src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001801-0000-1000-8000-00805f9 &lt;br/&gt;
  bluetoothd[756]: src/adapter.c:adapter_service_insert() /org/bluez/hci0 &lt;br/&gt;
  bluetoothd[756]: src/adapter.c:add_uuid() sending add uuid command for index 0 &lt;br/&gt;
  bluetoothd[756]: src/gatt-database.c:gatt_db_service_added() GATT Service added to local database &lt;br/&gt;
  bluetoothd[756]: src/advertising.c:btd_advertising_manager_new() LE Advertising Manager created for adapter: /org/bluez/hci0 &lt;br/&gt;
  bluetoothd[756]: profiles/time/server.c:time_server_init() path /org/bluez/hci0 &lt;br/&gt;
  bluetoothd[756]: src/attrib-server.c:attrib_db_find_avail() enter! &lt;br/&gt;
  bluetoothd[756]: src/attrib-server.c:attrib_db_find_avail() BT_UUID16! &lt;br/&gt;
  ***bluetoothd[756]: Not enough free handles to register service*** &lt;br/&gt;
  bluetoothd[756]: Current Time Service could not be registered &lt;br/&gt;
  bluetoothd[756]: gatt-time-server: Input/output error (5) &lt;br/&gt;
  </code></pre></li>
  </ol>
  
  <p>I dived into the code for debugging the issue a little bit. The <code>attrib_db_find_avail(adapter, svc_uuid, size)[in function: gatt_service_add()]</code> always return 0. </p>
  
  <p>The root cause is the <strong>servers</strong> <code>glist</code> parameter is always NULL, which is in <code>g_slist_find_custom(servers, adapter, adapter_cmp)[called from find_uuid16_avail()/find_uuid128_avail()]</code>. </p>
  
  <p>I noticed there is the call: <code>**btd_adapter_gatt_server_start**(struct btd_adapter *adapter)</code>to be used to add a server into the <strong>servers</strong> <code>glist</code>. But the weird thing is no where it gets called through the whole bluez source code tree. <br/></p>
  
  <p>So shall I call <code>btd_adapter_gatt_server_start()</code> somewhere in my code? Or any other steps I should do to resolve the issue? <br/></p>