78 kMaxTransmitSpan = kAckTimeout * ((2 << (kMaxRetransmit - 1)) - 1) *
79 kAckRandomFactorNumerator / kAckRandomFactorDenominator,
80 kMaxTransmitWait = kAckTimeout * ((2 << kMaxRetransmit) - 1) *
81 kAckRandomFactorNumerator / kAckRandomFactorDenominator,
83 kProcessingDelay = kAckTimeout,
84 kMaxRtt = 2 * kMaxLatency + kProcessingDelay,
85 kExchangeLifetime = kMaxTransmitSpan + 2 * (kMaxLatency) + kProcessingDelay,
86 kNonLifetime = kMaxTransmitSpan + kMaxLatency
106 mResponseHandler(NULL),
107 mResponseContext(NULL),
109 mRetransmissionTimeout(0),
110 mRetransmissionCount(0),
111 mAcknowledged(false),
112 mConfirmable(false) {};
136 return aMessage.
Append(
this,
sizeof(*
this));
148 return aMessage.
Read(aMessage.
GetLength() -
sizeof(*this),
sizeof(*this),
this);
160 return aMessage.
Write(aMessage.
GetLength() -
sizeof(*this),
sizeof(*this),
this);
171 bool IsEarlier(uint32_t aTime)
const {
return (static_cast<int32_t>(aTime - mNextTimerShot) > 0); };
181 bool IsLater(uint32_t aTime)
const {
return (static_cast<int32_t>(aTime - mNextTimerShot) < 0); };
186 uint16_t mDestinationPort;
188 void *mResponseContext;
189 uint32_t mNextTimerShot;
190 uint32_t mRetransmissionTimeout;
191 uint8_t mRetransmissionCount;
192 bool mAcknowledged: 1;
193 bool mConfirmable: 1;
207 kMaxReceivedUriPath = 32,
234 mHandler(mContext, &aHeader, &aMessage, &aMessageInfo);
259 mMessageInfo(aMessageInfo) {}
280 return aMessage.
Read(aMessage.
GetLength() -
sizeof(*this),
sizeof(*this),
this);
302 bool IsEarlier(uint32_t aTime)
const {
return (static_cast<int32_t>(aTime - mDequeueTime) > 0); }
310 uint32_t GetRemainingTime(
void)
const;
321 uint32_t mDequeueTime;
359 void DequeueOldestResponse(
void);
365 void DequeueAllResponses(
void);
415 void HandleTimer(
void);
423 void DequeueResponse(
Message &aMessage) { mQueue.Dequeue(aMessage); aMessage.
Free(); }
477 uint16_t
GetPort(
void) {
return mSocket.GetSockName().mPort; };
496 void RemoveResource(
Resource &aResource);
514 Message *NewMessage(
const Header &aHeader, uint8_t aPriority = kDefaultCoapMessagePriority);
630 mInterceptor = aInterceptor;
669 void HandleRetransmissionTimer(
void);
708 Message *CopyAndEnqueueMessage(
const Message &aMessage, uint16_t aCopyLength,
710 void DequeueMessage(
Message &aMessage);
730 Interceptor mInterceptor;
734 void *mDefaultHandlerContext;
754 static void HandleRetransmissionTimer(
Timer &aTimer);
755 static void HandleResponsesQueueTimer(
Timer &aTimer);
758 #if OPENTHREAD_ENABLE_APPLICATION_COAP 764 class ApplicationCoap:
public CoapBase 776 static ApplicationCoap &GetOwner(
const Context &aContext);
777 static void HandleRetransmissionTimer(
Timer &aTimer);
778 static void HandleResponsesQueueTimer(
Timer &aTimer);
otError AppendTo(Message &aMessage) const
This method append metadata to the message.
Definition: coap.hpp:269
This type represents all the static / global variables used by OpenThread allocated in one place...
Definition: openthread-instance.h:59
This class implements a message queue.
Definition: message.hpp:806
#define OPENTHREAD_CONFIG_COAP_MAX_RETRANSMIT
Maximum number of retransmissions for CoAP Confirmable messages (RFC7252 default value is 4)...
Definition: openthread-core-default-config.h:413
uint16_t ReadFrom(const Message &aMessage)
This method reads request data from the message.
Definition: coap.hpp:147
otCoapCode
CoAP Code values.
Definition: coap.h:84
void(* Handler)(Timer &aTimer)
This function pointer is called when the timer expires.
Definition: timer.hpp:86
This class implements CoAP resource handling.
Definition: coap.hpp:200
This class implements an IPv6 address object.
Definition: ip6_address.hpp:60
#define OPENTHREAD_CONFIG_COAP_ACK_RANDOM_FACTOR_NUMERATOR
Numerator of ACK_RANDOM_FACTOR used to calculate maximum spacing before first retransmission when ACK...
Definition: openthread-core-default-config.h:392
void HandleResponsesQueueTimer(void)
ResponsesQueue timer handler.
Definition: coap.hpp:678
This file includes definitions for locator class for OpenThread objects.
uint16_t GetLength(void) const
This method returns the number of bytes in the message.
Definition: message.hpp:252
otError SendEmptyAck(const Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo)
This method sends a CoAP ACK message on which a dummy CoAP response is piggybacked.
Definition: coap.hpp:590
Acknowledgment.
Definition: coap.h:70
Changed.
Definition: coap.h:96
const Ip6::MessageInfo & GetMessageInfo(void) const
This method returns the message info of cached CoAP response.
Definition: coap.hpp:318
Input arguments are invalid.
Definition: types.h:147
otError SendNotFound(const Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo)
This method sends a header-only CoAP message to indicate no resource matched for the request...
Definition: coap.hpp:606
This class implements message information for an IPv6 message.
Definition: socket.hpp:57
const MessageQueue & GetRequestMessages(void) const
This method returns a reference to the request message list.
Definition: coap.hpp:640
uint16_t Read(uint16_t aOffset, uint16_t aLength, void *aBuf) const
This method reads bytes from the message.
Definition: message.cpp:475
otError SendReset(Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo)
This method sends a CoAP reset message.
Definition: coap.hpp:546
Resource * GetNext(void) const
This method returns a pointer to the next resource.
Definition: coap.hpp:230
Resource(const char *aUriPath, otCoapRequestHandler aHandler, void *aContext)
This constructor initializes the resource.
Definition: coap.hpp:217
Reset.
Definition: coap.h:71
This class caches CoAP responses to implement message deduplication.
Definition: coap.hpp:329
This type points to an OpenThread message buffer.
Definition: types.h:479
otError SendAck(Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo)
This method sends a CoAP ACK empty message which is used in Separate Response for confirmable request...
Definition: coap.hpp:575
EnqueuedResponseHeader(const Ip6::MessageInfo &aMessageInfo)
Constructor creating object with valid dequeue time and message info.
Definition: coap.hpp:257
This class implements a timer.
Definition: timer.hpp:69
This class implements the millisecond timer.
Definition: timer.hpp:145
static void RemoveFrom(Message &aMessage)
This method removes metadata from the message.
Definition: coap.hpp:289
otCoapType
CoAP Type values.
Definition: coap.h:66
This structure represents a CoAP resource.
Definition: coap.h:224
uint16_t GetPort(void)
This method returns a port number used by CoAP service.
Definition: coap.hpp:477
Low priority level.
Definition: message.hpp:227
This file includes definitions for UDP/IPv6 sockets.
Not Found.
Definition: coap.h:103
void SetInterceptor(Interceptor aInterceptor, void *aContext)
This method sets interceptor to be called before processing a CoAP packet.
Definition: coap.hpp:629
const MessageQueue & GetResponses(void) const
Get a reference to the cached CoAP responses queue.
Definition: coap.hpp:406
This class implements definitions for maintaining a pointer to arbitrary context information.
Definition: context.hpp:61
This class represents a message.
Definition: message.hpp:195
This class implements the common base for CoAP client and server.
Definition: coap.hpp:433
int Write(uint16_t aOffset, uint16_t aLength, const void *aBuf)
This method writes bytes to the message.
Definition: message.cpp:553
bool IsEarlier(uint32_t aTime) const
This method checks if the message shall be sent before the given time.
Definition: coap.hpp:302
This class implements the CoAP client and server.
Definition: coap.hpp:741
int UpdateIn(Message &aMessage) const
This method updates request data in the message.
Definition: coap.hpp:159
otError Append(const void *aBuf, uint16_t aLength)
This method appends bytes to the end of the message.
Definition: message.cpp:405
otError AppendTo(Message &aMessage) const
This method appends request data to the message.
Definition: coap.hpp:135
This file includes definitions for the message buffer pool and message buffers.
CoapMetadata(void)
Default constructor for the object.
Definition: coap.hpp:104
This class implements locator for otInstance object.
Definition: locator.hpp:63
#define OPENTHREAD_CONFIG_COAP_SERVER_MAX_CACHED_RESPONSES
Maximum number of cached responses for CoAP Confirmable messages.
Definition: openthread-core-default-config.h:425
void(* otCoapResponseHandler)(void *aContext, otCoapHeader *aHeader, otMessage *aMessage, const otMessageInfo *aMessageInfo, otError aResult)
This function pointer is called when a CoAP response is received or on the request timeout...
Definition: coap.h:205
This file includes definitions for the multiplexed timer service.
bool IsLater(uint32_t aTime) const
This method checks if the message shall be sent after the given time.
Definition: coap.hpp:181
This file includes functions for debugging.
This file includes definitions for IPv6 packet processing.
#define OPENTHREAD_CONFIG_COAP_ACK_TIMEOUT
Minimum spacing before first retransmission when ACK is not received (RFC7252 default value is 2)...
Definition: openthread-core-default-config.h:381
This structure represents the local and peer IPv6 socket addresses.
Definition: types.h:436
uint16_t ReadFrom(const Message &aMessage)
This method reads request data from the message.
Definition: coap.hpp:279
EnqueuedResponseHeader(void)
Default constructor creating empty object.
Definition: coap.hpp:249
void Free(void)
This method frees this message buffer.
Definition: message.cpp:260
This class implements a UDP/IPv6 socket.
Definition: udp6.hpp:63
bool IsEarlier(uint32_t aTime) const
This method checks if the message shall be sent before the given time.
Definition: coap.hpp:171
#define OPENTHREAD_CONFIG_COAP_ACK_RANDOM_FACTOR_DENOMINATOR
Denominator of ACK_RANDOM_FACTOR used to calculate maximum spacing before first retransmission when A...
Definition: openthread-core-default-config.h:403
This file includes definitions for IPv6 network interfaces.
This file defines the top-level functions for the OpenThread CoAP implementation. ...
void(* otCoapRequestHandler)(void *aContext, otCoapHeader *aHeader, otMessage *aMessage, const otMessageInfo *aMessageInfo)
This function pointer is called when a CoAP request with a given Uri-Path is received.
Definition: coap.h:217
const MessageQueue & GetCachedResponses(void) const
This method returns a reference to the cached response list.
Definition: coap.hpp:648
Confirmable.
Definition: coap.h:68
otError
This enumeration represents error codes used throughout OpenThread.
Definition: types.h:107
otError SetLength(uint16_t aLength)
This method sets the number of bytes in the message.
Definition: message.cpp:289
This file includes compile-time configuration constants for OpenThread.
No error.
Definition: types.h:112