coap_message.c File Reference

CoAP message formatting and parsing. More...

#include "core/net.h"
#include "coap/coap_client.h"
#include "coap/coap_server.h"
#include "coap/coap_message.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   COAP_TRACE_LEVEL
 

Functions

error_t coapParseMessage (const CoapMessage *message)
 Parse CoAP message. More...
 
error_t coapParseMessageHeader (const uint8_t *p, size_t length, size_t *consumed)
 Parse CoAP message header. More...
 
error_t coapSetType (CoapMessage *message, CoapMessageType type)
 Set message type. More...
 
error_t coapGetType (const CoapMessage *message, CoapMessageType *type)
 Get message type. More...
 
error_t coapSetCode (CoapMessage *message, CoapCode code)
 Set method or response code. More...
 
error_t coapGetCode (const CoapMessage *message, CoapCode *code)
 Get method or response code. More...
 
error_t coapSetPayload (CoapMessage *message, const void *payload, size_t payloadLen)
 Set CoAP message payload. More...
 
error_t coapGetPayload (const CoapMessage *message, const uint8_t **payload, size_t *payloadLen)
 Get CoAP message payload. More...
 
error_t coapWritePayload (CoapMessage *message, const void *data, size_t length)
 Write payload data. More...
 
error_t coapReadPayload (CoapMessage *message, void *data, size_t size, size_t *length)
 Read payload data. More...
 
bool_t coapCompareToken (const CoapMessageHeader *header1, const CoapMessageHeader *header2)
 Token comparison. More...
 

Detailed Description

CoAP message formatting and parsing.

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.0

Definition in file coap_message.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   COAP_TRACE_LEVEL

Definition at line 32 of file coap_message.c.

Function Documentation

◆ coapCompareToken()

bool_t coapCompareToken ( const CoapMessageHeader header1,
const CoapMessageHeader header2 
)

Token comparison.

Parameters
[in]header1Pointer to the first CoAP message header
[in]header2Pointer to the second CoAP message header
Returns
TRUE if the tokens match, else FALSE

Definition at line 547 of file coap_message.c.

◆ coapGetCode()

error_t coapGetCode ( const CoapMessage message,
CoapCode code 
)

Get method or response code.

Parameters
[in]messagePointer to the CoAP message
[out]codeMethod or response code
Returns
Error code

Definition at line 226 of file coap_message.c.

◆ coapGetPayload()

error_t coapGetPayload ( const CoapMessage message,
const uint8_t **  payload,
size_t *  payloadLen 
)

Get CoAP message payload.

Parameters
[in]messagePointer to the CoAP message
[out]payloadPointer to the first byte of the payload
[out]payloadLenLength of the payload, in bytes
Returns
Error code

Definition at line 324 of file coap_message.c.

◆ coapGetType()

error_t coapGetType ( const CoapMessage message,
CoapMessageType type 
)

Get message type.

Parameters
[in]messagePointer to the CoAP message
[out]typeMessage type
Returns
Error code

Definition at line 176 of file coap_message.c.

◆ coapParseMessage()

error_t coapParseMessage ( const CoapMessage message)

Parse CoAP message.

Parameters
[in]messagePointer to the CoAP message
Returns
Error code

Definition at line 51 of file coap_message.c.

◆ coapParseMessageHeader()

error_t coapParseMessageHeader ( const uint8_t *  p,
size_t  length,
size_t *  consumed 
)

Parse CoAP message header.

Parameters
[in]pInput stream where to read the CoAP message header
[in]lengthNumber of bytes available in the input stream
[out]consumedTotal number of bytes that have been consumed
Returns
Error code

Definition at line 112 of file coap_message.c.

◆ coapReadPayload()

error_t coapReadPayload ( CoapMessage message,
void *  data,
size_t  size,
size_t *  length 
)

Read payload data.

Parameters
[in]messagePointer to the CoAP message
[out]dataBuffer into which received data will be placed
[in]sizeMaximum number of bytes that can be received
[out]lengthNumber of bytes that have been received
Returns
Error code

Definition at line 468 of file coap_message.c.

◆ coapSetCode()

error_t coapSetCode ( CoapMessage message,
CoapCode  code 
)

Set method or response code.

Parameters
[in]messagePointer to the CoAP message
[in]codeMethod or response code
Returns
Error code

Definition at line 201 of file coap_message.c.

◆ coapSetPayload()

error_t coapSetPayload ( CoapMessage message,
const void *  payload,
size_t  payloadLen 
)

Set CoAP message payload.

Parameters
[in]messagePointer to the CoAP message
[out]payloadPointer to payload data
[out]payloadLenLength of the payload, in bytes
Returns
Error code

Definition at line 252 of file coap_message.c.

◆ coapSetType()

error_t coapSetType ( CoapMessage message,
CoapMessageType  type 
)

Set message type.

Parameters
[in]messagePointer to the CoAP message
[in]typeMessage type (Confirmable or Non-confirmable)
Returns
Error code

Definition at line 151 of file coap_message.c.

◆ coapWritePayload()

error_t coapWritePayload ( CoapMessage message,
const void *  data,
size_t  length 
)

Write payload data.

Parameters
[in]messagePointer to the CoAP message
[in]dataPointer to a buffer containing the data to be written
[in]lengthNumber of bytes to written
Returns
Error code

Definition at line 386 of file coap_message.c.