mikroSDK Reference Manual
coap_common.h
Go to the documentation of this file.
1
31#ifndef _COAP_COMMON_H
32#define _COAP_COMMON_H
33
34//Dependencies
35#include "core/net.h"
36
37//CoAP port number
38#define COAP_PORT 5683
39//DTLS-secured CoAP port number
40#define COAPS_PORT 5684
41
42//CoAP message header size
43#define COAP_HEADER_SIZE 4
44//Maximum acceptable length for tokens
45#define COAP_MAX_TOKEN_LEN 8
46
47//CoAP payload marker value
48#define COAP_PAYLOAD_MARKER 0xFF
49
50//CoAP code definition
51#define COAP_CODE(c, d) ((((c) & 0x07U) << 5U) | ((d) & 0x1FU))
52
53//Get code class
54#define COAP_GET_CODE_CLASS(code) (((code) >> 5U) & 0x07U)
55//Get code subclass
56#define COAP_GET_CODE_SUBCLASS(code) ((code) & 0x1FU)
57
58//C++ guard
59#ifdef __cplusplus
60extern "C" {
61#endif
62
63
68typedef enum {
71
72
81
82
94
95
100typedef enum
101{
102 COAP_CODE_CLASS_SUCCESS = 2,
103 COAP_CODE_CLASS_CLIENT_ERROR = 4,
104 COAP_CODE_CLASS_SERVER_ERROR = 5
106
107
112typedef enum
113{
114 COAP_CODE_EMPTY = COAP_CODE(0, 0),
115 COAP_CODE_GET = COAP_CODE(0, 1),
116 COAP_CODE_POST = COAP_CODE(0, 2),
117 COAP_CODE_PUT = COAP_CODE(0, 3),
118 COAP_CODE_DELETE = COAP_CODE(0, 4),
119 COAP_CODE_FETCH = COAP_CODE(0, 5),
120 COAP_CODE_PATCH = COAP_CODE(0, 6),
121 COAP_CODE_IPATCH = COAP_CODE(0, 7),
122 COAP_CODE_CREATED = COAP_CODE(2, 1),
123 COAP_CODE_DELETED = COAP_CODE(2, 2),
124 COAP_CODE_VALID = COAP_CODE(2, 3),
125 COAP_CODE_CHANGED = COAP_CODE(2, 4),
126 COAP_CODE_CONTENT = COAP_CODE(2, 5),
127 COAP_CODE_CONTINUE = COAP_CODE(2, 31),
128 COAP_CODE_BAD_REQUEST = COAP_CODE(4, 0),
129 COAP_CODE_UNAUTHOZED = COAP_CODE(4, 1),
130 COAP_CODE_BAD_OPTION = COAP_CODE(4, 2),
131 COAP_CODE_FORBIDDEN = COAP_CODE(4, 3),
132 COAP_CODE_NOT_FOUND = COAP_CODE(4, 4),
133 COAP_CODE_METHOD_NOT_ALLOWED = COAP_CODE(4, 5),
134 COAP_CODE_NOT_ACCEPTABLE = COAP_CODE(4, 6),
135 COAP_CODE_REQUEST_ENTITY_INCOMPLETE = COAP_CODE(4, 8),
136 COAP_CODE_CONFLICT = COAP_CODE(4, 9),
137 COAP_CODE_PRECONDITION_FAILED = COAP_CODE(4, 12),
138 COAP_CODE_REQUEST_ENTITY_TO_LARGE = COAP_CODE(4, 13),
139 COAP_CODE_UNSUPPORTED_CONTENT_FORMAT = COAP_CODE(4, 15),
140 COAP_CODE_UNPROCESSABLE_ENTITY = COAP_CODE(4, 22),
141 COAP_CODE_INTERNAL_SERVER = COAP_CODE(5, 0),
142 COAP_CODE_NOT_IMPLEMENTED = COAP_CODE(5, 1),
143 COAP_CODE_BAD_GATEWAY = COAP_CODE(5, 2),
144 COAP_CODE_SERVICE_UNAVAILABLE = COAP_CODE(5, 3),
145 COAP_CODE_GATEWAY_TIMEOUT = COAP_CODE(5, 4),
146 COAP_CODE_PROXYING_NOT_SUPPORTED = COAP_CODE(5, 5),
147 COAP_CODE_HOP_LIMIT_REACHED = COAP_CODE(5, 8),
148 COAP_CODE_CSM = COAP_CODE(7, 1),
149 COAP_CODE_PING = COAP_CODE(7, 2),
150 COAP_CODE_PONG = COAP_CODE(7, 3),
151 COAP_CODE_RELEASE = COAP_CODE(7, 4),
152 COAP_CODE_ABORT = COAP_CODE(7, 5)
153} CoapCode;
154
155
156//CodeWarrior or Win32 compiler?
157#if defined(__CWCC__) || defined(_WIN32)
158 #pragma pack(push, 1)
159#endif
160
161
167{
168#if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
169 uint8_t version : 2; //0
170 uint8_t type : 2;
171 uint8_t tokenLen : 4;
172#else
173 uint8_t tokenLen : 4; //0
174 uint8_t type : 2;
175 uint8_t version : 2;
176#endif
177 uint8_t code; //1
178 uint16_t mid; //2-3
179 uint8_t token[]; //4
180} CoapMessageHeader;
181
182
187typedef __packed_struct
188{
189#if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
190 uint8_t delta : 4; //0
191 uint8_t length : 4;
192#else
193 uint8_t length : 4; //0
194 uint8_t delta : 4;
195#endif
196} CoapOptionHeader;
197
198
199//CodeWarrior or Win32 compiler?
200#if defined(__CWCC__) || defined(_WIN32)
201 #pragma pack(pop)
202#endif
203
204//C++ guard
205#ifdef __cplusplus
206}
207#endif
208
209#endif
CoapProtocolLevel
CoAP version numbers.
Definition coap_common.h:68
@ COAP_VERSION_1
CoAP version 1.
Definition coap_common.h:69
CoapMessageType
CoAP message types.
Definition coap_common.h:88
@ COAP_TYPE_RST
Reset message.
Definition coap_common.h:92
@ COAP_TYPE_NON
Non-confirmable message.
Definition coap_common.h:90
@ COAP_TYPE_CON
Confirmable message.
Definition coap_common.h:89
@ COAP_TYPE_ACK
Acknowledgment message.
Definition coap_common.h:91
typedef __packed_struct
CoAP message format.
Definition coap_common.h:167
CoapTransportProtocol
CoAP transport protocols.
Definition coap_common.h:77
@ COAP_TRANSPORT_PROTOCOL_UDP
UDP protocol.
Definition coap_common.h:78
@ COAP_TRANSPORT_PROTOCOL_DTLS
DTLS protocol.
Definition coap_common.h:79
CoapCodeClass
CoAP code classes.
Definition coap_common.h:101
CoapCode
CoAP method and response codes.
Definition coap_common.h:113
TCP/IP stack core.