coap_client_request.h
Go to the documentation of this file.
1 /**
2  * @file coap_client_request.h
3  * @brief CoAP request handling
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 #ifndef _COAP_CLIENT_REQUEST_H
32 #define _COAP_CLIENT_REQUEST_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "coap/coap_client.h"
37 #include "coap/coap_option.h"
38 
39 //C++ guard
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 
45 /**
46  * @brief CoAP request states
47  **/
48 
49 typedef enum
50 {
62 
63 
64 /**
65  * @brief Request status
66  **/
67 
68 typedef enum
69 {
76 
77 
78 /**
79  * @brief Request completed callback
80  **/
81 
83  CoapClientRequest *request, CoapRequestStatus status, void *param);
84 
85 
86 /**
87  * @brief CoAP request
88  **/
89 
91 {
92  CoapRequestState state; ///<CoAP request state
93  CoapClientContext *context; ///<CoAP client context
94  systime_t startTime; ///<Request start time
95  systime_t timeout; ///<Request timeout
96  systime_t retransmitStartTime; ///<Time at which the last message was sent
97  systime_t retransmitTimeout; ///<Retransmission timeout
98  uint_t retransmitCount; ///<Retransmission counter
99 #if (COAP_CLIENT_OBSERVE_SUPPORT == ENABLED)
100  uint32_t observeSeqNum; ///<Sequence number for reordering detection
101 #endif
102 #if (COAP_CLIENT_BLOCK_SUPPORT == ENABLED)
103  CoapBlockSize txBlockSzx; ///<TX block size
104  CoapBlockSize rxBlockSzx; ///<RX block size
105 #endif
106  CoapMessage message; ///<CoAP request message
107  CoapRequestCallback callback; ///<Callback function to invoke when the request completes
108  void *param; ///<Callback function parameter
109 };
110 
111 
112 //CoAP client related functions
114 
116  systime_t timeout);
117 
119  CoapRequestCallback callback, void *param);
120 
123 
126 
129 
132 
134 
136 
138  size_t maxLen);
139 
141 
143  size_t maxLen);
144 
146  size_t maxLen);
147 
149  char_t *queryString, size_t maxLen);
150 
152  uint_t optionIndex, const uint8_t *optionValue, size_t optionLen);
153 
155  uint_t optionIndex, const char_t *optionValue);
156 
158  uint_t optionIndex, uint32_t optionValue);
159 
160 error_t coapClientGetOpaqueOption(const CoapMessage *message, uint16_t optionNum,
161  uint_t optionIndex, const uint8_t **optionValue, size_t *optionLen);
162 
163 error_t coapClientGetStringOption(const CoapMessage *message, uint16_t optionNum,
164  uint_t optionIndex, const char_t **optionValue, size_t *optionLen);
165 
166 error_t coapClientGetUintOption(const CoapMessage *message, uint16_t optionNum,
167  uint_t optionIndex, uint32_t *optionValue);
168 
170  uint_t optionIndex);
171 
173  size_t payloadLen);
174 
175 error_t coapClientGetPayload(const CoapMessage *message, const uint8_t **payload,
176  size_t *payloadLen);
177 
179  size_t length);
180 
182  size_t *length);
183 
184 //C++ guard
185 #ifdef __cplusplus
186 }
187 #endif
188 
189 #endif
uint8_t code
Definition: coap_common.h:179
error_t coapClientDeleteOption(CoapMessage *message, uint16_t optionNum, uint_t optionIndex)
Remove an option from the CoAP message.
error_t coapClientGetLocationQuery(const CoapMessage *message, char_t *queryString, size_t maxLen)
Get Location-Query option.
void coapClientDeleteRequest(CoapClientRequest *request)
Release the resources associated with a CoAP request.
@ COAP_REQ_STATE_TRANSMIT
uint8_t message[]
Definition: chap.h:154
error_t coapClientSetPayload(CoapMessage *message, const void *payload, size_t payloadLen)
Set message payload.
uint8_t data[]
Definition: ethernet.h:222
systime_t timeout
Request timeout.
error_t coapClientReadPayload(CoapMessage *message, void *data, size_t size, size_t *length)
Read payload data.
uint8_t type
Definition: coap_common.h:176
error_t coapClientSetUriQuery(CoapMessage *message, const char_t *queryString)
Set Uri-Query option.
@ COAP_REQ_STATE_RESET
@ COAP_REQUEST_STATUS_SUCCESS
error_t coapClientSetUintOption(CoapMessage *message, uint16_t optionNum, uint_t optionIndex, uint32_t optionValue)
Add a uint option to the CoAP message.
error_t coapClientWritePayload(CoapMessage *message, const void *data, size_t length)
Write payload data.
@ COAP_REQ_STATE_DONE
#define CoapClientContext
Definition: coap_client.h:144
#define CoapClientRequest
Definition: coap_client.h:148
@ COAP_REQUEST_STATUS_RESET
error_t coapClientGetType(const CoapMessage *message, CoapMessageType *type)
Get message type.
@ COAP_REQ_STATE_OBSERVE
error_t coapClientGetResponseCode(const CoapMessage *message, CoapCode *code)
Get response code.
error_t coapClientSetUriPath(CoapMessage *message, const char_t *path)
Set Uri-Path option.
error_t coapClientSetStringOption(CoapMessage *message, uint16_t optionNum, uint_t optionIndex, const char_t *optionValue)
Add a string option to the CoAP message.
error_t
Error codes.
Definition: error.h:43
CoapRequestState state
CoAP request state.
error_t coapClientSetMethodCode(CoapMessage *message, CoapCode code)
Set request method.
error_t coapClientCancelRequest(CoapClientRequest *request)
Cancel an outstanding CoAP request.
error_t coapClientGetLocationPath(const CoapMessage *message, char_t *path, size_t maxLen)
Get Location-Path option.
error_t coapClientGetMethodCode(const CoapMessage *message, CoapCode *code)
Get request method.
CoAP message.
Definition: coap_message.h:56
error_t coapClientSetRequestTimeout(CoapClientRequest *request, systime_t timeout)
Set request timeout.
CoapRequestStatus
Request status.
CoAP client.
uint8_t length
Definition: tcp.h:368
CoapClientContext * context
CoAP client context.
CoapMessage * coapClientGetRequestMessage(CoapClientRequest *request)
Get request message.
CoapBlockSize rxBlockSzx
RX block size.
@ COAP_REQ_STATE_CANCELED
CoapMessage * coapClientGetResponseMessage(CoapClientRequest *request)
Get response message.
@ COAP_REQ_STATE_UNUSED
uint32_t systime_t
System time.
@ COAP_REQUEST_STATUS_FAILURE
systime_t retransmitStartTime
Time at which the last message was sent.
char char_t
Definition: compiler_port.h:48
CoapClientRequest * coapClientCreateRequest(CoapClientContext *context)
Initialize a new CoAP request.
@ COAP_REQUEST_STATUS_TIMEOUT
CoapRequestCallback callback
Callback function to invoke when the request completes.
error_t coapClientGetUintOption(const CoapMessage *message, uint16_t optionNum, uint_t optionIndex, uint32_t *optionValue)
Read an uint option from the CoAP message.
@ COAP_REQ_STATE_RECEIVE
error_t coapClientGetUriPath(const CoapMessage *message, char_t *path, size_t maxLen)
Get Uri-Path option.
CoapMessageType
CoAP message types.
Definition: coap_common.h:88
error_t coapClientSendRequest(CoapClientRequest *request, CoapRequestCallback callback, void *param)
Send a CoAP request.
error_t coapClientSetType(CoapMessage *message, CoapMessageType type)
Set message type.
systime_t startTime
Request start time.
CoapMessage message
CoAP request message.
uint8_t payload[]
Definition: ipv6.h:286
error_t coapClientGetOpaqueOption(const CoapMessage *message, uint16_t optionNum, uint_t optionIndex, const uint8_t **optionValue, size_t *optionLen)
Read an opaque option from the CoAP message.
error_t coapClientGetPayload(const CoapMessage *message, const uint8_t **payload, size_t *payloadLen)
Get message payload.
@ COAP_REQ_STATE_SEPARATE
@ COAP_REQUEST_STATUS_CANCELED
uint_t retransmitCount
Retransmission counter.
error_t(* CoapRequestCallback)(CoapClientContext *context, CoapClientRequest *request, CoapRequestStatus status, void *param)
Request completed callback.
uint16_t payloadLen
Definition: ipv6.h:281
void * param
Callback function parameter.
error_t coapClientGetUriQuery(const CoapMessage *message, char_t *queryString, size_t maxLen)
Get Uri-Query option.
unsigned int uint_t
Definition: compiler_port.h:50
systime_t retransmitTimeout
Retransmission timeout.
TCP/IP stack core.
uint32_t observeSeqNum
Sequence number for reordering detection.
error_t coapClientGetStringOption(const CoapMessage *message, uint16_t optionNum, uint_t optionIndex, const char_t **optionValue, size_t *optionLen)
Read a string option from the CoAP message.
CoapCode
CoAP method and response codes.
Definition: coap_common.h:113
Formatting and parsing of CoAP options.
CoapBlockSize
Block size parameter.
Definition: coap_option.h:200
CoapBlockSize txBlockSzx
TX block size.
error_t coapClientSetOpaqueOption(CoapMessage *message, uint16_t optionNum, uint_t optionIndex, const uint8_t *optionValue, size_t optionLen)
Add an opaque option to the CoAP message.
@ COAP_REQ_STATE_TIMEOUT
CoapRequestState
CoAP request states.
@ COAP_REQ_STATE_INIT