net: lwm2m: Deprecate LWM2M_ENGINE_MESSAGE_HEADER_SIZE
Kconfig value LWM2M_ENGINE_MESSAGE_HEADER_SIZE added an extra headroom for CoAP packet sizes so that if CoAP Block-Wise transfer block-size is configured to be same as LWM2M_COAP_MAX_MSG_SIZE, the full payload block would usually fit to the datagram. This causes too much confusion to be usable. CoAP headers and options vary on sizes, and there is no runtime limitations that we should check the header size against. Only real limitation is the CoAP packet size, which must fit into the UDP datagram with typical DTLS headers. Only limitation for CoAP block-size then is that it must fit into the CoAP message with all the headers and options. But as the option sizes, like path, vary, it must be checked runtime. Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
This commit is contained in:
parent
044a94f06a
commit
05abdf5d0b
7 changed files with 32 additions and 29 deletions
|
@ -67,6 +67,12 @@ Deprecated APIs and options
|
|||
renamed and deprecated. Use :kconfig:option:`CONFIG_SCHED_SIMPLE` and
|
||||
:kconfig:option:`CONFIG_WAITQ_SIMPLE` instead.
|
||||
|
||||
* The :kconfig:option:`CONFIG_LWM2M_ENGINE_MESSAGE_HEADER_SIZE` Kconfig option has been removed.
|
||||
The required header size should be included in the message size, configured using
|
||||
:kconfig:option:`CONFIG_LWM2M_COAP_MAX_MSG_SIZE`. Special care should be taken to ensure that
|
||||
used CoAP block size :kconfig:option:`CONFIG_LWM2M_COAP_BLOCK_SIZE` can fit given message size
|
||||
with headers. Previous headroom was 48 bytes.
|
||||
|
||||
* TLS credential type ``TLS_CREDENTIAL_SERVER_CERTIFICATE`` was renamed and
|
||||
deprecated, use :c:enumerator:`TLS_CREDENTIAL_PUBLIC_CERTIFICATE` instead.
|
||||
|
||||
|
|
|
@ -273,25 +273,25 @@ config LWM2M_ENGINE_MAX_MESSAGES
|
|||
|
||||
config LWM2M_COAP_BLOCK_SIZE
|
||||
int "LWM2M CoAP block-wise transfer size"
|
||||
default 256
|
||||
default 512
|
||||
range 64 1024
|
||||
help
|
||||
CoAP block size used by LwM2M when performing block-wise
|
||||
transfers. Possible values: 64, 128, 256, 512 and 1024.
|
||||
|
||||
config LWM2M_ENGINE_MESSAGE_HEADER_SIZE
|
||||
int "Room for CoAP header data"
|
||||
default 48
|
||||
range 24 128
|
||||
help
|
||||
Extra room allocated to handle CoAP header data
|
||||
When adjusting the value, ensure that LWM2M_COAP_MAX_MSG_SIZE is large enough
|
||||
to fit all CoAP headers and full block size.
|
||||
|
||||
config LWM2M_COAP_MAX_MSG_SIZE
|
||||
int "LWM2M CoAP maximum message size"
|
||||
default LWM2M_COAP_BLOCK_SIZE
|
||||
default 1232 if !LWM2M_DTLS_SUPPORT
|
||||
default 1195 if LWM2M_DTLS_SUPPORT && !LWM2M_DTLS_CID
|
||||
default 1187 if LWM2M_DTLS_SUPPORT && LWM2M_DTLS_CID
|
||||
help
|
||||
CoAP message size used by LWM2M. Minimum is the block size used
|
||||
in blockwise transfers.
|
||||
CoAP message size used by LWM2M. Default is the maximum
|
||||
packet size for IPv6 network (MTU(1280)-IPv6(40)-UDP(8)-DTLS(29..53)).
|
||||
If the network has a smaller MTU, this value should be adjusted accordingly.
|
||||
If CoAP block-wise transfer is enabled, this value should be larger than
|
||||
the block size and estimated CoAP header sizes.
|
||||
|
||||
config LWM2M_ENGINE_VALIDATION_BUFFER_SIZE
|
||||
int "Size of the validation buffer for the incoming data"
|
||||
|
|
|
@ -383,6 +383,7 @@ STATIC int build_msg_block_for_send(struct lwm2m_message *msg, uint16_t block_nu
|
|||
ret = buf_append(CPKT_BUF_WRITE(&msg->cpkt),
|
||||
complete_payload + (block_num * block_size_bytes), payload_size);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("CoAP message size overflow");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -392,19 +393,16 @@ STATIC int build_msg_block_for_send(struct lwm2m_message *msg, uint16_t block_nu
|
|||
STATIC int prepare_msg_for_send(struct lwm2m_message *msg)
|
||||
{
|
||||
int ret;
|
||||
uint16_t len;
|
||||
const uint8_t *payload;
|
||||
|
||||
/* save the big buffer for later use (splitting blocks) */
|
||||
msg->body_encode_buffer = msg->cpkt;
|
||||
|
||||
/* set the default (small) buffer for sending blocks */
|
||||
msg->cpkt.data = msg->msg_data;
|
||||
msg->cpkt.offset = 0;
|
||||
msg->cpkt.max_len = MAX_PACKET_SIZE;
|
||||
msg->cpkt.max_len = sizeof(msg->msg_data);
|
||||
|
||||
payload = coap_packet_get_payload(&msg->body_encode_buffer, &len);
|
||||
if (len <= CONFIG_LWM2M_COAP_MAX_MSG_SIZE) {
|
||||
/* Can we fit a whole message into one frame */
|
||||
if (msg->body_encode_buffer.offset <= msg->cpkt.max_len) {
|
||||
|
||||
/* copy the packet */
|
||||
ret = buf_append(CPKT_BUF_WRITE(&msg->cpkt), msg->body_encode_buffer.data,
|
||||
|
@ -422,6 +420,9 @@ STATIC int prepare_msg_for_send(struct lwm2m_message *msg)
|
|||
|
||||
NET_ASSERT(msg->out.block_ctx == NULL, "Expecting to have no context to release");
|
||||
} else {
|
||||
uint16_t len;
|
||||
const uint8_t *payload = coap_packet_get_payload(&msg->body_encode_buffer, &len);
|
||||
|
||||
/* Before splitting the content, append Etag option to protect the integrity of
|
||||
* the payload.
|
||||
*/
|
||||
|
|
|
@ -131,15 +131,12 @@
|
|||
|
||||
BUILD_ASSERT(CONFIG_LWM2M_COAP_BLOCK_SIZE <= CONFIG_LWM2M_COAP_MAX_MSG_SIZE,
|
||||
"CoAP block size can't exceed maximum message size");
|
||||
|
||||
#define MAX_PACKET_SIZE (CONFIG_LWM2M_COAP_MAX_MSG_SIZE + \
|
||||
CONFIG_LWM2M_ENGINE_MESSAGE_HEADER_SIZE)
|
||||
|
||||
#if defined(CONFIG_LWM2M_COAP_BLOCK_TRANSFER)
|
||||
BUILD_ASSERT(CONFIG_LWM2M_COAP_ENCODE_BUFFER_SIZE >
|
||||
(CONFIG_LWM2M_COAP_BLOCK_SIZE + CONFIG_LWM2M_ENGINE_MESSAGE_HEADER_SIZE),
|
||||
"The buffer for serializing message needs to be bigger than a message with one block");
|
||||
#endif
|
||||
BUILD_ASSERT(CONFIG_LWM2M_COAP_BLOCK_SIZE == 64 ||
|
||||
CONFIG_LWM2M_COAP_BLOCK_SIZE == 128 ||
|
||||
CONFIG_LWM2M_COAP_BLOCK_SIZE == 256 ||
|
||||
CONFIG_LWM2M_COAP_BLOCK_SIZE == 512 ||
|
||||
CONFIG_LWM2M_COAP_BLOCK_SIZE == 1024,
|
||||
"CoAP block must be 64, 128, 256, 512 or 1024");
|
||||
|
||||
/* buffer util macros */
|
||||
#define CPKT_BUF_WRITE(cpkt) (cpkt)->data, &(cpkt)->offset, (cpkt)->max_len
|
||||
|
@ -494,7 +491,7 @@ struct lwm2m_message {
|
|||
struct coap_packet cpkt;
|
||||
|
||||
/** Buffer data related outgoing message */
|
||||
uint8_t msg_data[MAX_PACKET_SIZE];
|
||||
uint8_t msg_data[CONFIG_LWM2M_COAP_MAX_MSG_SIZE];
|
||||
|
||||
#if defined(CONFIG_LWM2M_COAP_BLOCK_TRANSFER)
|
||||
/** Buffer data containing complete message */
|
||||
|
|
|
@ -14,3 +14,4 @@ CONFIG_LWM2M=y
|
|||
CONFIG_LWM2M_COAP_BLOCK_TRANSFER=y
|
||||
CONFIG_LWM2M_COAP_BLOCK_SIZE=64
|
||||
CONFIG_LWM2M_COAP_ENCODE_BUFFER_SIZE=256
|
||||
CONFIG_LWM2M_COAP_MAX_MSG_SIZE=96
|
||||
|
|
|
@ -21,7 +21,6 @@ target_include_directories(app PRIVATE ${ZEPHYR_BASE}/../modules/crypto/mbedtls/
|
|||
add_compile_definitions(CONFIG_LWM2M_ENGINE_MAX_PENDING=2)
|
||||
add_compile_definitions(CONFIG_LWM2M_ENGINE_MAX_REPLIES=2)
|
||||
add_compile_definitions(CONFIG_LWM2M_ENGINE_VALIDATION_BUFFER_SIZE=512)
|
||||
add_compile_definitions(CONFIG_LWM2M_ENGINE_MESSAGE_HEADER_SIZE=512)
|
||||
add_compile_definitions(CONFIG_LWM2M_ENGINE_MAX_OBSERVER=10)
|
||||
add_compile_definitions(CONFIG_LWM2M_ENGINE_STACK_SIZE=2048)
|
||||
add_compile_definitions(CONFIG_LWM2M_NUM_BLOCK1_CONTEXT=3)
|
||||
|
|
|
@ -18,7 +18,6 @@ target_include_directories(app PRIVATE ${ZEPHYR_BASE}/subsys/net/lib/lwm2m/)
|
|||
add_compile_definitions(CONFIG_LWM2M_ENGINE_MAX_PENDING=2)
|
||||
add_compile_definitions(CONFIG_LWM2M_ENGINE_MAX_REPLIES=2)
|
||||
add_compile_definitions(CONFIG_LWM2M_ENGINE_VALIDATION_BUFFER_SIZE=512)
|
||||
add_compile_definitions(CONFIG_LWM2M_ENGINE_MESSAGE_HEADER_SIZE=512)
|
||||
add_compile_definitions(CONFIG_LWM2M_RD_CLIENT_ENDPOINT_NAME_MAX_LENGTH=32)
|
||||
add_compile_definitions(CONFIG_LWM2M_RD_CLIENT_MAX_RETRIES=2)
|
||||
add_compile_definitions(CONFIG_LWM2M_COAP_BLOCK_SIZE=256)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue