Go to the documentation of this file.
31 #ifndef _COAP_SERVER_H
32 #define _COAP_SERVER_H
41 #ifndef COAP_SERVER_SUPPORT
42 #define COAP_SERVER_SUPPORT ENABLED
43 #elif (COAP_SERVER_SUPPORT != ENABLED && COAP_SERVER_SUPPORT != DISABLED)
44 #error COAP_SERVER_SUPPORT parameter is not valid
48 #ifndef COAP_SERVER_DTLS_SUPPORT
49 #define COAP_SERVER_DTLS_SUPPORT DISABLED
50 #elif (COAP_SERVER_DTLS_SUPPORT != ENABLED && COAP_SERVER_DTLS_SUPPORT != DISABLED)
51 #error COAP_SERVER_DTLS_SUPPORT parameter is not valid
55 #ifndef COAP_SERVER_OBSERVE_SUPPORT
56 #define COAP_SERVER_OBSERVE_SUPPORT DISABLED
57 #elif (COAP_SERVER_OBSERVE_SUPPORT != ENABLED && COAP_SERVER_OBSERVE_SUPPORT != DISABLED)
58 #error COAP_SERVER_OBSERVE_SUPPORT parameter is not valid
62 #ifndef COAP_SERVER_STACK_SIZE
63 #define COAP_SERVER_STACK_SIZE 650
64 #elif (COAP_SERVER_STACK_SIZE < 1)
65 #error COAP_SERVER_STACK_SIZE parameter is not valid
69 #ifndef COAP_SERVER_TICK_INTERVAL
70 #define COAP_SERVER_TICK_INTERVAL 250
71 #elif (COAP_SERVER_TICK_INTERVAL < 100)
72 #error COAP_SERVER_TICK_INTERVAL parameter is not valid
76 #ifndef COAP_SERVER_SESSION_TIMEOUT
77 #define COAP_SERVER_SESSION_TIMEOUT 120000
78 #elif (COAP_SERVER_SESSION_TIMEOUT < 0)
79 #error COAP_SERVER_SESSION_TIMEOUT parameter is not valid
83 #ifndef COAP_SERVER_MAX_RETRANSMIT
84 #define COAP_SERVER_MAX_RETRANSMIT 4
85 #elif (COAP_SERVER_MAX_RETRANSMIT < 1)
86 #error COAP_SERVER_MAX_RETRANSMIT parameter is not valid
90 #ifndef COAP_SERVER_ACK_TIMEOUT_MIN
91 #define COAP_SERVER_ACK_TIMEOUT_MIN 2000
92 #elif (COAP_SERVER_ACK_TIMEOUT_MIN < 1000)
93 #error COAP_SERVER_ACK_TIMEOUT_MIN
97 #ifndef COAP_SERVER_ACK_TIMEOUT_MAX
98 #define COAP_SERVER_ACK_TIMEOUT_MAX 3000
99 #elif (COAP_SERVER_ACK_TIMEOUT_MAX < COAP_SERVER_ACK_TIMEOUT_MIN)
100 #error COAP_SERVER_ACK_TIMEOUT_MAX
104 #ifndef COAP_SERVER_MIN_NON_CONFIRMABLE_NOTIF_INTERVAL
105 #define COAP_SERVER_MIN_NON_CONFIRMABLE_NOTIF_INTERVAL 3000
106 #elif (COAP_SERVER_MIN_NON_CONFIRMABLE_NOTIF_INTERVAL < 0)
107 #error COAP_SERVER_MIN_NON_CONFIRMABLE_NOTIF_INTERVAL
111 #ifndef COAP_SERVER_MAX_CONFIRMABLE_NOTIF_INTERVAL
112 #define COAP_SERVER_MAX_CONFIRMABLE_NOTIF_INTERVAL 60000
113 #elif (COAP_SERVER_MAX_CONFIRMABLE_NOTIF_INTERVAL < 1000)
114 #error COAP_SERVER_MAX_CONFIRMABLE_NOTIF_INTERVAL
118 #ifndef COAP_SERVER_BUFFER_SIZE
119 #define COAP_SERVER_BUFFER_SIZE 2048
120 #elif (COAP_SERVER_BUFFER_SIZE < 1)
121 #error COAP_SERVER_BUFFER_SIZE parameter is not valid
125 #ifndef COAP_SERVER_MAX_OBS_RESOURCE_SIZE
126 #define COAP_SERVER_MAX_OBS_RESOURCE_SIZE 512
127 #elif (COAP_SERVER_MAX_OBS_RESOURCE_SIZE < 1)
128 #error COAP_SERVER_MAX_OBS_RESOURCE_SIZE parameter is not valid
132 #ifndef COAP_SERVER_MAX_COOKIE_SECRET_SIZE
133 #define COAP_SERVER_MAX_COOKIE_SECRET_SIZE 32
134 #elif (COAP_SERVER_MAX_COOKIE_SECRET_SIZE < 1)
135 #error COAP_SERVER_MAX_COOKIE_SECRET_SIZE parameter is not valid
139 #ifndef COAP_SERVER_MAX_URI_LEN
140 #define COAP_SERVER_MAX_URI_LEN 128
141 #elif (COAP_SERVER_MAX_URI_LEN < 1)
142 #error COAP_SERVER_MAX_URI_LEN parameter is not valid
146 #ifndef COAP_SERVER_PRIORITY
147 #define COAP_SERVER_PRIORITY OS_TASK_PRIORITY_NORMAL
151 #ifndef COAP_SERVER_PRIVATE_CONTEXT
152 #define COAP_SERVER_PRIVATE_CONTEXT
156 #if (COAP_SERVER_DTLS_SUPPORT == ENABLED)
164 #define CoapServerContext struct _CoapServerContext
168 #define CoapDtlsSession struct _CoapDtlsSession
172 #define CoapResource struct _CoapResource
176 #define CoapObserver struct _CoapObserver
205 #if (COAP_SERVER_DTLS_SUPPORT == ENABLED)
243 #if (COAP_SERVER_DTLS_SUPPORT == ENABLED)
247 #if (COAP_SERVER_OBSERVE_SUPPORT == ENABLED)
254 #if (COAP_SERVER_DTLS_SUPPORT == ENABLED)
258 #if (COAP_SERVER_OBSERVE_SUPPORT == ENABLED)
273 #if (COAP_SERVER_DTLS_SUPPORT == ENABLED)
277 #if (COAP_SERVER_OBSERVE_SUPPORT == ENABLED)
284 #if (COAP_SERVER_DTLS_SUPPORT == ENABLED)
288 #if (COAP_SERVER_OBSERVE_SUPPORT == ENABLED)
307 #if (COAP_SERVER_DTLS_SUPPORT == ENABLED)
311 #if (COAP_SERVER_DTLS_SUPPORT == ENABLED && TLS_TICKET_SUPPORT == ENABLED)
314 #if (COAP_SERVER_OBSERVE_SUPPORT == ENABLED)
332 #if (COAP_SERVER_DTLS_SUPPORT == ENABLED)
383 const uint8_t *cookieSecret,
size_t cookieSecretLen);
CoapServerRequestCallback requestCallback
CoAP request callback.
IpAddr remoteIpAddr
Source IP address of the received CoAP request.
OsTaskParameters taskParams
Task parameters.
NetInterface * interface
Underlying network interface.
error_t(* CoapServerUdpInitCallback)(CoapServerContext *context, Socket *socket)
UDP initialization callback function.
size_t tokenLen
Length of the token.
uint_t numResources
Maximum number of observable resources.
OsMutex mutex
Mutex preventing simultaneous access to the context.
uint16_t mid
Message identifier.
NetInterface * interface
Underlying network interface.
NetInterface * interface
Underlying network interface.
IpAddr serverIpAddr
Server's IP address.
CoapResource * resources
List of observable resources.
CoapObserver * observers
List of registered observers.
uint_t numSessions
Maximum number of DTLS sessions.
CoapServerObserveCallback observeCallback
Observe callback.
NetInterface * interface
Underlying network interface.
CoapServerUdpInitCallback udpInitCallback
UDP initialization callback.
CoapMessageType type
Message type.
CoapResource * resource
Observer state.
uint16_t clientPort
Client's port.
uint_t numObservers
Maximum number of observers.
IpAddr clientIpAddr
Client's IP address.
char_t uri[COAP_SERVER_MAX_URI_LEN+1]
Resource identifier.
CoAP message formatting and parsing.
uint16_t clientPort
Client's port.
OsTaskId taskId
Task identifier.
uint16_t port
CoAP port number.
OsTaskParameters task
Task parameters.
@ COAP_OBSERVER_STATE_UNREGISTERED
Session ticket encryption context.
@ COAP_OBSERVER_STATE_UPDATING
CoapServerUdpInitCallback udpInitCallback
UDP initialization callback.
uint_t numObservers
Maximum number of observers.
CoapServerObserveCallback observeCallback
Observe callback.
NetContext * netContext
TCP/IP stack context.
uint_t numSessions
Maximum number of DTLS sessions.
OsEvent event
Event object used to poll the underlying socket.
int_t socket(int_t family, int_t type, int_t protocol)
Create a socket that is bound to a specific transport service provider.
CoapObserver * observers
Observers.
char_t uri[COAP_SERVER_MAX_URI_LEN+1]
Resource identifier.
NetInterface * localInterface
Network interface the CoAP request was received on.
CoapServerDtlsInitCallback dtlsInitCallback
DTLS initialization callback.
error_t coapServerDeleteResource(CoapServerContext *context, const char_t *uri)
Delete an observable resource.
size_t dataLen
Length of the resource state.
uint8_t data[COAP_SERVER_MAX_OBS_RESOURCE_SIZE]
Resource state.
void coapServerDeinit(CoapServerContext *context)
Release CoAP server context.
CoapMessage response
CoAP response message.
error_t coapServerStop(CoapServerContext *context)
Stop CoAP server.
General definitions for cryptographic algorithms.
size_t bufferLen
Length of the buffer, in bytes.
error_t coapServerUpdateResource(CoapServerContext *context, const char_t *uri, const void *data, size_t length)
Update the state of an observable resource.
uint8_t token[COAP_MAX_TOKEN_LEN]
Token.
NetContext * netContext
TCP/IP stack context.
uint16_t remotePort
Source port of the received CoAP request.
bool_t changed
The resource state has changed.
systime_t retransmitTimeout
Retransmission timeout.
uint32_t systime_t
System time.
uint8_t buffer[COAP_SERVER_BUFFER_SIZE]
Memory buffer for input/output operations.
IpAddr serverIpAddr
Server's IP address.
CoapServerContext * context
Pointer to the CoAP server context.
TlsContext * dtlsContext
DTLS context.
CoapDtlsSession * sessions
DTLS sessions.
CoapMessageType
CoAP message types.
CoapObserverState
Observer states.
@ COAP_OBSERVER_STATE_REGISTERED
#define COAP_SERVER_MAX_URI_LEN
TlsTicketContext dtlsTicketContext
DTLS ticket encryption context.
uint_t numResources
Maximum number of observable resources.
#define CoapServerContext
CoapServerRequestCallback requestCallback
CoAP request callback.
#define COAP_MAX_TOKEN_LEN
error_t coapServerCreateResource(CoapServerContext *context, const char_t *uri)
Create a new observable resource.
uint8_t cookieSecret[COAP_SERVER_MAX_COOKIE_SECRET_SIZE]
Cookie secret.
error_t(* CoapServerRequestCallback)(CoapServerContext *context, CoapCode method, const char_t *uri)
CoAP request callback function.
IpAddr clientIpAddr
Client's IP address.
CoapMessage request
CoAP request message.
void coapServerGetDefaultSettings(CoapServerSettings *settings)
Initialize settings with default values.
systime_t ackTimestamp
Time at which the last acknowledgement was received.
systime_t retransmitTimestamp
Time at which the last message was sent.
TLS (Transport Layer Security)
error_t coapServerStart(CoapServerContext *context)
Start CoAP server.
#define COAP_SERVER_PRIVATE_CONTEXT
CoapServerDtlsInitCallback dtlsInitCallback
DTLS initialization callback.
bool_t running
Operational state of the CoAP server.
thread_t * OsTaskId
Task identifier.
uint16_t port
CoAP port number.
CoapResource * resources
Observable resources.
#define COAP_SERVER_MAX_COOKIE_SECRET_SIZE
IpAddr localIpAddr
Destination IP address of the received CoAP request.
uint16_t mid
Message identifier.
systime_t timestamp
Timestamp to manage timeout.
CoapDtlsSession * sessions
DTLS sessions.
error_t(* CoapServerDtlsInitCallback)(CoapServerContext *context, TlsContext *dtlsContext)
DTLS initialization callback.
void coapServerTask(CoapServerContext *context)
CoAP server task.
size_t cookieSecretLen
Length of the cookie secret, in bytes.
error_t(* CoapServerObserveCallback)(CoapServerContext *context, CoapObserver *observer, CoapResource *resource)
Observe callback function.
Socket * socket
Underlying socket.
#define COAP_SERVER_BUFFER_SIZE
CoapCode
CoAP method and response codes.
uint32_t seqNum
Sequence number.
Definitions common to CoAP client and server.
#define COAP_SERVER_MAX_OBS_RESOURCE_SIZE
Formatting and parsing of CoAP options.
error_t coapServerInit(CoapServerContext *context, const CoapServerSettings *settings)
CoAP server initialization.
error_t coapServerSetCookieSecret(CoapServerContext *context, const uint8_t *cookieSecret, size_t cookieSecretLen)
Set cookie secret.
uint_t retransmitCount
Retransmission counter.