From 52669a925a86cfd9180086e7957bcd6f2b1194a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Duda?= Date: Fri, 26 Oct 2018 06:08:17 +0200 Subject: [PATCH] [coap] add support for CoAP header exceeding 255 bytes (#3210) --- include/openthread/coap.h | 4 ++-- src/core/coap/coap_header.cpp | 2 +- src/core/coap/coap_header.hpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/openthread/coap.h b/include/openthread/coap.h index 8a73d58e7..4cfed8d8d 100644 --- a/include/openthread/coap.h +++ b/include/openthread/coap.h @@ -165,7 +165,7 @@ typedef enum otCoapOptionContentFormat { OT_COAP_OPTION_CONTENT_FORMAT_JWS = 101 ///< application/json-web-signature } otCoapOptionContentFormat; -#define OT_COAP_HEADER_MAX_LENGTH 128 ///< Max CoAP header length (bytes) +#define OT_COAP_HEADER_MAX_LENGTH 512 ///< Max CoAP header length (bytes) /** * This structure represents a CoAP header. @@ -183,7 +183,7 @@ typedef struct otCoapHeader } mFields; ///< Structure representing a CoAP base header uint8_t mBytes[OT_COAP_HEADER_MAX_LENGTH]; ///< The raw byte encoding for the CoAP header } mHeader; ///< The CoAP header encoding - uint8_t mHeaderLength; ///< The CoAP header length (bytes) + uint16_t mHeaderLength; ///< The CoAP header length (bytes) uint16_t mOptionLast; ///< The last CoAP Option Number value uint16_t mFirstOptionOffset; ///< The byte offset for the first CoAP Option uint16_t mNextOptionOffset; ///< The byte offset for the next CoAP Option diff --git a/src/core/coap/coap_header.cpp b/src/core/coap/coap_header.cpp index 052efcfe3..7c86d4889 100644 --- a/src/core/coap/coap_header.cpp +++ b/src/core/coap/coap_header.cpp @@ -249,7 +249,7 @@ otError Header::AppendOption(const Option &aOption) memcpy(cur, aOption.mValue, aOption.mLength); cur += aOption.mLength; - mHeaderLength += static_cast(cur - buf); + mHeaderLength += static_cast(cur - buf); mOptionLast = aOption.mNumber; exit: diff --git a/src/core/coap/coap_header.hpp b/src/core/coap/coap_header.hpp index d5a067e1d..cf8e30e38 100644 --- a/src/core/coap/coap_header.hpp +++ b/src/core/coap/coap_header.hpp @@ -402,7 +402,7 @@ public: * @returns The header length in bytes. * */ - uint8_t GetLength(void) const { return mHeaderLength; } + uint16_t GetLength(void) const { return mHeaderLength; } /** * This method sets a default response header based on request header.