NRF_ERROR_FORBIDDEN occurs in sd_ble_gatts_characteristic_add.

Hello.

It is developed using nrf52832 (S132 v7.0.1, SDK v17.0.0) as a peripheral device.

I'm trying to characteristically add BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME and BLE_UUID_GAP_CHARACTERISTIC_APPEARANCE.

However, characteristic_add (sd_ble_gatts_characteristic_add) gives an NRF_ERROR_FORBIDDEN error. How can it be solved?

static uint16_t                 m_service_handle;                                   /**< Handle of local service (as provided by the BLE stack).*/
static ble_gatts_char_handles_t m_char_handles[2];                  /**< Handles of local characteristic (as provided by the BLE stack).*/


#define BLE_UUID_SERVICE_BASE {0xHH, 0xHH, 0xGG, 0xGG, 0xFF, 0xFF, 0xEE, 0xEE, 0xDD, 0xDD, 0xCC, 0xCC, 0xBB, 0xBB, 0xAA, 0xAA}
#define BLE_ADV_UUID_SERVICE 0xABCD
#define BLE_UUID_CHAR        0xEFGH

/**
 * @brief DEVICE NAME CHARACTERISTIC
 * 
 */
static ble_add_char_params_t char_device_name = 
{
    .uuid            = BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME,
    .uuid_type       = 0x00,
    .max_len         = 248,
    .init_len        = 248,
    .p_init_value    = NULL,
    .is_var_len      = false,
    .char_props.read = 1,
    .read_access     = SEC_OPEN,
};

/**
 * @brief APPEARANCE CHARACTERISTIC
 * 
 */
static ble_add_char_params_t char_appearance = 
{
    .uuid             = BLE_UUID_GAP_CHARACTERISTIC_APPEARANCE,
    .uuid_type        = 0x00,
    .max_len          = 2,
    .init_len         = 2,
    .is_var_len       = false,
    .char_props.read  = 1,
    .read_access      = SEC_OPEN,
};

static void services_init(void)
{
    ble_uuid128_t base_uuid = {BLE_UUID_SERVICE_BASE};
    ble_uuid_t service_uuid;
    ret_code_t err_code;    

    service_uuid.uuid = BLE_ADV_UUID_SERVICE;

    err_code = sd_ble_uuid_vs_add(&base_uuid, &service_uuid.type);
    APP_ERROR_CHECK(err_code);

    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &service_uuid, &m_service_handle);
    APP_ERROR_CHECK(err_code);

    characteristic_init();

    return;
}

static void characteristic_init(void)
{
    ble_uuid_t    char_uuid;
    ret_code_t    err_code;

    err_code = characteristic_add(m_service_handle, &char_device_name, &m_char_handles[0]);
    APP_ERROR_CHECK(err_code);

    err_code = characteristic_add(m_service_handle, &char_appearance, &m_char_handles[1]);
    APP_ERROR_CHECK(err_code);

    return;
}

Best regards.

Related