This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

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.

Parents Reply
  • Hello.

    BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME and BLE_UUID_GAP_CHARACTERISTIC_APPEARANCE are 16-bit UUIDs defined by the Bluetooth SIG. So, isn't the value registered in the characteristic also 16 bits? Therefore, I set it to ".uuid_type = 0x00".

    I don't know how to use BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME and BLE_UUID_GAP_CHARACTERISTIC_APPEARANCE, so please let me know.

    Best regards.

Children
  • sdi_kei said:
    BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME and BLE_UUID_GAP_CHARACTERISTIC_APPEARANCE are 16-bit UUIDs defined by the Bluetooth SIG. So, isn't the value registered in the characteristic also 16 bits? Therefore, I set it to ".uuid_type = 0x00".

    Aha, I must have missed that in my initial read-through. The uuid_type should instead be 0x01 (or better yet, use the BLE_UUID_TYPE_BLE define), for UUID's defined by Bluetooth SIG.
    The UUID type 0x00 is BLE_UUID_TYPE_UNKNOWN, which is an invalid UUID type. It is likely this combination of the BT SIG official UUID and the UNKNOWN type that is generating the error. Try switching to BLE_UUID_TYPE_BLE and let me know if it resolves the NRF_ERROR_FORBIDDEN issue.

    Best regards,
    Karl

  • Hello.

    The v17.0.0 documentation stated that 0x00 would result in a Bluetooth SIG UUID, so I set it to this value.
    As you told me, I changed it to BLE_UUID_TYPE_BLE and checked it, but NRF_ERROR_FORBIDDEN occurs.

    Is there anything else that is wrong with the settings?

    Best regards.

  • Hello,

    sdi_kei said:
    The v17.0.0 documentation stated that 0x00 would result in a Bluetooth SIG UUID, so I set it to this value.

    Oh, thank you for pointing that out. I have made an internal ticket to have this reviewed.

    It just dawned on me that you are trying to populate the Device name and Appearance GAP characteristics. My mistake, I must have glanced over this too quickly.
    Since these three are mandatory characteristics of the Generic Access Service they will always have to be present, and as such, the SoftDevice will initialize them when initializing the Generic Access service. The SoftDevice controls these mandatory characteristics, which is likely why the FORBIDDEN error is returned. They can only be accessed through SoftDevice API calls.

    In most of our examples you can see how these characteristics are populated with SoftDevice API calls as part of the gap_params_init function.
    You can populate the appearance and device name characteristics through the calls to sd_ble_gap_appearance_set and sd_ble_gap_device_name_set.
    Apologies for misunderstanding your intentions earlier.

    Please do not hesitate to ask if anything still should be unclear, or if you have any other issues or questions.

    Best regards,
    Karl

  • Hello.

    Thank you for the link and example.
    When I called sd_ble_gap_appearance_set and sd_ble_gap_device_name_set, I was able to add a characteristic.

    Thank you for telling me. It was very helpful.

    However, one question arose.
    The tutorial stated that there are three required characteristics, but in my environment there are "Device Name", "Apperance", "Peripheral Preferred Connection Parameters" as well as "Central Address Resolution".
    I would like to remove "Central Address Resolution" to follow the tutorial. Is it possible?

    Best regards.

  • sdi_kei said:
    Thank you for telling me. It was very helpful.

    Great, I am happy to hear that you found the tutorial and my comment helpful!

    sdi_kei said:
    However, one question arose.
    The tutorial stated that there are three required characteristics, but in my environment there are "Device Name", "Apperance", "Peripheral Preferred Connection Parameters" as well as "Central Address Resolution".
    I would like to remove "Central Address Resolution" to follow the tutorial. Is it possible?

    The Central Address Resolution (CAR) characteristic is mandatory for BLE central role that supports privacy feature, and optional for BLE peripheral role. The S132 stack supports both roles, and the characteristic is setup by the SoftDevice. This should not cause any issues for you when following the tutorial, however.
    You can read more about the Central Address Resolution - and BLE address resolution in general - in this thirdparty blogpost.

    Which example from the SDK did you begin your development from?

    Best regards,
    Karl

Related