This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

What exactly does the "Handle"s indicate, and how are they identified?

I'm still learning BLE development so I apologize if this is a basic question.

Here is a screenshot of a recent capture I did with the nRF52-DK. The bluetooth sniffer is following a connection between a Garmin Vivosmart (fitness device) and an Android phone:

Alongside the Generic Access Profile, which is present in all the packets, I also see a "Handle" value. I've looked everywhere and cannot for the life of me find where this is documented, nor can I find the definition of the value passed with the handle, which in this case are 0x001a and 0x0017. Are the Handle values of any given Bluetooth device proprietary, or is there a resource that I can use to identify what each Handle value represents? Any assistance would be appreciated.

  • Hi,

    This handle is also known as ATT handle. All entries in the Generic Attribute Profile (GATT) are stored using the Attribute Protocol (ATT), which is a table where each row has a handle, a UUID, permissions, and a value. The start of the table may for instance look something like this (some of the fields omitted (set to "-") for simplicity):

    Handle UUID Permissions Attribute value
    0x0001 0x2800 (Service) - 0x180D (Heart Rate)
    0x0002 0x2803 (Characteristic) - 0x2A37 (Heart Rate Measurement)
    0x0003 0x2A37 (Heart Rate Measurement) - - (what you see as "value" for the Heart Rate Measurement Characteristic)
    0x0004 0x2902 (CCCD) - -
    0x0005 0x2800 (Service) - 0x180F (Battery Service)
    0x0006 0x2803 (Characteristic) - 0x2A19 (Battery Level)
    0x0007 0x2A19 (Battery Level) - - (what you see as "value" for the Battery Level Characteristic)
    0x0008 0x2902 (CCCD) - -

    This describes two services; Heart Rate and Battery, each with one charactersitic. Things like enabling notifications is done through writing to the Client Characteristic Configuration Descriptor (CCCD). Writing to (or reading from) the Heart Rate Measurement Characteristic value uses to "Attribute value" of handle 0x0003. Enabling notifications uses handle 0x0004. Etc.

    The handles are assigned by the GATT server, and do not change while the device is powered. After having connected to a device, one of the first steps is usually to do a database discovery, which is essentially reading the ATT table. The information about handles, and what handle corresponds to what service, characteristic, etc, is something which is integrated in the Bluetooth Low Energy protocol, and something which a GATT client needs in order to communicate with the GATT server. There are procedures, handled by the BLE stack, for communicating this information.

    Please note that if you make a device, which is supposed to communicate with other devices, you should not rely on the ATT table of the other device always being the same. Rather you should do service discovery, looking for the services / characteristics that you are interested in, and use the handles of those services / characteristics as reported by the device. Even if the handle layout of one particular series of devices from one producer has always been the same, there is no guarantee that the next generation of devices, or the next production series of a given device, will have the same layout.

    For a more thorough understanding of how this all works you can have a look at Bluetooth low energy Characteristics, a beginner's tutorial.

    Regards,
    Terje

  • Thank you very much for the thorough explanation!

Related