Init sequence of bluetooth daemon

0

I'm looking at light weight bluetooth tools from Bluez without dependency on bluetoothd and dbus. The folder "src/shared" of BlueZ has the code for such tools. For ex: btgattclient.c produces "gattclient" when compiled. gattclient is able to connect to ble peripheral device and read/write or receive notifications from the ble device but it needs the hci0 interface to be initialised, something which bluetoothd is doing.

After running bluetoothd to perform the init and then if I kill the bluetoothd, gattclient still works fine connecting to a ble device and receiving notifications. It appears that bluetoothd is doing some settings or init on the adapter that enables "socket connect()" to succeed, without running bluetoothd to do its init, gattclient returns "connection refused" for the "connect()" socket call. btmon logs show that "connect()" failed at the host itself without a connection request to destination BD address.

It will be helpful if BLE experts here can point out the init sequence/commands of bluetoothd, so that I can manually (using btmgmt) or programmatically implement that to facilitate successful working of gattclient.

Here are the btmon logs when bluetoothd is started -

$ = bluetoothd: Bluetooth daemon 5.48                                   26.592869
@ MGMT Open: bluetoothd (privileged) version 1.14            {0x0002} 26.599957
= bluetoothd: Starting SDP server                                     26.600367
= bluetoothd: kernel lacks bnep-protocol support                      26.601263
= bluetoothd: System does not support network plugin                  26.601344
@ MGMT Command: Read Management Version I.. (0x0001) plen 0  {0x0002} 26.605719
@ MGMT Event: Command Complete (0x0001) plen 6               {0x0002} 26.605743
      Read Management Version Information (0x0001) plen 3
        Status: Success (0x00)
        Version: 1.14
= bluetoothd: Bluetooth management interface 1.14 initialized         26.606018
@ MGMT Command: Read Management Supported.. (0x0002) plen 0  {0x0002} 26.606076
@ MGMT Event: Command Complete (0x0001) plen 207             {0x0002} 26.606095
      Read Management Supported Commands (0x0002) plen 204
        Status: Success (0x00)
        Commands: 65
          Read Controller Index List (0x0003)
          Read Controller Information (0x0004)
          Set Powered (0x0005)
          Set Discoverable (0x0006)
          Set Connectable (0x0007)
          Set Fast Connectable (0x0008)
          Set Bondable (0x0009)
          Set Link Security (0x000a)
          Set Secure Simple Pairing (0x000b)
          Set High Speed (0x000c)
          Set Low Energy (0x000d)
          Set Device Class (0x000e)
          Set Local Name (0x000f)
          Add UUID (0x0010)
          Remove UUID (0x0011)
          Load Link Keys (0x0012)
          Load Long Term Keys (0x0013)
          Disconnect (0x0014)
          Get Connections (0x0015)
          PIN Code Reply (0x0016)
          PIN Code Negative Reply (0x0017)
          Set IO Capability (0x0018)
          Pair Device (0x0019)
          Cancel Pair Device (0x001a)
          Unpair Device (0x001b)
          User Confirmation Reply (0x001c)
          User Confirmation Negative Reply (0x001d)
          User Passkey Reply (0x001e)
          User Passkey Negative Reply (0x001f)
          Read Local Out Of Band Data (0x0020)
          Add Remote Out Of Band Data (0x0021)
          Remove Remote Out Of Band Data (0x0022)
          Start Discovery (0x0023)
          Stop Discovery (0x0024)
          Confirm Name (0x0025)
          Block Device (0x0026)
          Unblock Device (0x0027)
          Set Device ID (0x0028)
          Set Advertising (0x0029)
          Set BR/EDR (0x002a)
          Set Static Address (0x002b)
          Set Scan Parameters (0x002c)
          Set Secure Connections (0x002d)
          Set Debug Keys (0x002e)
          Set Privacy (0x002f)
          Load Identity Resolving Keys (0x0030)
          Get Connection Information (0x0031)
          Get Clock Information (0x0032)
          Add Device (0x0033)
          Remove Device (0x0034)
          Load Connection Parameters (0x0035)
          Read Unconfigured Controller Index List (0x0036)
          Read Controller Configuration Information (0x0037)
          Set External Configuration (0x0038)
          Set Public Address (0x0039)
          Start Service Discovery (0x003a)
          Read Local Out Of Band Extended Data (0x003b)
          Read Extended Controller Index List (0x003c)
          Read Advertising Features (0x003d)
          Add Advertising (0x003e)
          Remove Advertising (0x003f)
          Get Advertising Size Information (0x0040)
          Start Limited Discovery (0x0041)
          Read Extended Controller Information (0x0042)
          Set Appearance (0x0043)
        Events: 35
          Controller Error (0x0003)
          Index Added (0x0004)
          Index Removed (0x0005)
          New Settings (0x0006)
          Class Of Device Changed (0x0007)
          Local Name Changed (0x0008)
          New Link Key (0x0009)
          New Long Term Key (0x000a)
          Device Connected (0x000b)
          Device Disconnected (0x000c)
          Connect Failed (0x000d)
          PIN Code Request (0x000e)
          User Confirmation Request (0x000f)
          User Passkey Request (0x0010)
          Authentication Failed (0x0011)
          Device Found (0x0012)
          Discovering (0x0013)
          Device Blocked (0x0014)
          Device Unblocked (0x0015)
          Device Unpaired (0x0016)
          Passkey Notify (0x0017)
          New Identity Resolving Key (0x0018)
          New Signature Resolving Key (0x0019)
          Device Added (0x001a)
          Device Removed (0x001b)
          New Connection Parameter (0x001c)
          Unconfigured Index Added (0x001d)
          Unconfigured Index Removed (0x001e)
          New Configuration Options (0x001f)
          Extended Index Added (0x0020)
          Extended Index Removed (0x0021)
          Local Out Of Band Extended Data Updated (0x0022)
          Advertising Added (0x0023)
          Advertising Removed (0x0024)
          Extended Controller Information Changed (0x0025)
