coap_message.h
Go to the documentation of this file.
1 /**
2  * @file coap_message.h
3  * @brief CoAP message formatting and parsing
4  *
5  * @section License
6  *
7  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _COAP_MESSAGE_H
30 #define _COAP_MESSAGE_H
31 
32 //Dependencies
33 #include "core/net.h"
34 #include "coap/coap_common.h"
35 
36 //Maximum size of CoAP messages
37 #ifndef COAP_MAX_MSG_SIZE
38  #define COAP_MAX_MSG_SIZE 1024
39 #elif (COAP_MAX_MSG_SIZE < 16)
40  #error COAP_MAX_MSG_SIZE parameter is not valid
41 #endif
42 
43 //C++ guard
44 #ifdef __cplusplus
45  extern "C" {
46 #endif
47 
48 
49 /**
50  * @brief CoAP message
51  **/
52 
53 typedef struct
54 {
55  uint8_t buffer[COAP_MAX_MSG_SIZE];
56  size_t length;
57  size_t pos;
58 } CoapMessage;
59 
60 
61 //CoAP related functions
63 
64 error_t coapParseMessageHeader(const uint8_t *p, size_t length,
65  size_t *consumed);
66 
69 
72 
73 error_t coapSetPayload(CoapMessage *message, const void *payload,
74  size_t payloadLen);
75 
76 error_t coapGetPayload(const CoapMessage *message, const uint8_t **payload,
77  size_t *payloadLen);
78 
80  size_t length);
81 
82 error_t coapReadPayload(CoapMessage *message, void *data, size_t size,
83  size_t *length);
84 
86  const CoapMessageHeader *header2);
87 
88 //C++ guard
89 #ifdef __cplusplus
90  }
91 #endif
92 
93 #endif
uint8_t payloadLen
Definition: ipv6.h:341
CoapMessageType
CoAP message types.
Definition: coap_common.h:90
#define COAP_MAX_MSG_SIZE
Definition: coap_message.h:38
error_t coapSetCode(CoapMessage *message, CoapCode code)
Set method or response code.
Definition: coap_message.c:199
TCP/IP stack core.
uint8_t p
Definition: ndp.h:295
CoAP message.
Definition: coap_message.h:53
uint8_t message[]
Definition: chap.h:150
size_t length
Definition: coap_message.h:56
error_t coapGetPayload(const CoapMessage *message, const uint8_t **payload, size_t *payloadLen)
Get CoAP message payload.
Definition: coap_message.c:322
error_t coapParseMessageHeader(const uint8_t *p, size_t length, size_t *consumed)
Parse CoAP message header.
Definition: coap_message.c:110
char_t type
CoapCode
CoAP method and response codes.
Definition: coap_common.h:115
error_t coapGetType(const CoapMessage *message, CoapMessageType *type)
Get message type.
Definition: coap_message.c:174
error_t coapClientParseMessage(const CoapMessage *message)
Parse CoAP message.
Definition: coap_message.c:49
Definitions common to CoAP client and server.
error_t coapSetType(CoapMessage *message, CoapMessageType type)
Set message type.
Definition: coap_message.c:149
error_t
Error codes.
Definition: error.h:40
uint8_t code
Definition: coap_common.h:179
error_t coapWritePayload(CoapMessage *message, const void *data, size_t length)
Write payload data.
Definition: coap_message.c:384
uint8_t data[]
Definition: dtls_misc.h:167
bool_t coapCompareToken(const CoapMessageHeader *header1, const CoapMessageHeader *header2)
Token comparison.
Definition: coap_message.c:545
size_t pos
Definition: coap_message.h:57
uint8_t length
Definition: dtls_misc.h:140
__start_packed struct @110 CoapMessageHeader
CoAP message format.
error_t coapGetCode(const CoapMessage *message, CoapCode *code)
Get method or response code.
Definition: coap_message.c:224
int bool_t
Definition: compiler_port.h:47
error_t coapReadPayload(CoapMessage *message, void *data, size_t size, size_t *length)
Read payload data.
Definition: coap_message.c:466
error_t coapSetPayload(CoapMessage *message, const void *payload, size_t payloadLen)
Set CoAP message payload.
Definition: coap_message.c:250