coap_common.h File Reference

Definitions common to CoAP client and server. More...

#include "core/net.h"

Go to the source code of this file.

Macros

#define COAP_PORT   5683
 
#define COAPS_PORT   5684
 
#define COAP_HEADER_SIZE   4
 
#define COAP_MAX_TOKEN_LEN   8
 
#define COAP_PAYLOAD_MARKER   0xFF
 
#define COAP_CODE(c, d)   ((((c) & 0x07U) << 5U) | ((d) & 0x1FU))
 
#define COAP_GET_CODE_CLASS(code)   (((code) >> 5U) & 0x07U)
 
#define COAP_GET_CODE_SUBCLASS(code)   ((code) & 0x1FU)
 

Enumerations

enum  CoapProtocolLevel { COAP_VERSION_1 = 1 }
 CoAP version numbers. More...
 
enum  CoapTransportProtocol { COAP_TRANSPORT_PROTOCOL_UDP = 1, COAP_TRANSPORT_PROTOCOL_DTLS = 2 }
 CoAP transport protocols. More...
 
enum  CoapMessageType { COAP_TYPE_CON = 0, COAP_TYPE_NON = 1, COAP_TYPE_ACK = 2, COAP_TYPE_RST = 3 }
 CoAP message types. More...
 
enum  CoapCodeClass { COAP_CODE_CLASS_SUCCESS = 2, COAP_CODE_CLASS_CLIENT_ERROR = 4, COAP_CODE_CLASS_SERVER_ERROR = 5 }
 CoAP code classes. More...
 
enum  CoapCode {
  COAP_CODE_EMPTY = COAP_CODE(0, 0), COAP_CODE_GET = COAP_CODE(0, 1), COAP_CODE_POST = COAP_CODE(0, 2), COAP_CODE_PUT = COAP_CODE(0, 3),
  COAP_CODE_DELETE = COAP_CODE(0, 4), COAP_CODE_FETCH = COAP_CODE(0, 5), COAP_CODE_PATCH = COAP_CODE(0, 6), COAP_CODE_IPATCH = COAP_CODE(0, 7),
  COAP_CODE_CREATED = COAP_CODE(2, 1), COAP_CODE_DELETED = COAP_CODE(2, 2), COAP_CODE_VALID = COAP_CODE(2, 3), COAP_CODE_CHANGED = COAP_CODE(2, 4),
  COAP_CODE_CONTENT = COAP_CODE(2, 5), COAP_CODE_CONTINUE = COAP_CODE(2, 31), COAP_CODE_BAD_REQUEST = COAP_CODE(4, 0), COAP_CODE_UNAUTHOZED = COAP_CODE(4, 1),
  COAP_CODE_BAD_OPTION = COAP_CODE(4, 2), COAP_CODE_FORBIDDEN = COAP_CODE(4, 3), COAP_CODE_NOT_FOUND = COAP_CODE(4, 4), COAP_CODE_METHOD_NOT_ALLOWED = COAP_CODE(4, 5),
  COAP_CODE_NOT_ACCEPTABLE = COAP_CODE(4, 6), COAP_CODE_REQUEST_ENTITY_INCOMPLETE = COAP_CODE(4, 8), COAP_CODE_CONFLICT = COAP_CODE(4, 9), COAP_CODE_PRECONDITION_FAILED = COAP_CODE(4, 12),
  COAP_CODE_REQUEST_ENTITY_TO_LARGE = COAP_CODE(4, 13), COAP_CODE_UNSUPPORTED_CONTENT_FORMAT = COAP_CODE(4, 15), COAP_CODE_UNPROCESSABLE_ENTITY = COAP_CODE(4, 22), COAP_CODE_INTERNAL_SERVER = COAP_CODE(5, 0),
  COAP_CODE_NOT_IMPLEMENTED = COAP_CODE(5, 1), COAP_CODE_BAD_GATEWAY = COAP_CODE(5, 2), COAP_CODE_SERVICE_UNAVAILABLE = COAP_CODE(5, 3), COAP_CODE_GATEWAY_TIMEOUT = COAP_CODE(5, 4),
  COAP_CODE_PROXYING_NOT_SUPPORTED = COAP_CODE(5, 5), COAP_CODE_HOP_LIMIT_REACHED = COAP_CODE(5, 8), COAP_CODE_CSM = COAP_CODE(7, 1), COAP_CODE_PING = COAP_CODE(7, 2),
  COAP_CODE_PONG = COAP_CODE(7, 3), COAP_CODE_RELEASE = COAP_CODE(7, 4), COAP_CODE_ABORT = COAP_CODE(7, 5)
}
 CoAP method and response codes. More...
 

Variables

typedef __packed_struct
 CoAP message format. More...
 
uint8_t type
 
uint8_t version
 
uint8_t code
 
uint16_t mid
 
uint8_t token []
 
 CoapMessageHeader
 
uint8_t delta
 
 CoapOptionHeader
 

Detailed Description

Definitions common to CoAP client and server.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file coap_common.h.

Macro Definition Documentation

◆ COAP_CODE

