/* Function for creating a message for writing to the CCCD.  */
static uint32_t cccd_configure(uint16_t conn_handle, uint16_t cccd_handle, bool enable)
/* Function for creating a message for writing to the CCCD.  */
static uint32_t cccd_configure(uint16_t conn_handle, uint16_t cccd_handle, bool enable)
{
    uint8_t buf[BLE_CCCD_VALUE_LEN];
    buf[0] = enable ? BLE_GATT_HVX_NOTIFICATION : 0;
    buf[1] = 0;
    const ble_gattc_write_params_t write_params = {
        .write_op = BLE_GATT_OP_WRITE_REQ,
        .flags    = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE,
        .handle   = cccd_handle,
        .offset   = 0,
        .len      = sizeof(buf),
        .p_value  = buf
    };
    return sd_ble_gattc_write(conn_handle, &write_params);
}