465 message->
code = code;
493 message->
code = code;
524 message->
code = code;
526 message->
payload = (uint8_t*)payload;
539 .payload = (uint8_t*)payload,
540 .payload_size = payload ? strlen(payload) : 0 };
556 uint8_t* payload,
size_t payload_size,
559 message->
code = code;
579 .
code = code, .options = options, .payload = payload, .payload_size = payload_size
600 payload ? strlen(payload) : 0, options);
618 .payload = (uint8_t*)payload,
619 .payload_size = payload ? strlen(payload) : 0 };
764 uint8_t* payload,
size_t payload_size)
823 uint8_t* payload,
size_t payload_size,
920 response->
status = status;
964 uint8_t* payload,
size_t payload_size)
1004 const char* payload)
1024 size_t payload_size,
1041 size_t payload_size,
1060 const char* payload,
1076 const char* payload,
1183 #define UNICOAP_PDU_IOLIST_COUNT (4)
#define assert(cond)
abort the program if assertion is false
Constants used in CoAP such as option numbers and message codes.
static bool unicoap_message_is_request(uint8_t code)
Determines if the the given message's code is a a request code.
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.
const char * unicoap_string_from_code_class(uint8_t code)
Returns label for given CoAP message code class.
static void unicoap_request_set_method(unicoap_message_t *request, unicoap_method_t method)
Sets request method.
static void unicoap_message_payload_set(unicoap_message_t *message, uint8_t *payload, size_t size)
Assigns the given message a contiguous payload.
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.
static iolist_t * unicoap_message_payload_get_chunks(unicoap_message_t *message)
Retrieves noncontiguous message payload, if available.
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.
static void unicoap_message_init_with_options(unicoap_message_t *message, uint8_t code, uint8_t *payload, size_t payload_size, unicoap_options_t *options)
Initializes message with byte payload and options.
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.
const char * unicoap_string_from_status(unicoap_status_t status)
Generates short descriptive label from CoAP status code.
static void unicoap_request_init_with_options(unicoap_message_t *request, unicoap_method_t method, uint8_t *payload, size_t payload_size, unicoap_options_t *options)
Initializes request with byte payload and options.
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.
static void unicoap_request_init_string(unicoap_message_t *request, unicoap_method_t method, const char *payload)
Initializes request with payload from null-terminated UTF-8 string but no options.
static uint8_t * unicoap_message_options_data(const unicoap_message_t *message)
Retrieves options storage buffer.
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.
static uint8_t * unicoap_message_payload_get(unicoap_message_t *message)
Retrieves contiguous message payload, if available.
static unicoap_message_t unicoap_response_alloc_empty(unicoap_status_t status)
Creates response with no payload and no options.
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.
static void unicoap_message_set_signal(unicoap_message_t *message, unicoap_signal_t signal)
Sets signal code of given signal message.
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.
static void unicoap_response_init_empty(unicoap_message_t *response, unicoap_status_t status)
Initializes response with no payload and no options.
static void unicoap_message_init_string_with_options(unicoap_message_t *message, uint8_t code, const char *payload, unicoap_options_t *options)
Initializes message with payload from null-terminated UTF-8 string and options.
ssize_t unicoap_message_payload_make_contiguous(unicoap_message_t *message, uint8_t *buffer, size_t capacity)
Copies noncontiguous payload into contiguous storage buffer.
static void unicoap_response_init_string(unicoap_message_t *response, unicoap_status_t status, const char *payload)
Initializes response with payload from null-terminated UTF-8 string but no options.
static unicoap_message_t unicoap_message_alloc_empty(uint8_t code)
Creates message with no payload and no options.
static uint8_t unicoap_code_detail(uint8_t code)
Reads the code detail number encoded in the given code.
#define UNICOAP_RFC7252_MESSAGE_TYPE_FIXED_WIDTH
Number of bits needed to represent unicoap_rfc7252_message_type_t.
static unicoap_message_t unicoap_message_alloc_string(uint8_t code, const char *payload)
Creates message with payload from null-terminated but no options.
ssize_t unicoap_message_payload_copy(const unicoap_message_t *message, uint8_t *buffer, size_t capacity)
Copies payload into given buffer.
int unicoap_print_code(uint8_t code, char *string)
Prints a c.dd class-detail string into the given buffer.
static uint8_t unicoap_code_class(uint8_t code)
Reads the code class number encoded in the given code.
static void unicoap_request_init_string_with_options(unicoap_message_t *request, unicoap_method_t method, const char *payload, unicoap_options_t *options)
Initializes request with payload from null-terminated UTF-8 string and options.
static void unicoap_request_init(unicoap_message_t *request, unicoap_method_t method, uint8_t *payload, size_t payload_size)
Initializes request with payload but no options.
const char * unicoap_string_from_signal(unicoap_signal_t signal)
Returns label for given CoAP signal code.
static void unicoap_response_init_with_options(unicoap_message_t *response, unicoap_status_t status, uint8_t *payload, size_t payload_size, unicoap_options_t *options)
Initializes response with byte payload and options.
const char * unicoap_string_from_method(unicoap_method_t method)
Obtains label for given request method.
static unicoap_status_t unicoap_response_get_status(const unicoap_message_t *response)
Obtains response status from the given message's code.
static size_t unicoap_message_payload_get_size(const unicoap_message_t *message)
Retrieves payload size, regardless of payload representation.
static void unicoap_response_init_string_with_options(unicoap_message_t *response, unicoap_status_t status, const char *payload, unicoap_options_t *options)
Initializes response with payload from null-terminated UTF-8 string and options.
const char * unicoap_string_from_code(uint8_t code)
Returns label for given CoAP message code.
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.
static void unicoap_response_init(unicoap_message_t *response, unicoap_status_t status, uint8_t *payload, size_t payload_size)
Initializes response with payload but no options.
static bool unicoap_message_is_signal(uint8_t code)
Determines if the given message's code is a a signaling code.
unicoap_payload_representation_t
A type indicating how a message's payload is represented.
static void unicoap_request_init_empty(unicoap_message_t *request, unicoap_method_t method)
Initializes request with no payload and no options.
bool unicoap_message_payload_is_empty(const unicoap_message_t *message)
Determines whether message has any payload.
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.
static unicoap_method_t unicoap_request_get_method(const unicoap_message_t *request)
Obtains request method from the given message's code.
unicoap_status_t
CoAP response status codes.
static unicoap_message_t unicoap_request_alloc_empty(unicoap_method_t method)
Creates request with no payload and no options.
static void unicoap_message_init_empty(unicoap_message_t *message, uint8_t code)
Initializes message with no payload and no options.
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.
unicoap_signal_t
CoAP Signal Message Codes (7.xx range)
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.
static void unicoap_message_payload_set_chunks(unicoap_message_t *message, iolist_t *chunks)
Assigns the given message a noncontiguous payload.
unicoap_rfc7252_message_type_t
RFC 7252 message type.
bool unicoap_message_is_response(uint8_t code)
Determines if the the given message's code is a a response code.
static void unicoap_response_set_status(unicoap_message_t *response, unicoap_status_t status)
Sets response status.
static unicoap_signal_t unicoap_message_get_signal(const unicoap_message_t *message)
Retrieves signal code from given signal message.
#define UNICOAP_TOKEN_LENGTH_FIXED_WIDTH
Numbers of bits needed to represent token length.
static void unicoap_message_init_string(unicoap_message_t *message, uint8_t code, const char *payload)
Initializes message with payload from null-terminated UTF-8 string but no options.
unicoap_method_t
CoAP request method codes (0.xx range)
static void unicoap_message_init(unicoap_message_t *message, uint8_t code, uint8_t *payload, size_t payload_size)
Initializes message with payload but no options.
static size_t unicoap_message_options_size(const unicoap_message_t *message)
Retrieves total size of options in buffer.
void unicoap_message_payload_append_chunk(unicoap_message_t *message, iolist_t *chunk)
Appends a payload chunk to a message.
@ UNICOAP_CODE_CLASS_SIGNAL
Signaling message.
@ UNICOAP_CODE_CLASS_REQUEST
Message class for requests.
@ UNICOAP_PAYLOAD_NONCONTIGUOUS
iolist_t payload vector
@ UNICOAP_PAYLOAD_CONTIGUOUS
Contiguous payload buffer.
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.
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.
ssize_t unicoap_pdu_parse_options_and_payload(uint8_t *cursor, const uint8_t *end, unicoap_message_t *message)
Parses PDU starting at options.
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.
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.
#define UNICOAP_PDU_IOLIST_COUNT
Number of iolists in the iolist buffer that must be passed to unicoap_pdu_buildv_options_and_payload.
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.
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.
ssize_t(* unicoap_parser_t)(const uint8_t *pdu, size_t size, unicoap_message_t *message, unicoap_message_properties_t *properties)
Common PDU parser.
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.
size_t iolist_size(const iolist_t *iolist)
Sum up number of bytes in iolist.
iolist scatter / gather IO
iolist structure definition
Properties of a CoAP message.
bool is_registration
Determines if the corresponding message is considered an Observe registration.
uint16_t id
RFC 7252 message ID.
uint8_t * token
CoAP token used to correlate requests to responses.
uint8_t token_length
Length of unicoap_message_properties_t::token.
bool is_notification
Determines if the corresponding message is considered an Observe notification.
unicoap_rfc7252_message_type_t type
RFC 7252 message type.
unicoap_payload_representation_t payload_representation
A value indicating how the payload is represented.
unicoap_method_t method
CoAP request method.
size_t payload_size
Size of message payload.
unicoap_status_t status
CoAP response status.
uint8_t * payload
Message payload.
uint8_t code
CoAP message code.
unicoap_signal_t signal
CoAP signal.
unicoap_options_t * options
Message options.
iolist_t * payload_chunks
Noncontiguous payload.
uint8_t * data
Pointer into options storage where this option starts.
size_t storage_size
Current size of encoded options.
unicoap_option_entry_t entries[CONFIG_UNICOAP_OPTIONS_MAX]
Helper array used to encode and decode options into options storage.
Helper structure for parsing PDUs manually.
unicoap_message_properties_t properties
Parsed message properties.
unicoap_options_t options
Parsed options.
unicoap_message_t message
Message.