@@ -42,25 +42,25 @@ extern "C" {
42
42
* Refer to RFC 7252, section 12.2 for more information.
43
43
*/
44
44
enum coap_option_num {
45
- COAP_OPTION_IF_MATCH = 1 ,
46
- COAP_OPTION_URI_HOST = 3 ,
47
- COAP_OPTION_ETAG = 4 ,
48
- COAP_OPTION_IF_NONE_MATCH = 5 ,
49
- COAP_OPTION_OBSERVE = 6 ,
50
- COAP_OPTION_URI_PORT = 7 ,
51
- COAP_OPTION_LOCATION_PATH = 8 ,
52
- COAP_OPTION_URI_PATH = 11 ,
53
- COAP_OPTION_CONTENT_FORMAT = 12 ,
54
- COAP_OPTION_MAX_AGE = 14 ,
55
- COAP_OPTION_URI_QUERY = 15 ,
56
- COAP_OPTION_ACCEPT = 17 ,
57
- COAP_OPTION_LOCATION_QUERY = 20 ,
58
- COAP_OPTION_BLOCK2 = 23 ,
59
- COAP_OPTION_BLOCK1 = 27 ,
60
- COAP_OPTION_SIZE2 = 28 ,
61
- COAP_OPTION_PROXY_URI = 35 ,
62
- COAP_OPTION_PROXY_SCHEME = 39 ,
63
- COAP_OPTION_SIZE1 = 60 ,
45
+ COAP_OPTION_IF_MATCH = 1 , /**< If-Match */
46
+ COAP_OPTION_URI_HOST = 3 , /**< Uri-Host */
47
+ COAP_OPTION_ETAG = 4 , /**< ETag */
48
+ COAP_OPTION_IF_NONE_MATCH = 5 , /**< If-None-Match */
49
+ COAP_OPTION_OBSERVE = 6 , /**< Observe (RFC 7641) */
50
+ COAP_OPTION_URI_PORT = 7 , /**< Uri-Port */
51
+ COAP_OPTION_LOCATION_PATH = 8 , /**< Location-Path */
52
+ COAP_OPTION_URI_PATH = 11 , /**< Uri-Path */
53
+ COAP_OPTION_CONTENT_FORMAT = 12 , /**< Content-Format */
54
+ COAP_OPTION_MAX_AGE = 14 , /**< Max-Age */
55
+ COAP_OPTION_URI_QUERY = 15 , /**< Uri-Query */
56
+ COAP_OPTION_ACCEPT = 17 , /**< Accept */
57
+ COAP_OPTION_LOCATION_QUERY = 20 , /**< Location-Query */
58
+ COAP_OPTION_BLOCK2 = 23 , /**< Block2 (RFC 7959) */
59
+ COAP_OPTION_BLOCK1 = 27 , /**< Block1 (RFC 7959) */
60
+ COAP_OPTION_SIZE2 = 28 , /**< Size2 (RFC 7959) */
61
+ COAP_OPTION_PROXY_URI = 35 , /**< Proxy-Uri */
62
+ COAP_OPTION_PROXY_SCHEME = 39 , /**< Proxy-Scheme */
63
+ COAP_OPTION_SIZE1 = 60 /**< Size1 */
64
64
};
65
65
66
66
/**
@@ -69,13 +69,13 @@ enum coap_option_num {
69
69
* To be used when creating a request or a response.
70
70
*/
71
71
enum coap_method {
72
- COAP_METHOD_GET = 1 ,
73
- COAP_METHOD_POST = 2 ,
74
- COAP_METHOD_PUT = 3 ,
75
- COAP_METHOD_DELETE = 4 ,
76
- COAP_METHOD_FETCH = 5 ,
77
- COAP_METHOD_PATCH = 6 ,
78
- COAP_METHOD_IPATCH = 7 ,
72
+ COAP_METHOD_GET = 1 , /**< GET */
73
+ COAP_METHOD_POST = 2 , /**< POST */
74
+ COAP_METHOD_PUT = 3 , /**< PUT */
75
+ COAP_METHOD_DELETE = 4 , /**< DELETE */
76
+ COAP_METHOD_FETCH = 5 , /**< FETCH */
77
+ COAP_METHOD_PATCH = 6 , /**< PATCH */
78
+ COAP_METHOD_IPATCH = 7 , /**< IPATCH */
79
79
};
80
80
81
81
#define COAP_REQUEST_MASK 0x07
@@ -120,7 +120,7 @@ enum coap_msgtype {
120
120
* @param class Class of the response code (ex. 2, 4, 5, ...)
121
121
* @param det Detail of the response code
122
122
* @return Response code literal
123
- */
123
+ */
124
124
#define COAP_MAKE_RESPONSE_CODE (class , det ) ((class << 5) | (det))
125
125
126
126
/**
@@ -129,33 +129,60 @@ enum coap_msgtype {
129
129
* To be used when creating a response.
130
130
*/
131
131
enum coap_response_code {
132
+ /** 2.00 - OK */
132
133
COAP_RESPONSE_CODE_OK = COAP_MAKE_RESPONSE_CODE (2 , 0 ),
134
+ /** 2.01 - Created */
133
135
COAP_RESPONSE_CODE_CREATED = COAP_MAKE_RESPONSE_CODE (2 , 1 ),
136
+ /** 2.02 - Deleted */
134
137
COAP_RESPONSE_CODE_DELETED = COAP_MAKE_RESPONSE_CODE (2 , 2 ),
138
+ /** 2.03 - Valid */
135
139
COAP_RESPONSE_CODE_VALID = COAP_MAKE_RESPONSE_CODE (2 , 3 ),
140
+ /** 2.04 - Changed */
136
141
COAP_RESPONSE_CODE_CHANGED = COAP_MAKE_RESPONSE_CODE (2 , 4 ),
142
+ /** 2.05 - Content */
137
143
COAP_RESPONSE_CODE_CONTENT = COAP_MAKE_RESPONSE_CODE (2 , 5 ),
144
+ /** 2.31 - Continue */
138
145
COAP_RESPONSE_CODE_CONTINUE = COAP_MAKE_RESPONSE_CODE (2 , 31 ),
146
+ /** 4.00 - Bad Request */
139
147
COAP_RESPONSE_CODE_BAD_REQUEST = COAP_MAKE_RESPONSE_CODE (4 , 0 ),
148
+ /** 4.01 - Unauthorized */
140
149
COAP_RESPONSE_CODE_UNAUTHORIZED = COAP_MAKE_RESPONSE_CODE (4 , 1 ),
150
+ /** 4.02 - Bad Option */
141
151
COAP_RESPONSE_CODE_BAD_OPTION = COAP_MAKE_RESPONSE_CODE (4 , 2 ),
152
+ /** 4.03 - Forbidden */
142
153
COAP_RESPONSE_CODE_FORBIDDEN = COAP_MAKE_RESPONSE_CODE (4 , 3 ),
154
+ /** 4.04 - Not Found */
143
155
COAP_RESPONSE_CODE_NOT_FOUND = COAP_MAKE_RESPONSE_CODE (4 , 4 ),
156
+ /** 4.05 - Method Not Allowed */
144
157
COAP_RESPONSE_CODE_NOT_ALLOWED = COAP_MAKE_RESPONSE_CODE (4 , 5 ),
158
+ /** 4.06 - Not Acceptable */
145
159
COAP_RESPONSE_CODE_NOT_ACCEPTABLE = COAP_MAKE_RESPONSE_CODE (4 , 6 ),
160
+ /** 4.08 - Request Entity Incomplete */
146
161
COAP_RESPONSE_CODE_INCOMPLETE = COAP_MAKE_RESPONSE_CODE (4 , 8 ),
162
+ /** 4.12 - Precondition Failed */
147
163
COAP_RESPONSE_CODE_CONFLICT = COAP_MAKE_RESPONSE_CODE (4 , 9 ),
164
+ /** 4.12 - Precondition Failed */
148
165
COAP_RESPONSE_CODE_PRECONDITION_FAILED = COAP_MAKE_RESPONSE_CODE (4 , 12 ),
166
+ /** 4.13 - Request Entity Too Large */
149
167
COAP_RESPONSE_CODE_REQUEST_TOO_LARGE = COAP_MAKE_RESPONSE_CODE (4 , 13 ),
168
+ /** 4.15 - Unsupported Content-Format */
150
169
COAP_RESPONSE_CODE_UNSUPPORTED_CONTENT_FORMAT =
151
170
COAP_MAKE_RESPONSE_CODE (4 , 15 ),
171
+ /** 4.22 - Unprocessable Entity */
152
172
COAP_RESPONSE_CODE_UNPROCESSABLE_ENTITY = COAP_MAKE_RESPONSE_CODE (4 , 22 ),
173
+ /** 4.29 - Too Many Requests */
153
174
COAP_RESPONSE_CODE_TOO_MANY_REQUESTS = COAP_MAKE_RESPONSE_CODE (4 , 29 ),
175
+ /** 5.00 - Internal Server Error */
154
176
COAP_RESPONSE_CODE_INTERNAL_ERROR = COAP_MAKE_RESPONSE_CODE (5 , 0 ),
177
+ /** 5.01 - Not Implemented */
155
178
COAP_RESPONSE_CODE_NOT_IMPLEMENTED = COAP_MAKE_RESPONSE_CODE (5 , 1 ),
179
+ /** 5.02 - Bad Gateway */
156
180
COAP_RESPONSE_CODE_BAD_GATEWAY = COAP_MAKE_RESPONSE_CODE (5 , 2 ),
181
+ /** 5.03 - Service Unavailable */
157
182
COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE = COAP_MAKE_RESPONSE_CODE (5 , 3 ),
183
+ /** 5.04 - Gateway Timeout */
158
184
COAP_RESPONSE_CODE_GATEWAY_TIMEOUT = COAP_MAKE_RESPONSE_CODE (5 , 4 ),
185
+ /** 5.05 - Proxying Not Supported */
159
186
COAP_RESPONSE_CODE_PROXYING_NOT_SUPPORTED =
160
187
COAP_MAKE_RESPONSE_CODE (5 , 5 )
161
188
};
@@ -170,15 +197,15 @@ enum coap_response_code {
170
197
* To be used when encoding or decoding a Content-Format option.
171
198
*/
172
199
enum coap_content_format {
173
- COAP_CONTENT_FORMAT_TEXT_PLAIN = 0 , /* charset=urf -8 */
174
- COAP_CONTENT_FORMAT_APP_LINK_FORMAT = 40 ,
175
- COAP_CONTENT_FORMAT_APP_XML = 41 ,
176
- COAP_CONTENT_FORMAT_APP_OCTET_STREAM = 42 ,
177
- COAP_CONTENT_FORMAT_APP_EXI = 47 ,
178
- COAP_CONTENT_FORMAT_APP_JSON = 50 ,
179
- COAP_CONTENT_FORMAT_APP_JSON_PATCH_JSON = 51 ,
180
- COAP_CONTENT_FORMAT_APP_MERGE_PATCH_JSON = 52 ,
181
- COAP_CONTENT_FORMAT_APP_CBOR = 60 ,
200
+ COAP_CONTENT_FORMAT_TEXT_PLAIN = 0 , /**< text/plain; charset=utf -8 */
201
+ COAP_CONTENT_FORMAT_APP_LINK_FORMAT = 40 , /**< application/link-format */
202
+ COAP_CONTENT_FORMAT_APP_XML = 41 , /**< application/xml */
203
+ COAP_CONTENT_FORMAT_APP_OCTET_STREAM = 42 , /**< application/octet-stream */
204
+ COAP_CONTENT_FORMAT_APP_EXI = 47 , /**< application/exi */
205
+ COAP_CONTENT_FORMAT_APP_JSON = 50 , /**< application/json */
206
+ COAP_CONTENT_FORMAT_APP_JSON_PATCH_JSON = 51 , /**< application/json-patch+json */
207
+ COAP_CONTENT_FORMAT_APP_MERGE_PATCH_JSON = 52 , /**< application/merge-patch+json */
208
+ COAP_CONTENT_FORMAT_APP_CBOR = 60 /**< application/cbor */
182
209
};
183
210
184
211
/* block option helper */
@@ -239,25 +266,32 @@ struct coap_observer {
239
266
* @brief Representation of a CoAP Packet.
240
267
*/
241
268
struct coap_packet {
242
- uint8_t * data ; /* User allocated buffer */
243
- uint16_t offset ; /* CoAP lib maintains offset while adding data */
244
- uint16_t max_len ; /* Max CoAP packet data length */
245
- uint8_t hdr_len ; /* CoAP header length */
246
- uint16_t opt_len ; /* Total options length (delta + len + value) */
247
- uint16_t delta ; /* Used for delta calculation in CoAP packet */
248
- #if defined(CONFIG_COAP_KEEP_USER_DATA )
249
- void * user_data ; /* Application specific user data */
269
+ uint8_t * data ; /**< User allocated buffer */
270
+ uint16_t offset ; /**< CoAP lib maintains offset while adding data */
271
+ uint16_t max_len ; /**< Max CoAP packet data length */
272
+ uint8_t hdr_len ; /**< CoAP header length */
273
+ uint16_t opt_len ; /**< Total options length (delta + len + value) */
274
+ uint16_t delta ; /**< Used for delta calculation in CoAP packet */
275
+ #if defined(CONFIG_COAP_KEEP_USER_DATA ) || defined(DOXGEN )
276
+ /**
277
+ * Application specific user data.
278
+ * Only available when @kconfig{CONFIG_COAP_KEEP_USER_DATA} is enabled.
279
+ */
280
+ void * user_data ;
250
281
#endif
251
282
};
252
283
284
+ /**
285
+ * @brief Representation of a CoAP option.
286
+ */
253
287
struct coap_option {
254
- uint16_t delta ;
288
+ uint16_t delta ; /**< Option delta */
255
289
#if defined(CONFIG_COAP_EXTENDED_OPTIONS_LEN )
256
290
uint16_t len ;
257
291
uint8_t value [CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE ];
258
292
#else
259
- uint8_t len ;
260
- uint8_t value [12 ];
293
+ uint8_t len ; /**< Option length */
294
+ uint8_t value [12 ]; /**< Option value */
261
295
#endif
262
296
};
263
297
@@ -277,13 +311,13 @@ typedef int (*coap_reply_t)(const struct coap_packet *response,
277
311
* @brief Represents a request awaiting for an acknowledgment (ACK).
278
312
*/
279
313
struct coap_pending {
280
- struct sockaddr addr ;
281
- int64_t t0 ;
282
- uint32_t timeout ;
283
- uint16_t id ;
284
- uint8_t * data ;
285
- uint16_t len ;
286
- uint8_t retries ;
314
+ struct sockaddr addr ; /**< Remote address */
315
+ int64_t t0 ; /**< Time when the request was sent */
316
+ uint32_t timeout ; /**< Timeout in ms */
317
+ uint16_t id ; /**< Message id */
318
+ uint8_t * data ; /**< User allocated buffer */
319
+ uint16_t len ; /**< Length of the CoAP packet */
320
+ uint8_t retries ; /**< Number of times the request has been sent */
287
321
};
288
322
289
323
/**
@@ -563,13 +597,13 @@ int coap_handle_request(struct coap_packet *cpkt,
563
597
* https://tools.ietf.org/html/rfc7959
564
598
*/
565
599
enum coap_block_size {
566
- COAP_BLOCK_16 ,
567
- COAP_BLOCK_32 ,
568
- COAP_BLOCK_64 ,
569
- COAP_BLOCK_128 ,
570
- COAP_BLOCK_256 ,
571
- COAP_BLOCK_512 ,
572
- COAP_BLOCK_1024 ,
600
+ COAP_BLOCK_16 , /**< 16-byte block size */
601
+ COAP_BLOCK_32 , /**< 32-byte block size */
602
+ COAP_BLOCK_64 , /**< 64-byte block size */
603
+ COAP_BLOCK_128 , /**< 128-byte block size */
604
+ COAP_BLOCK_256 , /**< 256-byte block size */
605
+ COAP_BLOCK_512 , /**< 512-byte block size */
606
+ COAP_BLOCK_1024 , /**< 1024-byte block size */
573
607
};
574
608
575
609
/**
0 commit comments