@ MGMT Command: Read Controller Index List (0x0003) plen 0   {0x0002} 26.606174
@ MGMT Event: Command Complete (0x0001) plen 7               {0x0002} 26.606182
      Read Controller Index List (0x0003) plen 4
        Status: Success (0x00)
        Controllers: 1
          hci0
@ MGMT Command: Read Controller In.. (0x0004) plen 0  {0x0002} [hci0] 26.606296
@ MGMT Event: Command Complete (0x0001) plen 283      {0x0002} [hci0] 26.606310
      Read Controller Information (0x0004) plen 280
        Status: Success (0x00)
        Address: C8:DF:84:4E:43:6F (OUI C8-DF-84)
        Version: Bluetooth 4.2 (0x08)
        Manufacturer: Texas Instruments Inc. (13)
        Supported settings: 0x0000bfff
          Powered
          Connectable
          Fast Connectable
          Discoverable
          Bondable
          Link Security
          Secure Simple Pairing
          BR/EDR
          High Speed
          Low Energy
          Advertising
          Secure Connections
          Debug Keys
          Privacy
          Static Address
        Current settings: 0x00000081
          Powered
          BR/EDR
        Class: 0x001f00
          Major class: Uncategorized, specific device code not specified
          Minor class: 0x00
        Name:
        Short name:
@ MGMT Open: bluetoothd (privileged) version 1.14            {0x0003} 26.606719
@ MGMT Command: Remove UUID (0x0011) plen 16          {0x0002} [hci0] 26.608603
        UUID: 00000000-0000-0000-0000-000000000000
@ MGMT Event: Command Complete (0x0001) plen 6        {0x0002} [hci0] 26.608625
      Remove UUID (0x0011) plen 3
        Status: Success (0x00)
        Class: 0x001f00
          Major class: Uncategorized, specific device code not specified
          Minor class: 0x00
@ MGMT Command: Read Advertising F.. (0x003d) plen 0  {0x0003} [hci0] 26.608652
@ MGMT Event: Command Complete (0x0001) plen 11       {0x0003} [hci0] 26.608660
      Read Advertising Features (0x003d) plen 8
        Status: Success (0x00)
        Flags: 0x0000007f
          Switch into Connectable mode
          Advertise as Discoverable
          Advertise as Limited Discoverable
          Add Flags field to Advertising Data
          Add TX Power field to Advertising Data
          Add Appearance field to Scan Response
          Add Local Name in Scan Response
        Advertising data length: 31
        Scan response length: 31
        Max instances: 5
        Instances: 0
@ MGMT Command: Remove Device (0x0034) plen 7         {0x0002} [hci0] 26.608819
        BR/EDR Address: 00:00:00:00:00:00 (OUI 00-00-00)
@ MGMT Event: Command Complete (0x0001) plen 10       {0x0002} [hci0] 26.608847
      Remove Device (0x0034) plen 7
        Status: Success (0x00)
        BR/EDR Address: 00:00:00:00:00:00 (OUI 00-00-00)
@ MGMT Command: Set Secure Simple... (0x000b) plen 1  {0x0002} [hci0] 26.608959
        Secure Simple Pairing: Enabled (0x01)
