diff --git a/include/openthread/coap.h b/include/openthread/coap.h index 7e2312040..396d53573 100644 --- a/include/openthread/coap.h +++ b/include/openthread/coap.h @@ -717,6 +717,15 @@ otCoapType otCoapMessageGetType(const otMessage *aMessage); */ otCoapCode otCoapMessageGetCode(const otMessage *aMessage); +/** + * This function sets the Code value. + * + * @param[inout] aMessage A pointer to the CoAP message to initialize. + * @param[in] aCode CoAP message code. + * + */ +void otCoapMessageSetCode(otMessage *aMessage, otCoapCode aCode); + /** * This method returns the CoAP Code as human readable string. * diff --git a/include/openthread/instance.h b/include/openthread/instance.h index e06b7754e..699941c5d 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (186) +#define OPENTHREAD_API_VERSION (187) /** * @addtogroup api-instance diff --git a/src/core/api/coap_api.cpp b/src/core/api/coap_api.cpp index 48353678e..4dfb35edf 100644 --- a/src/core/api/coap_api.cpp +++ b/src/core/api/coap_api.cpp @@ -144,6 +144,11 @@ otCoapCode otCoapMessageGetCode(const otMessage *aMessage) return static_cast(AsCoapMessage(aMessage).GetCode()); } +void otCoapMessageSetCode(otMessage *aMessage, otCoapCode aCode) +{ + AsCoapMessage(aMessage).SetCode(MapEnum(aCode)); +} + const char *otCoapMessageCodeToString(const otMessage *aMessage) { return AsCoapMessage(aMessage).CodeToString();