gcoap.h File Reference

gcoap definition More...

Detailed Description

#include <stdint.h>
#include <stdatomic.h>
#include "net/sock/udp.h"
#include "mutex.h"
#include "nanocoap.h"
#include "xtimer.h"
+ Include dependency graph for gcoap.h:

Go to the source code of this file.

Data Structures

struct  gcoap_listener
 A modular collection of resources for a server. More...
 
struct  gcoap_request_memo_t
 Memo to handle a response for a request. More...
 
struct  gcoap_observe_memo_t
 Memo for Observe registration and notifications. More...
 
struct  gcoap_state_t
 Container for the state of gcoap itself. More...
 

Macros

#define GCOAP_MSG_QUEUE_SIZE   (4)
 Size for module message queue.
 
#define GCOAP_PORT   (5683)
 Server port; use RFC 7252 default if not defined.
 
#define GCOAP_PDU_BUF_SIZE   (128)
 Size of the buffer used to build a CoAP request or response.
 
#define GCOAP_REQ_OPTIONS_BUF   (40)
 Size of the buffer used to write options, other than Uri-Path, in a request. More...
 
#define GCOAP_RESP_OPTIONS_BUF   (8)
 Size of the buffer used to write options in a response. More...
 
#define GCOAP_OBS_OPTIONS_BUF   (8)
 Size of the buffer used to write options in an Observe notification. More...
 
#define GCOAP_REQ_WAITING_MAX   (2)
 Maximum number of requests awaiting a response.
 
#define GCOAP_TOKENLEN_MAX   (8)
 Maximum length in bytes for a token.
 
#define GCOAP_HEADER_MAXLEN   (sizeof(coap_hdr_t) + GCOAP_TOKENLEN_MAX)
 Maximum length in bytes for a header, including the token.
 
#define GCOAP_TOKENLEN   (2)
 Length in bytes for a token; use 2 if not defined.
 
#define GCOAP_PAYLOAD_MARKER   (0xFF)
 Marks the boundary between header and payload.
 
#define GCOAP_RECV_TIMEOUT   (1 * US_PER_SEC)
 Time in usec that the event loop waits for an incoming CoAP message.
 
#define GCOAP_NON_TIMEOUT   (5000000U)
 Default time to wait for a non-confirmable response [in usec]. More...
 
#define GCOAP_MSG_TYPE_TIMEOUT   (0x1501)
 Identifies waiting timed out for a response to a sent message.
 
#define GCOAP_MSG_TYPE_INTR   (0x1502)
 Identifies a request to interrupt listening for an incoming message on a sock. More...
 
#define GCOAP_OBS_CLIENTS_MAX   (2)
 Maximum number of Observe clients; use 2 if not defined.
 
#define GCOAP_OBS_REGISTRATIONS_MAX   (2)
 Maximum number of registrations for Observable resources; use 2 if not defined.
 
#define GCOAP_OBS_VALUE_WIDTH   (3)
 Width in bytes of the Observe option value for a notification. More...
 
#define GCOAP_OBS_TICK_EXPONENT   (5)
 See GCOAP_OBS_VALUE_WIDTH.
 
#define GCOAP_STACK_SIZE   (THREAD_STACKSIZE_DEFAULT + DEBUG_EXTRA_STACKSIZE)
 Stack size for module thread.
 
States for the memo used to track waiting for a response
#define GCOAP_MEMO_UNUSED   (0)
 This memo is unused.
 
#define GCOAP_MEMO_WAIT   (1)
 Request sent; awaiting response.
 
#define GCOAP_MEMO_RESP   (2)
 Got response.
 
#define GCOAP_MEMO_TIMEOUT   (3)
 Timeout waiting for response.
 
#define GCOAP_MEMO_ERR   (4)
 Error processing response packet.
 
States for the memo used to track Observe registrations
#define GCOAP_OBS_MEMO_UNUSED   (0)
 This memo is unused.
 
#define GCOAP_OBS_MEMO_IDLE   (1)
 Registration OK; no current activity.
 
#define GCOAP_OBS_MEMO_PENDING   (2)
 Resource changed; notification pending.
 
Return values for gcoap_obs_init()
#define GCOAP_OBS_INIT_OK   (0)
 
#define GCOAP_OBS_INIT_ERR   (-1)
 
#define GCOAP_OBS_INIT_UNUSED   (-2)
 

Typedefs

typedef struct gcoap_listener gcoap_listener_t
 A modular collection of resources for a server.
 
typedef void(* gcoap_resp_handler_t) (unsigned req_state, coap_pkt_t *pdu, sock_udp_ep_t *remote)
 Handler function for a server response, including the state for the originating request. More...
 

Functions

kernel_pid_t gcoap_init (void)
 Initializes the gcoap thread and device. More...
 
void gcoap_register_listener (gcoap_listener_t *listener)
 Starts listening for resource paths. More...
 
int gcoap_req_init (coap_pkt_t *pdu, uint8_t *buf, size_t len, unsigned code, char *path)
 Initializes a CoAP request PDU on a buffer. More...
 
ssize_t gcoap_finish (coap_pkt_t *pdu, size_t payload_len, unsigned format)
 Finishes formatting a CoAP PDU after the payload has been written. More...
 
static ssize_t gcoap_request (coap_pkt_t *pdu, uint8_t *buf, size_t len, unsigned code, char *path)
 Writes a complete CoAP request PDU when there is not a payload. More...
 
size_t gcoap_req_send2 (const uint8_t *buf, size_t len, const sock_udp_ep_t *remote, gcoap_resp_handler_t resp_handler)
 Sends a buffer containing a CoAP request to the provided endpoint. More...
 
size_t gcoap_req_send (const uint8_t *buf, size_t len, const ipv6_addr_t *addr, uint16_t port, gcoap_resp_handler_t resp_handler)
 Sends a buffer containing a CoAP request to the provided host/port. More...
 
int gcoap_resp_init (coap_pkt_t *pdu, uint8_t *buf, size_t len, unsigned code)
 Initializes a CoAP response packet on a buffer. More...
 
static ssize_t gcoap_response (coap_pkt_t *pdu, uint8_t *buf, size_t len, unsigned code)
 Writes a complete CoAP response PDU when there is no payload. More...
 
int gcoap_obs_init (coap_pkt_t *pdu, uint8_t *buf, size_t len, const coap_resource_t *resource)
 Initializes a CoAP Observe notification packet on a buffer, for the observer registered for a resource. More...
 
size_t gcoap_obs_send (const uint8_t *buf, size_t len, const coap_resource_t *resource)
 Sends a buffer containing a CoAP Observe notification to the observer registered for a resource. More...
 
uint8_t gcoap_op_state (void)
 Provides important operational statistics. More...
 
int gcoap_get_resource_list (void *buf, size_t maxlen, uint8_t cf)
 Get the resource list, currently only CoRE Link Format (COAP_FORMAT_LINK) supported. More...
 
int gcoap_add_qstring (coap_pkt_t *pdu, const char *key, const char *val)
 Adds a single Uri-Query option to a CoAP request. More...