< HCI Command: Write Simple Pairing.. (0x03|0x0056) plen 1  #1 [hci0] 26.608989
        Mode: Enabled (0x01)
> HCI Event: Command Complete (0x0e) plen 4                 #2 [hci0] 26.615520
      Write Simple Pairing Mode (0x03|0x0056) ncmd 1
        Status: Success (0x00)
@ MGMT Event: Command Complete (0x0001) plen 7        {0x0002} [hci0] 26.615563
      Set Secure Simple Pairing (0x000b) plen 4
        Status: Success (0x00)
        Current settings: 0x000000c1
          Powered
          Secure Simple Pairing
          BR/EDR
@ MGMT Event: New Settings (0x0006) plen 4            {0x0003} [hci0] 26.615579
        Current settings: 0x000000c1
          Powered
          Secure Simple Pairing
          BR/EDR
@ MGMT Event: New Settings (0x0006) plen 4            {0x0001} [hci0] 26.615579
        Current settings: 0x000000c1
          Powered
          Secure Simple Pairing
          BR/EDR
@ MGMT Command: Set Low Energy (0x000d) plen 1        {0x0002} [hci0] 26.615712
        Low Energy: Enabled (0x01)
< HCI Command: Write LE Host Suppor.. (0x03|0x006d) plen 2  #3 [hci0] 26.615743
        Supported: 0x01
        Simultaneous: 0x00
> HCI Event: Command Complete (0x0e) plen 4                 #4 [hci0] 26.615982
      Write LE Host Supported (0x03|0x006d) ncmd 1
        Status: Success (0x00)
@ MGMT Event: Command Complete (0x0001) plen 7        {0x0002} [hci0] 26.616014
      Set Low Energy (0x000d) plen 4
        Status: Success (0x00)
        Current settings: 0x000002c1
          Powered
          Secure Simple Pairing
          BR/EDR
          Low Energy
@ MGMT Event: New Settings (0x0006) plen 4            {0x0003} [hci0] 26.616025
        Current settings: 0x000002c1
          Powered
          Secure Simple Pairing
          BR/EDR
          Low Energy
@ MGMT Event: New Settings (0x0006) plen 4            {0x0001} [hci0] 26.616025
        Current settings: 0x000002c1
          Powered
          Secure Simple Pairing
          BR/EDR
          Low Energy
< HCI Command: LE Set Advertising... (0x08|0x0008) plen 32  #5 [hci0] 26.616060
        Length: 3
        TX power: 14 dBm
@ MGMT Command: Set Secure Connect.. (0x002d) plen 1  {0x0002} [hci0] 26.616194
        Secure Connections: Enabled (0x01)
@ MGMT Event: Command Complete (0x0001) plen 7        {0x0002} [hci0] 26.616203
      Set Secure Connections (0x002d) plen 4
        Status: Success (0x00)
        Current settings: 0x00000ac1
          Powered
          Secure Simple Pairing
          BR/EDR
          Low Energy
          Secure Connections
@ MGMT Event: New Settings (0x0006) plen 4            {0x0003} [hci0] 26.616208
        Current settings: 0x00000ac1
          Powered
          Secure Simple Pairing
          BR/EDR
          Low Energy
          Secure Connections
@ MGMT Event: New Settings (0x0006) plen 4            {0x0001} [hci0] 26.616208
        Current settings: 0x00000ac1
          Powered
          Secure Simple Pairing
          BR/EDR
          Low Energy
          Secure Connections
@ MGMT Command: Set Privacy (0x002f) plen 17          {0x0002} [hci0] 26.616330
        Privacy: Disabled (0x00)
        Key: 00000000000000000000000000000000
@ MGMT Event: Command Status (0x0002) plen 3          {0x0002} [hci0] 26.616338
      Set Privacy (0x002f)
        Status: Rejected (0x0b)
> HCI Event: Command Complete (0x0e) plen 4                 #6 [hci0] 26.616401
      LE Set Advertising Data (0x08|0x0008) ncmd 1
        Status: Success (0x00)
= bluetoothd: Failed to set privacy: Rejected (0x0b)           [hci0] 27.944530
@ MGMT Command: Add UUID (0x0010) plen 17             {0x0002} [hci0] 26.616572
        UUID: 0000110e-0000-1000-8000-00805f9b34fb
        Service class: 0x00
@ MGMT Event: Command Complete (0x0001) plen 6        {0x0002} [hci0] 26.616582
      Add UUID (0x0010) plen 3
        Status: Success (0x00)
        Class: 0x001f00
          Major class: Uncategorized, specific device code not specified
          Minor class: 0x00
