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

Add 0x2901

Dear Nordic,

I would like to add 0x2901 Characteristic User Description, but I use below program, it return error_code = 15, please let me know what is the correct method to add 0x2901!

Thanks a lots!

kwan

/**@brief Function for adding the Data I/O characteristic.
 *
 */
static uint32_t sn_char_add(ble_zwave_service_t * p_zwave_service, const ble_zwave_service_init_t * p_zwave_service_init)
{
    uint32_t   err_code;
    ble_gatts_char_md_t char_md;
    ble_gatts_attr_md_t cccd_md;
    ble_gatts_attr_t    attr_char_value;
    ble_uuid_t          ble_uuid;
    ble_gatts_attr_md_t attr_md;

    // Configure the CCCD which is needed for Notifications and Indications
    memset(&cccd_md, 0, sizeof(cccd_md));
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
    cccd_md.vloc = BLE_GATTS_VLOC_STACK;
   
    // Configure the characteristic metadata.
    memset(&char_md, 0, sizeof(char_md));
    char_md.char_props.read          = 1;
    char_md.char_props.write_wo_resp = 1;
    char_md.char_props.notify        = 1;
    char_md.p_char_user_desc         = NULL;
    char_md.p_char_pf                = NULL;
    char_md.p_user_desc_md           = NULL;
    char_md.p_cccd_md                = &cccd_md;
    char_md.p_sccd_md                = NULL;
   
    // Add the ZWAVE SN Characteristic UUID
    ble_uuid128_t base_uuid = {BLE_UUID_ZWAVE_SN_CHAR_BASE_UUID};
    err_code = sd_ble_uuid_vs_add(&base_uuid, &p_zwave_service->uuid_type);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
   
    ble_uuid.type = p_zwave_service->uuid_type;
    ble_uuid.uuid = BLE_UUID_ZWAVE_SN_CHAR_UUID;
   
    // Configure the characteristic value's metadata
    memset(&attr_md, 0, sizeof(attr_md));
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&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;
   
    // Configure the characteristic value
    memset(&attr_char_value, 0, sizeof(attr_char_value));
    attr_char_value.p_uuid       = &ble_uuid;
    attr_char_value.p_attr_md    = &attr_md;
    attr_char_value.init_len     = sizeof(uint8_t);
    attr_char_value.init_offs    = 0;
    attr_char_value.max_len      = sizeof(uint8_t);
    attr_char_value.p_value      = NULL;
       
    err_code=sd_ble_gatts_characteristic_add(p_zwave_service->service_handle, &char_md,
                                               &attr_char_value,
                                               &p_zwave_service->sn_char_handles);

    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }  


// Add Report Reference descriptor
        BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_REPORT_REF_DESCR);
        //BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_DESCRIPTOR_CHAR_USER_DESC);

        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;
           
        memset(&attr_char_value, 0, sizeof(attr_char_value));

        attr_char_value.p_uuid    = &ble_uuid;
        attr_char_value.p_attr_md = &attr_md;
        attr_char_value.init_len  = 30;
        attr_char_value.init_offs = 0;
        attr_char_value.max_len   = 30;
        attr_char_value.p_value   = "Serial Number";

        err_code = sd_ble_gatts_descriptor_add(p_zwave_service->sn_char_handles.value_handle,
                                               &attr_char_value,
                                               &p_zwave_service->descr_handle);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
 

//Add descriptor
   BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_DESCRIPTOR_CHAR_USER_DESC);

    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;

    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       = 30;
    attr.max_len        = 30;
    attr.init_offs      = 0;
    attr.p_value        = attr_value;
    attr.p_attr_md      = &attr_md;
    attr.p_uuid         = &ble_uuid;
   
    err_code = sd_ble_gatts_descriptor_add(p_zwave_service->char_handle, &attr, &p_zwave_service->descr_handle);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
   

        return err_code;
}

Related