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 Children
  • 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

  • Hello.

    Regarding the SDK that started development, I don't know about the SDK that I was using because I took over the program from my predecessor.
    At the moment, the program only works with peripherals, so it should be an option, but I think you're mistaken for SoftDevice to do central work as well.

    Please let me know if you have any advice on how to turn off Central Address Resolution.

    Best regards.

  • Hello,

    sdi_kei said:

    Regarding the SDK that started development, I don't know about the SDK that I was using because I took over the program from my predecessor.

    I understand.
    Knowing which SDK version you are working with is vital, since the documentation is only valid for a particular SDK version. You can check the SDK version by going into SDK_ROOT/documentation/release_notes.txt it should say at the top of the file, which SDK version it is.

    sdi_kei said:

    I think you're mistaken for SoftDevice to do central work as well.

    Please let me know if you have any advice on how to turn off Central Address Resolution.

    Aha, I see. Thank you for clarifying!
    What is the value of the BLE_GAP_CHAR_INCL_CONFIG_INCLUDE define in your project? This is the define that is used for determine CAR inclusion in a peripheral.

    Best regards,
    Karl

Related