@ MGMT Command: Add UUID (0x0010) plen 17             {0x0002} [hci0] 26.616711
        UUID: 0000110c-0000-1000-8000-00805f9b34fb
        Service class: 0x00
@ MGMT Event: Command Complete (0x0001) plen 6        {0x0002} [hci0] 26.616721
      Add UUID (0x0010) plen 3
        Status: Success (0x00)
        Class: 0x001f00
          Major class: Uncategorized, specific device code not specified
          Minor class: 0x00
@ MGMT Command: Unblock Device (0x0027) plen 7        {0x0002} [hci0] 26.616826
        BR/EDR Address: 00:00:00:00:00:00 (OUI 00-00-00)
@ MGMT Event: Device Unblocked (0x0015) plen 7        {0x0003} [hci0] 26.616834
        BR/EDR Address: 00:00:00:00:00:00 (OUI 00-00-00)
@ MGMT Event: Device Unblocked (0x0015) plen 7        {0x0001} [hci0] 26.616834
        BR/EDR Address: 00:00:00:00:00:00 (OUI 00-00-00)
@ MGMT Event: Command Complete (0x0001) plen 10       {0x0002} [hci0] 26.616847
      Unblock Device (0x0027) plen 7
        Status: Success (0x00)
        BR/EDR Address: 00:00:00:00:00:00 (OUI 00-00-00)
@ MGMT Command: Load Link Keys (0x0012) plen 3        {0x0002} [hci0] 26.616946
        Debug keys: Disabled (0x00)
        Keys: 0
@ MGMT Event: Command Complete (0x0001) plen 3        {0x0002} [hci0] 26.616954
      Load Link Keys (0x0012) plen 0
        Status: Success (0x00)
@ MGMT Command: Load Long Term Keys (0x0013) plen 2   {0x0002} [hci0] 26.617042
        Keys: 0
@ MGMT Event: Command Complete (0x0001) plen 3        {0x0002} [hci0] 26.617050
      Load Long Term Keys (0x0013) plen 0
        Status: Success (0x00)
@ MGMT Command: Load Identity Reso.. (0x0030) plen 2  {0x0002} [hci0] 26.617138
        Keys: 0
@ MGMT Event: Command Complete (0x0001) plen 3        {0x0002} [hci0] 26.617146
      Load Identity Resolving Keys (0x0030) plen 0
        Status: Success (0x00)
@ MGMT Command: Load Connection Pa.. (0x0035) plen 2  {0x0002} [hci0] 26.617225
        Parameters: 0
@ MGMT Event: Command Complete (0x0001) plen 3        {0x0002} [hci0] 26.617234
      Load Connection Parameters (0x0035) plen 0
        Status: Success (0x00)
@ MGMT Command: Get Connections (0x0015) plen 0       {0x0002} [hci0] 26.617314
@ MGMT Event: Command Complete (0x0001) plen 5        {0x0002} [hci0] 26.617327
      Get Connections (0x0015) plen 2
        Status: Success (0x00)
        Connections: 0
@ MGMT Command: Add UUID (0x0010) plen 17             {0x0002} [hci0] 26.617408
        UUID: 00001200-0000-1000-8000-00805f9b34fb
        Service class: 0x00
@ MGMT Event: Command Complete (0x0001) plen 6        {0x0002} [hci0] 26.617417
      Add UUID (0x0010) plen 3
        Status: Success (0x00)
        Class: 0x001f00
          Major class: Uncategorized, specific device code not specified
          Minor class: 0x00
@ MGMT Command: Set Device ID (0x0028) plen 8         {0x0002} [hci0] 26.617517
        Device ID: USB Implementer's Forum assigned (0x0002)
          Vendor: 0x1d6b
          Product: 0x0246
          Version: 5.3.0 (0x0530)
@ MGMT Event: Command Complete (0x0001) plen 3        {0x0002} [hci0] 26.617526
      Set Device ID (0x0028) plen 0
        Status: Success (0x00)
@ MGMT Command: Set Device Class (0x000e) plen 2      {0x0002} [hci0] 26.617606
        Major class: 0x00
        Minor class: 0x00
< HCI Command: Write Extended Inq.. (0x03|0x0052) plen 241  #7 [hci0] 26.617645
        FEC: Not required (0x00)
        TX power: 14 dBm
        Device ID: USB Implementer's Forum assigned (0x0002)
          Vendor: 0x1d6b
          Product: 0x0246
          Version: 5.3.0 (0x0530)
        16-bit Service UUIDs (complete): 2 entries
          A/V Remote Control (0x110e)
          A/V Remote Control Target (0x110c)
