CoAP Message API. More...

Detailed Description

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include "iolist.h"
#include "net/unicoap/constants.h"
#include "net/unicoap/options.h"
+ Include dependency graph for message.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  unicoap_message_t
 Generic CoAP message. More...
 
struct  unicoap_message_properties_t
 Properties of a CoAP message. More...
 
struct  unicoap_parser_result_t
 Helper structure for parsing PDUs manually. More...
 

Serializing

#define UNICOAP_PDU_IOLIST_COUNT   (4)
 Number of iolists in the iolist buffer that must be passed to unicoap_pdu_buildv_options_and_payload.
 
ssize_t unicoap_pdu_build_options_and_payload (uint8_t *cursor, size_t remaining_capacity, const unicoap_message_t *message)
 Populates the given buffer with options and payload. More...
 
int unicoap_pdu_buildv_options_and_payload (uint8_t *header, size_t header_size, const unicoap_message_t *message, iolist_t iolists[UNICOAP_PDU_IOLIST_COUNT])
 Populates the given iolist with header, options, payload separator and payload. More...
 
ssize_t unicoap_pdu_build_header_rfc7252 (uint8_t *header, size_t capacity, const unicoap_message_t *message, const unicoap_message_properties_t *properties)
 Writes RFC 7252 PDU header in the given buffer. More...
 
static ssize_t unicoap_pdu_build_rfc7252 (uint8_t *pdu, size_t capacity, const unicoap_message_t *message, const unicoap_message_properties_t *properties)
 Writes RFC 7252 PDU into buffer. More...
 
static ssize_t unicoap_pdu_buildv_rfc7252 (uint8_t *header, size_t header_capacity, const unicoap_message_t *message, const unicoap_message_properties_t *properties, iolist_t iolists[UNICOAP_PDU_IOLIST_COUNT])
 Populates the given iolist with header according to RFC 7252, options, and payload. More...
 

CoAP message

enum  unicoap_payload_representation_t { UNICOAP_PAYLOAD_CONTIGUOUS = 0 , UNICOAP_PAYLOAD_NONCONTIGUOUS = 1 }
 A type indicating how a message's payload is represented. More...
 
const char * unicoap_string_from_rfc7252_type (unicoap_rfc7252_message_type_t type)
 Returns a null-terminated label for the CoAP over UDP/DTLS message type. More...
 

Parsing

typedef ssize_t(* unicoap_parser_t) (const uint8_t *pdu, size_t size, unicoap_message_t *message, unicoap_message_properties_t *properties)
 Common PDU parser. More...
 
ssize_t unicoap_pdu_parse_options_and_payload (uint8_t *cursor, const uint8_t *end, unicoap_message_t *message)
 Parses PDU starting at options. More...
 
ssize_t unicoap_pdu_parse_rfc7252 (uint8_t *pdu, size_t size, unicoap_message_t *message, unicoap_message_properties_t *properties)
 Parses RFC 7252 PDU. More...
 
static ssize_t unicoap_pdu_parse_rfc7252_result (uint8_t *pdu, size_t size, unicoap_parser_result_t *parsed)
 Helper method for manually parsing a PDU. More...
 

CoAP code

static uint8_t unicoap_code_class (uint8_t code)
 Reads the code class number encoded in the given code. More...
 
static uint8_t unicoap_code_detail (uint8_t code)
 Reads the code detail number encoded in the given code. More...
 
int unicoap_print_code (uint8_t code, char *string)
 Prints a c.dd class-detail string into the given buffer. More...
 
const char * unicoap_string_from_code (uint8_t code)
 Returns label for given CoAP message code. More...
 
const char * unicoap_string_from_code_class (uint8_t code)
 Returns label for given CoAP message code class. More...
 

Message initializers

static unicoap_message_t unicoap_message_alloc_empty (uint8_t code)
 Creates message with no payload and no options. More...
 
static unicoap_message_t unicoap_message_alloc (uint8_t code, uint8_t *payload, size_t payload_size)
 Creates message with no payload and no options. More...
 
static unicoap_message_t unicoap_message_alloc_string (uint8_t code, const char *payload)
 Creates message with payload from null-terminated but no options. More...
 
static unicoap_message_t unicoap_message_alloc_with_options (uint8_t code, uint8_t *payload, size_t payload_size, unicoap_options_t *options)
 Creates message with byte payload and options. More...
 
static unicoap_message_t unicoap_message_alloc_string_with_options (uint8_t code, const char *payload, unicoap_options_t *options)
 Creates message with payload from null-terminated UTF-8 string and options. More...
 

Signaling messages

static bool unicoap_message_is_signal (uint8_t code)
 Determines if the given message's code is a a signaling code. More...
 
const char * unicoap_string_from_signal (unicoap_signal_t signal)
 Returns label for given CoAP signal code. More...
 

Request messages

static bool unicoap_message_is_request (uint8_t code)
 Determines if the the given message's code is a a request code. More...
 
const char * unicoap_string_from_method (unicoap_method_t method)
 Obtains label for given request method. More...
 
static unicoap_message_t unicoap_request_alloc_empty (unicoap_method_t method)
 Creates request with no payload and no options. More...
 
static unicoap_message_t unicoap_request_alloc (unicoap_method_t method, uint8_t *payload, size_t payload_size)
 Creates request with no payload and no options. More...
 
static unicoap_message_t unicoap_request_alloc_string (unicoap_method_t method, const char *payload)
 Creates request with payload from null-terminated UTF-8 string but no options. More...
 
static unicoap_message_t unicoap_request_alloc_with_options (unicoap_method_t method, uint8_t *payload, size_t payload_size, unicoap_options_t *options)
 Creates request with byte payload and options. More...
 
static unicoap_message_t unicoap_request_alloc_string_with_options (unicoap_method_t method, const char *payload, unicoap_options_t *options)
 Creates request with payload from null-terminated UTF-8 string and options. More...
 

Response messages

bool unicoap_message_is_response (uint8_t code)
 Determines if the the given message's code is a a response code. More...
 
const char * unicoap_string_from_status (unicoap_status_t status)
 Generates short descriptive label from CoAP status code. More...
 
static unicoap_message_t unicoap_response_alloc_empty (unicoap_status_t status)
 Creates response with no payload and no options. More...
 
static unicoap_message_t unicoap_response_alloc (unicoap_status_t status, uint8_t *payload, size_t payload_size)
 Creates response with no payload and no options. More...
 
static unicoap_message_t unicoap_response_alloc_string (unicoap_status_t status, const char *payload)
 Creates response with payload from null-terminated UTF-8 string but no options. More...
 
static unicoap_message_t unicoap_response_alloc_with_options (unicoap_status_t status, uint8_t *payload, size_t payload_size, unicoap_options_t *options)
 Creates response with string byte and options. More...
 
static unicoap_message_t unicoap_response_alloc_string_with_options (unicoap_status_t status, const char *payload, unicoap_options_t *options)
 Creates response with payload from null-terminated UTF-8 string and options. More...