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

Difference between attr_char_value.init_len and attr_char_value.max_len

Hi,

When creating and adding characteristic to service, what is the meaning and difference between these two variables:

attr_char_value.init_len 
attr_char_value.max_len   

To give context, my aim is to write a value of variable length to a characteristic. I have set the variable vlen to one as it was zero

attr_md.vlen    = 1; // = 0;

Am I right to assume that I should change this value to one to send variable length values to this characteristic? That is my second question.

  • To quote the spec (v5.0 Vol 3, Part F, 3.2.4 "Attribute Value"):

    An attribute value is an octet array that may be either fixed or variable length. For example, it can be a one octet value, or a four octet integer, or a variable length string.

    In other words, init_len and max_len describe the initial length and maximum allowed length, respectively. If vlen is 0 then it does not make sense to have different values for these variables. I am not sure what behavior the SoftDevice enforces in this case.

    To answer your second question: Yes, if you want to be able to send variable length values then vlen needs to be set to 1.

Related