> HCI Event: Command Complete (0x0e) plen 4                 #8 [hci0] 26.618802
      Write Extended Inquiry Response (0x03|0x0052) ncmd 1
        Status: Success (0x00)
< HCI Command: Write Class of Device (0x03|0x0024) plen 3   #9 [hci0] 26.618848
        Class: 0x000000
          Major class: Miscellaneous
          Minor class: 0x00
> HCI Event: Command Complete (0x0e) plen 4                #10 [hci0] 26.619058
      Write Class of Device (0x03|0x0024) ncmd 1
        Status: Success (0x00)
@ MGMT Event: Class Of Device Chan.. (0x0007) plen 3  {0x0003} [hci0] 26.619082
        Class: 0x000000
          Major class: Miscellaneous
          Minor class: 0x00
@ MGMT Event: Class Of Device Chan.. (0x0007) plen 3  {0x0002} [hci0] 26.619082
        Class: 0x000000
          Major class: Miscellaneous
          Minor class: 0x00
@ MGMT Event: Class Of Device Chan.. (0x0007) plen 3  {0x0001} [hci0] 26.619082
        Class: 0x000000
          Major class: Miscellaneous
          Minor class: 0x00
@ MGMT Event: Command Complete (0x0001) plen 6        {0x0002} [hci0] 26.619114
      Set Device Class (0x000e) plen 3
        Status: Success (0x00)
        Class: 0x000000
          Major class: Miscellaneous
          Minor class: 0x00
@ MGMT Command: Set Local Name (0x000f) plen 260      {0x0002} [hci0] 26.619282
        Name: BlueZ 5.48
        Short name:
< HCI Command: Write Local Name (0x03|0x0013) plen 248     #11 [hci0] 26.619319
        Name: BlueZ 5.48
> HCI Event: Command Complete (0x0e) plen 4                #12 [hci0] 26.620330
      Write Local Name (0x03|0x0013) ncmd 1
        Status: Success (0x00)
@ MGMT Event: Local Name Changed (0x0008) plen 260    {0x0003} [hci0] 26.620362
        Name: BlueZ 5.48
        Short name:
@ MGMT Event: Local Name Changed (0x0008) plen 260    {0x0001} [hci0] 26.620362
        Name: BlueZ 5.48
        Short name:
< HCI Command: Write Extended In.. (0x03|0x0052) plen 241  #13 [hci0] 26.620404
        FEC: Not required (0x00)
        Name (complete): BlueZ 5.48
        TX power: 14 dBm
        Device ID: USB Implementer's Forum assigned (0x0002)
          Vendor: 0x1d6b
          Product: 0x0246
          Version: 5.3.0 (0x0530)
        16-bit Service UUIDs (complete): 2 entries
          A/V Remote Control (0x110e)
          A/V Remote Control Target (0x110c)
> HCI Event: Command Complete (0x0e) plen 4                #14 [hci0] 26.621500
      Write Extended Inquiry Response (0x03|0x0052) ncmd 1
        Status: Success (0x00)
@ MGMT Event: Command Complete (0x0001) plen 263      {0x0002} [hci0] 26.621533
      Set Local Name (0x000f) plen 260
        Status: Success (0x00)
        Name: BlueZ 5.48
        Short name:
@ MGMT Command: Set Bondable (0x0009) plen 1          {0x0002} [hci0] 26.621666
        Bondable: Enabled (0x01)
@ MGMT Event: Command Complete (0x0001) plen 7        {0x0002} [hci0] 26.621677
      Set Bondable (0x0009) plen 4
        Status: Success (0x00)
        Current settings: 0x00000ad1
          Powered
          Bondable
          Secure Simple Pairing
          BR/EDR
          Low Energy
          Secure Connections
@ MGMT Event: New Settings (0x0006) plen 4            {0x0003} [hci0] 26.621682
        Current settings: 0x00000ad1
          Powered
          Bondable
          Secure Simple Pairing
          BR/EDR
          Low Energy
          Secure Connections
@ MGMT Event: New Settings (0x0006) plen 4            {0x0001} [hci0] 26.621682
        Current settings: 0x00000ad1
          Powered
          Bondable
          Secure Simple Pairing
          BR/EDR
          Low Energy
          Secure Connections

Please advice.

Thanks

bluetooth
bluetooth-lowenergy
bluetooth-gatt
gatttool
gattlib
asked on Stack Overflow Apr 21, 2021 by Vinay

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0