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

[S132, S140] char_props.write=0 doesn't prevent writing

Hello,

There is a characteristic with properties:

memset(&char_md, 0, sizeof(char_md));
...
attr_md.vloc    = BLE_GATTS_VLOC_USER;
...
char_md.char_props.write = 0;
char_md.char_props.read = 1;
attr_char_value.init_len = 16
attr_char_value.max_len = 16
attr_char_value.p_value = device_data;

When reading with gatttool, 16 bytes are read. But, after writing (char-write-rec) to this char., the length becames to be a number of bytes that was written, e.g., after writing 1 byte, 1 byte of data will be read then (instead of 16 that must always be).

Questions:

  1. Why props.write=0 doesn't prevent writing and length corruption on the stack level?
  2. How to prevent length corruption when data is stored on the user location?
Parents
  • Hi,

    The char_props only set the properties of the characteristic. It doesn't prevent the characteristic being written. The properties are for information (to the peer) only.

    If you want to prevent your characteristic being written, you need to use permission, for example attr_md.write_perm. Set BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm) will block any write to the characteristic.

    To fix the length of the characteristic, you set vlen (Variable length attribute) = 0.

Reply
  • Hi,

    The char_props only set the properties of the characteristic. It doesn't prevent the characteristic being written. The properties are for information (to the peer) only.

    If you want to prevent your characteristic being written, you need to use permission, for example attr_md.write_perm. Set BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm) will block any write to the characteristic.

    To fix the length of the characteristic, you set vlen (Variable length attribute) = 0.

Children
Related