#define COAP_CODE (   c,
 
)    ((((c) & 0x07U) << 5U) | ((d) & 0x1FU))

Definition at line 51 of file coap_common.h.

◆ COAP_GET_CODE_CLASS

#define COAP_GET_CODE_CLASS (   code)    (((code) >> 5U) & 0x07U)

Definition at line 54 of file coap_common.h.

◆ COAP_GET_CODE_SUBCLASS

#define COAP_GET_CODE_SUBCLASS (   code)    ((code) & 0x1FU)

Definition at line 56 of file coap_common.h.

◆ COAP_HEADER_SIZE

#define COAP_HEADER_SIZE   4

Definition at line 43 of file coap_common.h.

◆ COAP_MAX_TOKEN_LEN

#define COAP_MAX_TOKEN_LEN   8

Definition at line 45 of file coap_common.h.

◆ COAP_PAYLOAD_MARKER

#define COAP_PAYLOAD_MARKER   0xFF

Definition at line 48 of file coap_common.h.

◆ COAP_PORT

#define COAP_PORT   5683

Definition at line 38 of file coap_common.h.

◆ COAPS_PORT

#define COAPS_PORT   5684

Definition at line 40 of file coap_common.h.

Enumeration Type Documentation

◆ CoapCode

enum CoapCode

CoAP method and response codes.

Enumerator
COAP_CODE_EMPTY 
COAP_CODE_GET 
COAP_CODE_POST 
COAP_CODE_PUT 
COAP_CODE_DELETE 
COAP_CODE_FETCH 
COAP_CODE_PATCH 
COAP_CODE_IPATCH 
COAP_CODE_CREATED 
COAP_CODE_DELETED 
COAP_CODE_VALID 
COAP_CODE_CHANGED 
COAP_CODE_CONTENT 
COAP_CODE_CONTINUE 
COAP_CODE_BAD_REQUEST 
COAP_CODE_UNAUTHOZED 
COAP_CODE_BAD_OPTION 
COAP_CODE_FORBIDDEN 
COAP_CODE_NOT_FOUND 
COAP_CODE_METHOD_NOT_ALLOWED 
COAP_CODE_NOT_ACCEPTABLE 
COAP_CODE_REQUEST_ENTITY_INCOMPLETE 
COAP_CODE_CONFLICT 
COAP_CODE_PRECONDITION_FAILED 
COAP_CODE_REQUEST_ENTITY_TO_LARGE 
COAP_CODE_UNSUPPORTED_CONTENT_FORMAT 
COAP_CODE_UNPROCESSABLE_ENTITY 
COAP_CODE_INTERNAL_SERVER 
COAP_CODE_NOT_IMPLEMENTED 
COAP_CODE_BAD_GATEWAY 
COAP_CODE_SERVICE_UNAVAILABLE 
COAP_CODE_GATEWAY_TIMEOUT 
COAP_CODE_PROXYING_NOT_SUPPORTED 
COAP_CODE_HOP_LIMIT_REACHED 
COAP_CODE_CSM 
COAP_CODE_PING 
COAP_CODE_PONG 
COAP_CODE_RELEASE 
COAP_CODE_ABORT 

Definition at line 112 of file coap_common.h.

◆ CoapCodeClass

CoAP code classes.

Enumerator
COAP_CODE_CLASS_SUCCESS 
COAP_CODE_CLASS_CLIENT_ERROR 
COAP_CODE_CLASS_SERVER_ERROR 

Definition at line 100 of file coap_common.h.

◆ CoapMessageType

CoAP message types.

Enumerator
COAP_TYPE_CON 

Confirmable message.

COAP_TYPE_NON 

Non-confirmable message.

COAP_TYPE_ACK 

Acknowledgment message.

COAP_TYPE_RST 

Reset message.

Definition at line 87 of file coap_common.h.

◆ CoapProtocolLevel

CoAP version numbers.

Enumerator
COAP_VERSION_1 

CoAP version 1.

Definition at line 68 of file coap_common.h.

◆ CoapTransportProtocol

CoAP transport protocols.

Enumerator
COAP_TRANSPORT_PROTOCOL_UDP 

UDP protocol.

COAP_TRANSPORT_PROTOCOL_DTLS 

DTLS protocol.

Definition at line 77 of file coap_common.h.

Variable Documentation

◆ __packed_struct

typedef __packed_struct
Initial value:
{
uint8_t tokenLen : 4

CoAP message format.

CoAP option format.

Definition at line 168 of file coap_common.h.

◆ CoapMessageHeader

CoapMessageHeader

Definition at line 182 of file coap_common.h.

◆ CoapOptionHeader

CoapOptionHeader

Definition at line 198 of file coap_common.h.

◆ code

uint8_t code

Definition at line 179 of file coap_common.h.

◆ delta

uint8_t delta

Definition at line 196 of file coap_common.h.

◆ mid

uint16_t mid

Definition at line 180 of file coap_common.h.

◆ token

uint8_t token[]

Definition at line 181 of file coap_common.h.

◆ type

uint8_t type

Definition at line 176 of file coap_common.h.

◆ version

uint8_t version

Definition at line 177 of file coap_common.h.