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

for write_wo_resp and write

Hi. I'm using nRF52832, SDK13.0.0.

I made my code as below.

    char_md.char_props.notify = 1;
    char_md.char_props.read= 1;
    char_md.char_props.write= 1;
//    char_md.char_props.write_wo_resp= 1;
    char_md.p_char_user_desc  = NULL;
    char_md.p_char_pf         = NULL;
    char_md.p_user_desc_md    = NULL;
    char_md.p_cccd_md         = &cccd_md;
    char_md.p_sccd_md         = NULL;

I didn't allow to use "write_wo_resp".

But my central can assess with write command.

I don't know why.

Could you please let me know why central can use write command?

Parents
  • Hi,

     

    char_md sets the properties found when scanning/advertising, while attr_md sets the actual attribute permissions. See this post for more information:

    https://devzone.nordicsemi.com/f/nordic-q-a/20382/i-have-a-question-about-configuration-of-charateristic-value-r-w-permission#post-id-120910

     

    Best regards,

    Håkon

  • Hi.

    Thank you very much for your reply.

    My code is

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

        char_md.char_props.notify = 1;
        char_md.char_props.read= 1;
        char_md.char_props.write= 1;
    //    char_md.char_props.write_wo_resp= 1;
        char_md.p_char_user_desc  = NULL;
        char_md.p_char_pf         = NULL;
        char_md.p_user_desc_md    = NULL;
        char_md.p_cccd_md         = &cccd_md;
        char_md.p_sccd_md         = NULL;

        ble_uuid.type = p_iRevo_p->uuid_type;
        ble_uuid.uuid = BLE_UUID_iRevo_p_RX_CHARACTERISTIC;

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

        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);

        attr_md.vloc    = BLE_GATTS_VLOC_STACK;
        attr_md.rd_auth = 0;
        attr_md.wr_auth = 0;
        attr_md.vlen    = 1;

        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  = sizeof(uint8_t);
        attr_char_value.init_offs = 0;
        attr_char_value.max_len   = BLE_iRevo_p_MAX_RX_CHAR_LEN;

        return sd_ble_gatts_characteristic_add(p_iRevo_p->service_handle,
                                               &char_md,
                                               &attr_char_value,
                                               &m_char_handles);

    If I don't want to allow central to use write command, how can I do?

  • Hi,

     

    Then you'll have to call "BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.write_perm)"

    Kind regards,

    Håkon

Reply Children
  • Hi.

    Thank you so much.

    There are 2 options, write and write command.

    So I think I can make it 4 cases.

    1. write enabled, write command enabled.

    2. write enabled, write command disabled.

    3. write disabled, write command enabled.

    4. write disabled, write command disabled.

    How can I make these cases using "BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.write_perm)" or "BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm)" function?

  • My former answer will force a "read only" permission, which would cover case 2 and 4. As the bluetooth specification states that the char_md setting shall be consistent with the attr_md permissions, you shall not set one enabled and the other disabled.

    By setting the attr_md.write_perm to "BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS" (or other defines in ble_gap.h group BLE_GAP_CONN_SEC_MODE_SET_MACROS, based on your security needs), you will cover 1 and 3.

    Please note that you cannot dynamically change a characteristic without repopulating the GATT table (ie: disable/enable the softdevice).

     

    As stated in the linked answer, attr_md sets the properties while char_md is shown as an indicator during advertisement.

    It sounds like you want to use "write authorization" (attr_md.wr_auth), which is where the application enables the use of WRITE_REQ (the application can choose to NACK/ACK the data), which is different from the WRITE_CMD as you're using now.

     

    Best regards,

    Håkon

Related