Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
f3f673eb
Commit
f3f673eb
authored
6 years ago
by
Hauke Petersen
Browse files
Options
Downloads
Patches
Plain Diff
net/nanocoap: factor out generic CoAP defines
parent
8e9c28da
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
sys/include/net/coap.h
+188
-0
188 additions, 0 deletions
sys/include/net/coap.h
sys/include/net/nanocoap.h
+12
-170
12 additions, 170 deletions
sys/include/net/nanocoap.h
sys/net/application_layer/nanocoap/nanocoap.c
+9
-0
9 additions, 0 deletions
sys/net/application_layer/nanocoap/nanocoap.c
with
209 additions
and
170 deletions
sys/include/net/coap.h
0 → 100644
+
188
−
0
View file @
f3f673eb
/*
* Copyright (C) 2018 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup net_coap CoAP defines
* @ingroup net
* @brief Generic CoAP values as defined by RFC7252
* @{
*
* @file
* @brief Generic CoAP values as defined by RFC7252
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
*/
#ifndef NET_COAP_H
#define NET_COAP_H
#ifdef __cplusplus
extern
"C"
{
#endif
/**
* @brief Default CoAP port
*/
#define COAP_PORT (5683)
/**
* @name CoAP option numbers
* @{
*/
#define COAP_OPT_URI_HOST (3)
#define COAP_OPT_OBSERVE (6)
#define COAP_OPT_LOCATION_PATH (8)
#define COAP_OPT_URI_PATH (11)
#define COAP_OPT_CONTENT_FORMAT (12)
#define COAP_OPT_URI_QUERY (15)
#define COAP_OPT_LOCATION_QUERY (20)
#define COAP_OPT_BLOCK2 (23)
#define COAP_OPT_BLOCK1 (27)
/** @} */
/**
* @name Message types -- confirmable, non-confirmable, etc.
* @{
*/
#define COAP_TYPE_CON (0)
#define COAP_TYPE_NON (1)
#define COAP_TYPE_ACK (2)
#define COAP_TYPE_RST (3)
/** @} */
/**
* @name CoAP method codes used in header
* @{
*/
#define COAP_CLASS_REQ (0)
#define COAP_METHOD_GET (1)
#define COAP_METHOD_POST (2)
#define COAP_METHOD_PUT (3)
#define COAP_METHOD_DELETE (4)
/** @} */
/**
* @name Empty CoAP message code
* @{
*/
#define COAP_CODE_EMPTY (0)
/** @} */
/**
* @name Response message codes: success
* @{
*/
#define COAP_CLASS_SUCCESS (2)
#define COAP_CODE_CREATED ((2 << 5) | 1)
#define COAP_CODE_DELETED ((2 << 5) | 2)
#define COAP_CODE_VALID ((2 << 5) | 3)
#define COAP_CODE_CHANGED ((2 << 5) | 4)
#define COAP_CODE_204 ((2 << 5) | 4)
#define COAP_CODE_CONTENT ((2 << 5) | 5)
#define COAP_CODE_205 ((2 << 5) | 5)
#define COAP_CODE_231 ((2 << 5) | 31)
/** @} */
/**
* @name Response message codes: client error
* @{
*/
#define COAP_CLASS_CLIENT_FAILURE (4)
#define COAP_CODE_BAD_REQUEST ((4 << 5) | 0)
#define COAP_CODE_UNAUTHORIZED ((4 << 5) | 1)
#define COAP_CODE_BAD_OPTION ((4 << 5) | 2)
#define COAP_CODE_FORBIDDEN ((4 << 5) | 3)
#define COAP_CODE_PATH_NOT_FOUND ((4 << 5) | 4)
#define COAP_CODE_404 ((4 << 5) | 4)
#define COAP_CODE_METHOD_NOT_ALLOWED ((4 << 5) | 5)
#define COAP_CODE_NOT_ACCEPTABLE ((4 << 5) | 6)
#define COAP_CODE_REQUEST_ENTITY_INCOMPLETE ((4 << 5) | 8)
#define COAP_CODE_PRECONDITION_FAILED ((4 << 5) | 0xC)
#define COAP_CODE_REQUEST_ENTITY_TOO_LARGE ((4 << 5) | 0xD)
#define COAP_CODE_UNSUPPORTED_CONTENT_FORMAT ((4 << 5) | 0xF)
/** @} */
/**
* @name Response message codes: server error
* @{
*/
#define COAP_CLASS_SERVER_FAILURE (5)
#define COAP_CODE_INTERNAL_SERVER_ERROR ((5 << 5) | 0)
#define COAP_CODE_NOT_IMPLEMENTED ((5 << 5) | 1)
#define COAP_CODE_BAD_GATEWAY ((5 << 5) | 2)
#define COAP_CODE_SERVICE_UNAVAILABLE ((5 << 5) | 3)
#define COAP_CODE_GATEWAY_TIMEOUT ((5 << 5) | 4)
#define COAP_CODE_PROXYING_NOT_SUPPORTED ((5 << 5) | 5)
/** @} */
/**
* @name Content types
* @{
*/
#define COAP_CT_LINK_FORMAT (40)
#define COAP_CT_XML (41)
#define COAP_CT_OCTET_STREAM (42)
#define COAP_CT_EXI (47)
#define COAP_CT_JSON (50)
/** @} */
/**
* @name Content-Format option codes
* @{
*/
#define COAP_FORMAT_TEXT (0)
#define COAP_FORMAT_LINK (40)
#define COAP_FORMAT_OCTET (42)
#define COAP_FORMAT_JSON (50)
#define COAP_FORMAT_CBOR (60)
/** @} */
/**
* @name Observe (RFC 7641) constants
* @{
*/
#define COAP_OBS_REGISTER (0)
#define COAP_OBS_DEREGISTER (1)
/** @} */
/**
* @name Timing parameters
* @{
*/
#define COAP_ACK_TIMEOUT (2U)
#define COAP_RANDOM_FACTOR (1.5)
/**
* @brief Maximum variation for confirmable timeout.
*
* Must be an integer, defined as:
*
* (COAP_ACK_TIMEOUT * COAP_RANDOM_FACTOR) - COAP_ACK_TIMEOUT
*/
#define COAP_ACK_VARIANCE (1U)
#define COAP_MAX_RETRANSMIT (4)
#define COAP_NSTART (1)
#define COAP_DEFAULT_LEISURE (5)
/** @} */
/**
* @name Blockwise transfer (RFC7959)
* @{
*/
#define COAP_BLOCKWISE_NUM_OFF (4)
#define COAP_BLOCKWISE_MORE_OFF (3)
#define COAP_BLOCKWISE_SZX_MASK (0x07)
#define COAP_BLOCKWISE_SZX_MAX (7)
/** @} */
#ifdef __cplusplus
}
#endif
#endif
/* NET_COAP_H */
/** @} */
This diff is collapsed.
Click to expand it.
sys/include/net/nanocoap.h
+
12
−
170
View file @
f3f673eb
...
...
@@ -33,7 +33,9 @@
#ifdef RIOT_VERSION
#include
"byteorder.h"
#include
"net/coap.h"
#else
#include
"coap.h"
#include
<arpa/inet.h>
#endif
...
...
@@ -42,69 +44,7 @@ extern "C" {
#endif
/**
* @brief CoAP port to use
*/
#define COAP_PORT (5683)
/**
* @name Nanocoap specific maximum values
* @{
*/
#define NANOCOAP_NOPTS_MAX (16)
#define NANOCOAP_URI_MAX (64)
/** @} */
#ifdef MODULE_GCOAP
#define NANOCOAP_URL_MAX NANOCOAP_URI_MAX
#define NANOCOAP_QS_MAX (64)
#endif
/**
* @name CoAP option numbers
* @{
*/
#define COAP_OPT_URI_HOST (3)
#define COAP_OPT_OBSERVE (6)
#define COAP_OPT_LOCATION_PATH (8)
#define COAP_OPT_URI_PATH (11)
#define COAP_OPT_CONTENT_FORMAT (12)
#define COAP_OPT_URI_QUERY (15)
#define COAP_OPT_LOCATION_QUERY (20)
#define COAP_OPT_BLOCK2 (23)
#define COAP_OPT_BLOCK1 (27)
/** @} */
/**
* @name CoAP packet types
* @{
*/
#define COAP_REQ (0)
#define COAP_RESP (2)
#define COAP_RST (3)
/**
* @name Message types -- confirmable, non-confirmable, etc.
* @{
*/
#define COAP_TYPE_CON (0)
#define COAP_TYPE_NON (1)
#define COAP_TYPE_ACK (2)
#define COAP_TYPE_RST (3)
/** @} */
/**
* @name CoAP method codes used in header
* @{
*/
#define COAP_CLASS_REQ (0)
#define COAP_METHOD_GET (1)
#define COAP_METHOD_POST (2)
#define COAP_METHOD_PUT (3)
#define COAP_METHOD_DELETE (4)
/** @} */
/**
* @name CoAP method flags used in coap_handlers array
* @name Nanocoap specific CoAP method flags used in coap_handlers array
* @{
*/
#define COAP_GET (0x1)
...
...
@@ -114,120 +54,22 @@ extern "C" {
/** @} */
/**
* @name Empty CoAP message code
* @{
*/
#define COAP_CODE_EMPTY (0)
/** @} */
/**
* @name Response message codes: success
* @{
* @brief Nanocoap-specific value to indicate no format specified
*/
#define COAP_CLASS_SUCCESS (2)
#define COAP_CODE_CREATED ((2 << 5) | 1)
#define COAP_CODE_DELETED ((2 << 5) | 2)
#define COAP_CODE_VALID ((2 << 5) | 3)
#define COAP_CODE_CHANGED ((2 << 5) | 4)
#define COAP_CODE_204 ((2 << 5) | 4)
#define COAP_CODE_CONTENT ((2 << 5) | 5)
#define COAP_CODE_205 ((2 << 5) | 5)
#define COAP_CODE_231 ((2 << 5) | 31)
/** @} */
#define COAP_FORMAT_NONE (65535)
/**
* @name Response message codes: client error
* @{
*/
#define COAP_CLASS_CLIENT_FAILURE (4)
#define COAP_CODE_BAD_REQUEST ((4 << 5) | 0)
#define COAP_CODE_UNAUTHORIZED ((4 << 5) | 1)
#define COAP_CODE_BAD_OPTION ((4 << 5) | 2)
#define COAP_CODE_FORBIDDEN ((4 << 5) | 3)
#define COAP_CODE_PATH_NOT_FOUND ((4 << 5) | 4)
#define COAP_CODE_404 ((4 << 5) | 4)
#define COAP_CODE_METHOD_NOT_ALLOWED ((4 << 5) | 5)
#define COAP_CODE_NOT_ACCEPTABLE ((4 << 5) | 6)
#define COAP_CODE_REQUEST_ENTITY_INCOMPLETE ((4 << 5) | 8)
#define COAP_CODE_PRECONDITION_FAILED ((4 << 5) | 0xC)
#define COAP_CODE_REQUEST_ENTITY_TOO_LARGE ((4 << 5) | 0xD)
#define COAP_CODE_UNSUPPORTED_CONTENT_FORMAT ((4 << 5) | 0xF)
/** @} */
/**
* @name Response message codes: server error
* @{
*/
#define COAP_CLASS_SERVER_FAILURE (5)
#define COAP_CODE_INTERNAL_SERVER_ERROR ((5 << 5) | 0)
#define COAP_CODE_NOT_IMPLEMENTED ((5 << 5) | 1)
#define COAP_CODE_BAD_GATEWAY ((5 << 5) | 2)
#define COAP_CODE_SERVICE_UNAVAILABLE ((5 << 5) | 3)
#define COAP_CODE_GATEWAY_TIMEOUT ((5 << 5) | 4)
#define COAP_CODE_PROXYING_NOT_SUPPORTED ((5 << 5) | 5)
/** @} */
/**
* @name Content types
* @{
*/
#define COAP_CT_LINK_FORMAT (40)
#define COAP_CT_XML (41)
#define COAP_CT_OCTET_STREAM (42)
#define COAP_CT_EXI (47)
#define COAP_CT_JSON (50)
/** @} */
/**
* @name Content-Format option codes
* @{
*/
#define COAP_FORMAT_TEXT (0)
#define COAP_FORMAT_LINK (40)
#define COAP_FORMAT_OCTET (42)
#define COAP_FORMAT_JSON (50)
#define COAP_FORMAT_CBOR (60)
/** @brief nanocoap-specific value to indicate no format specified. */
#define COAP_FORMAT_NONE (65535)
/** @} */
/**
* @name Observe (RFC 7641) constants
* @{
*/
#define COAP_OBS_REGISTER (0)
#define COAP_OBS_DEREGISTER (1)
/** @} */
/**
* @name Timing parameters
* @name Nanocoap specific maximum values
* @{
*/
#define COAP_ACK_TIMEOUT (2U)
#define COAP_RANDOM_FACTOR (1.5)
/**
* @brief Maximum variation for confirmable timeout.
*
* Must be an integer, defined as:
*
* (COAP_ACK_TIMEOUT * COAP_RANDOM_FACTOR) - COAP_ACK_TIMEOUT
*/
#define COAP_ACK_VARIANCE (1U)
#define COAP_MAX_RETRANSMIT (4)
#define COAP_NSTART (1)
#define COAP_DEFAULT_LEISURE (5)
#define NANOCOAP_NOPTS_MAX (16)
#define NANOCOAP_URI_MAX (64)
/** @} */
/**
* @name Blockwise transfer (RFC7959)
* @{
*/
#define COAP_BLOCKWISE_NUM_OFF (4)
#define COAP_BLOCKWISE_MORE_OFF (3)
#define COAP_BLOCKWISE_SZX_MASK (0x07)
#define COAP_BLOCKWISE_SZX_MAX (7)
/** @} */
#ifdef MODULE_GCOAP
#define NANOCOAP_URL_MAX NANOCOAP_URI_MAX
#define NANOCOAP_QS_MAX (64)
#endif
/**
* @name coap_opt_finish() flag parameter values
...
...
This diff is collapsed.
Click to expand it.
sys/net/application_layer/nanocoap/nanocoap.c
+
9
−
0
View file @
f3f673eb
...
...
@@ -30,6 +30,15 @@
#define ENABLE_DEBUG (0)
#include
"debug.h"
/**
* @name Internally used CoAP packet types
* @{
*/
#define COAP_REQ (0)
#define COAP_RESP (2)
#define COAP_RST (3)
/** @} */
static
int
_decode_value
(
unsigned
val
,
uint8_t
**
pkt_pos_ptr
,
uint8_t
*
pkt_end
);
int
coap_get_option_uint
(
coap_pkt_t
*
pkt
,
unsigned
opt_num
,
uint32_t
*
target
);
static
uint32_t
_decode_uint
(
uint8_t
*
pkt_pos
,
unsigned
nbytes
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment