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

How to add the descriptions of GATT Primary Service(0x2800) and GATT characteristic?

How to add the descriptions of GATT Primary Service(0x2800) and GATT characteristic? Just like the picture below. image description

  • Hi

    You can use sd_ble_gatts_descriptor_add() to add Characteristic User Descriptions to your characteristics.

    You can do something like this:

    static uint32_t our_descriptor_add(ble_os_t * p_our_service, uint16_t char_handle)
    {
        uint32_t   err_code; // Variable to hold return codes from library and softdevice functions
        
        ble_gatts_attr_md_t    attr_md;
        memset(&attr_md, 0, sizeof(attr_md));
    
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
        BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.write_perm);
    
        attr_md.vloc    = BLE_GATTS_VLOC_STACK;
        attr_md.rd_auth = 0;
        attr_md.wr_auth = 0;
        attr_md.vlen    = 0;
        
        ble_uuid_t          attr_uuid;
        attr_uuid.uuid      = BLE_UUID_DESCRIPTOR_CHAR_USER_DESC;
        ble_uuid128_t       base_uuid = {0x23, 0xD1, 0x13, 0xEF, 0x5F, 0x78, 0x23, 0x15, 0xDE, 0xEF, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00}; // 128-bit base UUID
        err_code = sd_ble_uuid_vs_add(&base_uuid, &attr_uuid.type);
        APP_ERROR_CHECK(err_code); 
        
        
        uint8_t attr_value[]  = "Your User description";
        const uint16_t attr_len   = sizeof(attr_value);
        
        ble_gatts_attr_t    attr;
        memset(&attr, 0, sizeof(attr));
        
        attr.init_len       = attr_len;
        attr.max_len        = attr_len;
        attr.init_offs      = 0;
        attr.p_value        = attr_value;
        attr.p_attr_md      = &attr_md;
        attr.p_uuid         = &attr_uuid;
        
        err_code = sd_ble_gatts_descriptor_add(char_handle, &attr, &p_our_service->descr_handle);
        APP_ERROR_CHECK(err_code); 
        
        return err_code;
    }
    

    Please have a look at e.g. the ble_app_hids_mouse example in e.g. SDK 9.0.0. It shows how to add descriptors like this.

  • Hi, Martin Børs-Lind

    I can't find the example how to add descriptors in the ble_app_hids_mouse example . And, what is the ble_os_t and and char_handle in the code you showed above. Can you tell me how to use the "our_descriptor_add()" detailedly?

  • The example is located in "your_sdk_folder\examples\ble_peripheral\ble_app_hids_mouse". The sd_ble_gatts_descriptor_add() function is used in e.g. the rep_char_add() function found in ble_hids.c file.

    The code above is copy-pasted from a random example i made. ble_os_t and char_handle are just residues from that example. ble_os_t is a service struct containing data about the service being worked on and char_handle is the handle to the characteristic that you want to add a descriptor to. If you want to use the code above you will have to modify it a bit to fit your particular application.

Related