Contiki-NG
Modules | Files | Macros | Enumerations | Functions

This is an implementation of the Constrained Application Protocol. More...

Modules

 CoAP keystore API
 The CoAP keystore API defines a common interface for retrieving authorization information for CoAP/DTLS.
 
 CoAP timer API
 The CoAP timer API defines a common interface for CoAP timer and time functionality.
 
 CoAP transport API
 The CoAP transport API defines a common interface for sending/receiving CoAP messages.
 

Files

file  coap-request-state.h
 
    Common request state for all the APIs

 

Macros

#define COAP_MAX_PACKET_SIZE   (COAP_MAX_HEADER_SIZE + COAP_MAX_CHUNK_SIZE)
 The max size of the CoAP messages.
 

Enumerations

enum  coap_resource_flags_t
 Resource flags for allowed methods and special functionalities.
 

Functions

int coap_block1_handler (coap_message_t *request, coap_message_t *response, uint8_t *target, size_t *len, size_t max_len)
 Block 1 support within a coap-ressource. More...
 
int coap_send_request (coap_callback_request_state_t *callback_state, coap_endpoint_t *endpoint, coap_message_t *request, void(*callback)(coap_callback_request_state_t *callback_state))
 Send a CoAP request to a remote endpoint. More...
 
void coap_activate_resource (coap_resource_t *resource, const char *path)
 Makes a resource available under the given URI path. More...
 
coap_resource_t * coap_get_first_resource (void)
 Returns the first of registered CoAP resources. More...
 
coap_resource_t * coap_get_next_resource (coap_resource_t *resource)
 Returns the next registered CoAP resource. More...
 
void coap_log_string (const char *text, size_t len)
 Logs a CoAP string that has a length but might not be 0-terminated. More...
 
void coap_separate_reject ()
 Reject a request that would require a separate response with an error message. More...
 
void coap_separate_accept (coap_message_t *coap_req, coap_separate_t *separate_store)
 Initiate a separate response with an empty ACK. More...
 

Detailed Description

This is an implementation of the Constrained Application Protocol.

Function Documentation

◆ coap_activate_resource()

void coap_activate_resource ( coap_resource_t *  resource,
const char *  path 
)

Makes a resource available under the given URI path.

Resources wanted to be accessible should be activated with the following code.

Parameters
resourceA pointer to a resource implementation
pathThe URI path string for this resource

The resource implementation must be imported first using the extern keyword. The build system takes care of compiling every *.c file in the ./resources/ sub-directory (see example Makefile).

Parameters
resourceA CoAP resource defined through the RESOURCE macros.
pathThe local URI path where to provide the resource.

Definition at line 399 of file coap-engine.c.

◆ coap_block1_handler()

int coap_block1_handler ( coap_message_t *  request,
coap_message_t *  response,
uint8_t *  target,
size_t *  len,
size_t  max_len 
)

Block 1 support within a coap-ressource.

This function will help you to use block 1. If target is null error handling and response configuration is active. On return value 0, the last block was recived, while on return value 1 more blocks will follow. With target, len and maxlen this function will assemble the blocks.

You can find an example in: examples/er-rest-example/resources/res-b1-sep-b2.c

Parameters
requestRequest pointer from the handler
responseResponse pointer from the handler
targetPointer to the buffer where the request payload can be assembled
lenPointer to the variable, where the function stores the actual length
max_lenLength of the "target"-Buffer
Returns
0 if initialisation was successful -1 if initialisation failed

Definition at line 79 of file coap-block1.c.

◆ coap_get_first_resource()

coap_resource_t * coap_get_first_resource ( void  )

Returns the first of registered CoAP resources.

Returns
The first registered CoAP resource or NULL if none exists.

Definition at line 424 of file coap-engine.c.

References list_head().

◆ coap_get_next_resource()

coap_resource_t * coap_get_next_resource ( coap_resource_t *  resource)

Returns the next registered CoAP resource.

Returns
The next resource or NULL if no more exists.

Definition at line 430 of file coap-engine.c.

References list_item_next().

◆ coap_log_string()

void coap_log_string ( const char *  text,
size_t  len 
)

Logs a CoAP string that has a length but might not be 0-terminated.

Parameters
textThe CoAP string
lenThe number of characters in the CoAP string

Definition at line 47 of file coap-log.c.

◆ coap_send_request()

int coap_send_request ( coap_callback_request_state_t *  callback_state,
coap_endpoint_t *  endpoint,
coap_message_t *  request,
void(*)(coap_callback_request_state_t *callback_state)  callback 
)

Send a CoAP request to a remote endpoint.

Parameters
callback_stateThe callback state to handle the CoAP request
endpointThe destination endpoint
requestThe request to be sent
callbackcallback to execute when the response arrives or the timeout expires
Returns
1 if there is a transaction available to send, 0 otherwise

Definition at line 150 of file coap-callback-api.c.

◆ coap_separate_accept()

void coap_separate_accept ( coap_message_t *  coap_req,
coap_separate_t *  separate_store 
)

Initiate a separate response with an empty ACK.

Parameters
coap_reqThe request to accept
separate_storeA pointer to the data structure that will store the relevant information for the response

When the server does not have enough resources left to store the information for a separate response or otherwise cannot execute the resource handler, this function will respond with 5.03 Service Unavailable. The client can then retry later.

Definition at line 86 of file coap-separate.c.

◆ coap_separate_reject()

void coap_separate_reject ( )

Reject a request that would require a separate response with an error message.

When the server does not have enough resources left to store the information for a separate response or otherwise cannot execute the resource handler, this function will respond with 5.03 Service Unavailable. The client can then retry later.

Definition at line 67 of file coap-separate.c.