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  * 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_CLIENT_REQUEST_H
30 #define _COAP_CLIENT_REQUEST_H
31 
32 //Dependencies
33 #include "core/net.h"
34 #include "coap/coap_client.h"
35 #include "coap/coap_option.h"
36 
37 //C++ guard
38 #ifdef __cplusplus
39  extern "C" {
40 #endif
41 
42 
43 /**
44  * @brief CoAP request states
45  **/
46 
47 typedef enum
48 {
60 
61 
62 /**
63  * @brief Request status
64  **/
65 
66 typedef enum
67 {
74 
75 
76 /**
77  * @brief Request completed callback
78  **/
79 
81  CoapClientRequest *request, CoapRequestStatus status, void *param);
82 
83 
84 /**
85  * @brief CoAP request
86  **/
87 
89 {
90  CoapRequestState state; ///<CoAP request state
91  CoapClientContext *context; ///<CoAP client context
92  systime_t startTime; ///<Request start time
93  systime_t timeout; ///<Request timeout
94  systime_t retransmitStartTime; ///<Time at which the last message was sent
95  systime_t retransmitTimeout; ///<Retransmission timeout
96  uint_t retransmitCount; ///<Retransmission counter
97 #if (COAP_CLIENT_OBSERVE_SUPPORT == ENABLED)
98  uint32_t observeSeqNum; ///<Sequence number for reordering detection
99 #endif
100 #if (COAP_CLIENT_BLOCK_SUPPORT == ENABLED)
101  CoapBlockSize txBlockSzx; ///<TX block size
102  CoapBlockSize rxBlockSzx; ///<RX block size
103 #endif
104  CoapMessage message; ///<CoAP request message
105  CoapRequestCallback callback; ///<Callback function to invoke when the request completes
106  void *param; ///<Callback function parameter
107 };
108 
109 
110 //CoAP client related functions
112 
114  systime_t timeout);
115 
117  CoapRequestCallback callback, void *param);
118 
121 
124 
127 
130 
132 
134 
136  size_t maxLen);
137 
139 
141  size_t maxLen);
142 
144  size_t maxLen);
145 
147  char_t *queryString, size_t maxLen);
148 
150  uint_t optionIndex, const uint8_t *optionValue, size_t optionLen);
151 
153  uint_t optionIndex, const char_t *optionValue);
154 
156  uint_t optionIndex, uint32_t optionValue);
157 
158 error_t coapClientGetOpaqueOption(const CoapMessage *message, uint16_t optionNum,
159  uint_t optionIndex, const uint8_t **optionValue, size_t *optionLen);
160 
161 error_t coapClientGetStringOption(const CoapMessage *message, uint16_t optionNum,
162  uint_t optionIndex, const char_t **optionValue, size_t *optionLen);
163 
164 error_t coapClientGetUintOption(const CoapMessage *message, uint16_t optionNum,
165  uint_t optionIndex, uint32_t *optionValue);
166 
168  uint_t optionIndex);
169 
170 error_t coapClientSetPayload(CoapMessage *message, const void *payload,
171  size_t payloadLen);
172 
173 error_t coapClientGetPayload(const CoapMessage *message, const uint8_t **payload,
174  size_t *payloadLen);
175 
177  size_t length);
178 
180  size_t *length);
181 
182 //C++ guard
183 #ifdef __cplusplus
184  }
185 #endif
186 
187 #endif
uint8_t payloadLen
Definition: ipv6.h:341
uint32_t systime_t
Definition: compiler_port.h:44
CoapMessageType
CoAP message types.
Definition: coap_common.h:90
CoapMessage * coapClientGetResponseMessage(CoapClientRequest *request)
Get response message.
CoapMessage * coapClientGetRequestMessage(CoapClientRequest *request)
Get request message.
void coapClientDeleteRequest(CoapClientRequest *request)
Release the resources associated with a CoAP request.
error_t coapClientSendRequest(CoapClientRequest *request, CoapRequestCallback callback, void *param)
Send a CoAP request.
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.
char char_t
Definition: compiler_port.h:41
TCP/IP stack core.
error_t coapClientGetPayload(const CoapMessage *message, const uint8_t **payload, size_t *payloadLen)
Get message payload.
error_t coapClientSetUriPath(CoapMessage *message, const char_t *path)
Set Uri-Path option.
systime_t timeout
Request timeout.
error_t coapClientGetUriQuery(const CoapMessage *message, char_t *queryString, size_t maxLen)
Get Uri-Query option.
error_t coapClientSetMethodCode(CoapMessage *message, CoapCode code)
Set request method.
CoAP message.
Definition: coap_message.h:53
uint8_t message[]
Definition: chap.h:150
CoAP option formatting and parsing.
CoapBlockSize
Block size parameter.
Definition: coap_option.h:156
char_t type
CoapRequestState state
CoAP request state.
CoapCode
CoAP method and response codes.
Definition: coap_common.h:115
error_t coapClientDeleteOption(CoapMessage *message, uint16_t optionNum, uint_t optionIndex)
Remove an option from the CoAP message.
error_t coapClientGetType(const CoapMessage *message, CoapMessageType *type)
Get message type.
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 coapClientGetUriPath(const CoapMessage *message, char_t *path, size_t maxLen)
Get Uri-Path option.
error_t coapClientSetType(CoapMessage *message, CoapMessageType type)
Set message type.
CoapRequestCallback callback
Callback function to invoke when the request completes.
error_t coapClientSetPayload(CoapMessage *message, const void *payload, size_t payloadLen)
Set message payload.
error_t coapClientWritePayload(CoapMessage *message, const void *data, size_t length)
Write payload data.
error_t(* CoapRequestCallback)(CoapClientContext *context, CoapClientRequest *request, CoapRequestStatus status, void *param)
Request completed callback.
systime_t startTime
Request start time.
CoapClientContext * context
CoAP client context.
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.
error_t
Error codes.
Definition: error.h:40
uint8_t code
Definition: coap_common.h:179
error_t coapClientReadPayload(CoapMessage *message, void *data, size_t size, size_t *length)
Read payload data.
error_t coapClientGetMethodCode(const CoapMessage *message, CoapCode *code)
Get request method.
unsigned int uint_t
Definition: compiler_port.h:43
CoapBlockSize rxBlockSzx
RX block size.
CoapRequestState
CoAP request states.
uint8_t data[]
Definition: dtls_misc.h:167
uint_t retransmitCount
Retransmission counter.
systime_t retransmitStartTime
Time at which the last message was sent.
systime_t retransmitTimeout
Retransmission timeout.
error_t coapClientSetUintOption(CoapMessage *message, uint16_t optionNum, uint_t optionIndex, uint32_t optionValue)
Add a uint option to the CoAP message.
uint32_t observeSeqNum
Sequence number for reordering detection.
CoAP client.
CoapMessage message
CoAP request message.
void * param
Callback function parameter.
error_t coapClientGetLocationQuery(const CoapMessage *message, char_t *queryString, size_t maxLen)
Get Location-Query option.
error_t coapClientSetStringOption(CoapMessage *message, uint16_t optionNum, uint_t optionIndex, const char_t *optionValue)
Add a string option to the CoAP message.
CoapBlockSize txBlockSzx
TX block size.
error_t coapClientGetResponseCode(const CoapMessage *message, CoapCode *code)
Get response code.
error_t coapClientCancelRequest(CoapClientRequest *request)
Cancel an outstanding CoAP request.
CoapClientRequest * coapClientCreateRequest(CoapClientContext *context)
Initialize a new CoAP request.
CoapRequestStatus
Request status.
uint8_t length
Definition: dtls_misc.h:140
error_t coapClientGetUintOption(const CoapMessage *message, uint16_t optionNum, uint_t optionIndex, uint32_t *optionValue)
Read an uint option from the CoAP message.
#define CoapClientRequest
Definition: coap_client.h:141
error_t coapClientSetUriQuery(CoapMessage *message, const char_t *queryString)
Set Uri-Query option.
error_t coapClientGetLocationPath(const CoapMessage *message, char_t *path, size_t maxLen)
Get Location-Path option.
error_t coapClientSetRequestTimeout(CoapClientRequest *request, systime_t timeout)
Set request timeout.
#define CoapClientContext
Definition: coap_client.h:137