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

characteristic user description is always shown as writable

Hi,

     I am working with a custom board based on nRF52840. I am using SDK 15.0 and softdevice 6.0.0.

I have two custom services that have user descriptions on all characteristics. I have ensured that  wr_aux is set to 0 in the extended properties. However nrfConnect is showing an up arrow. I note this devzone post from three years ago: https://devzone.nordicsemi.com/f/nordic-q-a/12185/user-description-read-only. Which didn't come to any conclusion about why it was showing as writable or how to stop it showing as writable.

static uint32_t char_add(uint16_t                        uuid,
                         uint8_t                       * p_char_value,
                         uint16_t                        char_len,
                         ble_srv_security_mode_t const * dis_attr_md,
                         ble_gatts_char_handles_t      * p_handles,
                         char *p_desc)
{
    ble_uuid_t          ble_uuid;
    ble_gatts_char_md_t char_md;
    ble_gatts_attr_t    attr_char_value;
    ble_gatts_attr_md_t attr_md, desc_md;

    APP_ERROR_CHECK_BOOL(p_char_value != NULL);
    APP_ERROR_CHECK_BOOL(char_len > 0);

    // The ble_gatts_char_md_t structure uses bit fields. So we reset the memory to zero.
    memset(&char_md, 0, sizeof(char_md));
    memset(&desc_md, 0, sizeof(ble_gatts_attr_md_t));
    BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&desc_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&desc_md.write_perm);
    desc_md.vloc    = BLE_GATTS_VLOC_STACK;
    desc_md.vlen    = 0;

    char_md.p_char_pf        = NULL;
    char_md.p_user_desc_md   = &desc_md;

    char_md.p_char_user_desc = p_desc;
    char_md.char_user_desc_size = strlen(p_desc);
    char_md.char_user_desc_max_size = strlen(p_desc);

   // char_md.p_user_desc_md   = NULL;
    char_md.p_cccd_md        = NULL;
    char_md.p_sccd_md        = NULL;
    char_md.char_ext_props.wr_aux = 0;
    char_md.char_ext_props.reliable_wr = 0;
    char_md.char_props.read   = 1;
    char_md.char_props.write  = 0;

    BLE_UUID_BLE_ASSIGN(ble_uuid, uuid);

    memset(&attr_md, 0, sizeof(attr_md));

    attr_md.read_perm  = dis_attr_md->read_perm;
    attr_md.write_perm = dis_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  = char_len;
    attr_char_value.init_offs = 0;
    attr_char_value.max_len   = char_len;
    attr_char_value.p_value   = p_char_value;

    return sd_ble_gatts_characteristic_add(m_dev_service.svc_h, &char_md, &attr_char_value, p_handles);
}

thanks in advance

Paul

  • Hi Paul, 

    It could be a bug inside our nRFConnect code. Which nRFConnect were you testing with ? If you were testing with the nRFConnect on PC, could you try the same with nRFConnect on Android/iOS. 

    Please be aware that setting char_md.char_ext_props.wr_aux is only control the properties of the characteristic. What more important is the permission of the characteristic/user description of the characteristic. The permission decides if the attribute can be written or not. The property is only providing information, as a reference. 

  • Hi Hung,

                    thanks for this. I am seeing the behavior on the Android version of nrfConnect. I haven't seen how to get the same functionality on the PC version on Linux.

    char_md.char_ext_props.wr_aux is documented as: "Writing the Characteristic User Description descriptor permitted." hence my setting of it. I also set the metadata for the description - pointed to in the same struct to no access.

    How are you supposed to set the permission?

    Cheers Paul

  • To change the permission, you set this value: user_descr_attr_md.read_perm. Have a look inside characteristic_add() in ble_srv_common.c , we set the value of that in: 

       set_security_req(p_char_props->p_user_descr->read_access, &user_descr_attr_md.read_perm);

  • Thanks Hung,

                              essentially set_security_req applies the security setting macros to the two permission variables in the user_description metadata. I am already doing the equivalent:

    BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&desc_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&desc_md.write_perm);

    So I guess you are right in saying that nrfConnect probably has a bug.

    Cheers Paul

Related