libcoap
4.2.1
|
Go to the source code of this file.
Data Structures | |
struct | error_desc_t |
Macros | |
#define | min(a, b) ((a) < (b) ? (a) : (b)) |
#define | max(a, b) ((a) > (b) ? (a) : (b)) |
Functions | |
void | coap_pdu_clear (coap_pdu_t *pdu, size_t size) |
Clears any contents from pdu and resets used_size , and data pointers. More... | |
coap_pdu_t * | coap_pdu_init (uint8_t type, uint8_t code, uint16_t tid, size_t size) |
Creates a new CoAP PDU with at least enough storage space for the given size maximum message size. More... | |
coap_pdu_t * | coap_new_pdu (const struct coap_session_t *session) |
Creates a new CoAP PDU. More... | |
void | coap_delete_pdu (coap_pdu_t *pdu) |
Dispose of an CoAP PDU and frees associated storage. More... | |
int | coap_pdu_resize (coap_pdu_t *pdu, size_t new_size) |
Dynamically grows the size of pdu to new_size . More... | |
static int | coap_pdu_check_resize (coap_pdu_t *pdu, size_t size) |
int | coap_add_token (coap_pdu_t *pdu, size_t len, const uint8_t *data) |
Adds token of length len to pdu . More... | |
size_t | coap_add_option (coap_pdu_t *pdu, uint16_t type, size_t len, const uint8_t *data) |
Adds option of given type to pdu that is passed as first parameter. More... | |
uint8_t * | coap_add_option_later (coap_pdu_t *pdu, uint16_t type, size_t len) |
Adds option of given type to pdu that is passed as first parameter, but does not write a value. More... | |
int | coap_add_data (coap_pdu_t *pdu, size_t len, const uint8_t *data) |
Adds given data to the pdu that is passed as first parameter. More... | |
uint8_t * | coap_add_data_after (coap_pdu_t *pdu, size_t len) |
Adds given data to the pdu that is passed as first parameter but does not copyt it. More... | |
int | coap_get_data (const coap_pdu_t *pdu, size_t *len, uint8_t **data) |
Retrieves the length and data pointer of specified PDU. More... | |
const char * | coap_response_phrase (unsigned char code) |
Returns a human-readable response phrase for the specified CoAP response code . More... | |
static size_t | next_option_safe (coap_opt_t **optp, size_t *length) |
Advances *optp to next option if still in PDU. More... | |
size_t | coap_pdu_parse_header_size (coap_proto_t proto, const uint8_t *data) |
Interprets data to determine the number of bytes in the header. More... | |
size_t | coap_pdu_parse_size (coap_proto_t proto, const uint8_t *data, size_t length) |
Parses data to extract the message size. More... | |
int | coap_pdu_parse_header (coap_pdu_t *pdu, coap_proto_t proto) |
Decode the protocol specific header for the specified PDU. More... | |
int | coap_pdu_parse_opt (coap_pdu_t *pdu) |
Verify consistency in the given CoAP PDU structure and locate the data. More... | |
int | coap_pdu_parse (coap_proto_t proto, const uint8_t *data, size_t length, coap_pdu_t *pdu) |
Parses data into the CoAP PDU structure given in result . More... | |
size_t | coap_pdu_encode_header (coap_pdu_t *pdu, coap_proto_t proto) |
Compose the protocol specific header for the specified PDU. More... | |
Variables | |
error_desc_t | coap_error [] |
int coap_add_data | ( | coap_pdu_t * | pdu, |
size_t | len, | ||
const uint8_t * | data | ||
) |
Adds given data to the pdu that is passed as first parameter.
Note that the PDU's data is destroyed by coap_add_option(). coap_add_data() must be called only once per PDU, otherwise the result is undefined.
Definition at line 288 of file pdu.c.
uint8_t* coap_add_data_after | ( | coap_pdu_t * | pdu, |
size_t | len | ||
) |
Adds given data to the pdu that is passed as first parameter but does not copyt it.
Note that the PDU's data is destroyed by coap_add_option(). coap_add_data() must be have been called once for this PDU, otherwise the result is undefined. The actual data must be copied at the returned location.
Definition at line 300 of file pdu.c.
size_t coap_add_option | ( | coap_pdu_t * | pdu, |
uint16_t | type, | ||
size_t | len, | ||
const uint8_t * | data | ||
) |
Adds option of given type to pdu that is passed as first parameter.
coap_add_option() destroys the PDU's data, so coap_add_data() must be called after all options have been added. As coap_add_token() destroys the options following the token, the token must be added before coap_add_option() is called. This function returns the number of bytes written or 0
on error.
Definition at line 215 of file pdu.c.
uint8_t* coap_add_option_later | ( | coap_pdu_t * | pdu, |
uint16_t | type, | ||
size_t | len | ||
) |
Adds option of given type to pdu that is passed as first parameter, but does not write a value.
It works like coap_add_option with respect to calling sequence (i.e. after token and before data). This function returns a memory address to which the option data has to be written before the PDU can be sent, or NULL
on error.
Definition at line 252 of file pdu.c.
int coap_add_token | ( | coap_pdu_t * | pdu, |
size_t | len, | ||
const uint8_t * | data | ||
) |
Adds token of length len
to pdu
.
Adding the token destroys any following contents of the pdu. Hence options and data must be added after coap_add_token() has been called. In pdu
, length is set to len
+ 4
, and max_delta is set to 0
. This function returns 0
on error or a value greater than zero on success.
pdu | The PDU where the token is to be added. |
len | The length of the new token. |
data | The token to add. |
0
on error. Definition at line 191 of file pdu.c.
void coap_delete_pdu | ( | coap_pdu_t * | ) |
Dispose of an CoAP PDU and frees associated storage.
Not that in general you should not call this function directly. When a PDU is sent with coap_send(), coap_delete_pdu() will be called automatically for you.
Definition at line 127 of file pdu.c.
int coap_get_data | ( | const coap_pdu_t * | pdu, |
size_t * | len, | ||
uint8_t ** | data | ||
) |
coap_pdu_t* coap_new_pdu | ( | const struct coap_session_t * | session | ) |
|
static |
void coap_pdu_clear | ( | coap_pdu_t * | pdu, |
size_t | size | ||
) |
Clears any contents from pdu
and resets used_size
, and data
pointers.
max_size
is set to size
, any other field is set to 0
. Note that pdu
must be a valid pointer to a coap_pdu_t object created e.g. by coap_pdu_init().
Definition at line 34 of file pdu.c.
size_t coap_pdu_encode_header | ( | coap_pdu_t * | pdu, |
coap_proto_t | proto | ||
) |
coap_pdu_t* coap_pdu_init | ( | uint8_t | type, |
uint8_t | code, | ||
uint16_t | tid, | ||
size_t | size | ||
) |
Creates a new CoAP PDU with at least enough storage space for the given size
maximum message size.
The function returns a pointer to the node coap_pdu_t object on success, or NULL
on error. The storage allocated for the result must be released with coap_delete_pdu() if coap_send() is not called.
type | The type of the PDU (one of COAP_MESSAGE_CON, COAP_MESSAGE_NON, COAP_MESSAGE_ACK, COAP_MESSAGE_RST). |
code | The message code. |
tid | The transcation id to set or 0 if unknown / not applicable. |
size | The maximum allowed number of byte for the message. |
NULL
on error. Definition at line 79 of file pdu.c.
int coap_pdu_parse | ( | coap_proto_t | proto, |
const uint8_t * | data, | ||
size_t | length, | ||
coap_pdu_t * | pdu | ||
) |
Parses data
into the CoAP PDU structure given in result
.
The target pdu must be large enough to This function returns 0
on error or a number greater than zero on success.
proto | Session's protocol |
data | The raw data to parse as CoAP PDU. |
length | The actual size of data . |
pdu | The PDU structure to fill. Note that the structure must provide space to hold at least the token and options part of the message. |
0
on error. Definition at line 543 of file pdu.c.
int coap_pdu_parse_header | ( | coap_pdu_t * | pdu, |
coap_proto_t | proto | ||
) |
size_t coap_pdu_parse_header_size | ( | coap_proto_t | proto, |
const uint8_t * | data | ||
) |
Interprets data
to determine the number of bytes in the header.
This function returns 0
on error or a number greater than zero on success.
proto | Session's protocol |
data | The first byte of raw data to parse as CoAP PDU. |
0
on error. Definition at line 405 of file pdu.c.
int coap_pdu_parse_opt | ( | coap_pdu_t * | pdu | ) |
Verify consistency in the given CoAP PDU structure and locate the data.
This function returns 0
on error or a number greater than zero on success. This function only parses the token and options, up to the payload start marker.
pdu | The PDU structure to. |
0
on error. Definition at line 492 of file pdu.c.
size_t coap_pdu_parse_size | ( | coap_proto_t | proto, |
const uint8_t * | data, | ||
size_t | length | ||
) |
Parses data
to extract the message size.
length
must be at least coap_pdu_parse_header_size(proto, data). This function returns 0
on error or a number greater than zero on success.
proto | Session's protocol |
data | The raw data to parse as CoAP PDU. |
length | The actual size of data . |
0
on error. Definition at line 428 of file pdu.c.
int coap_pdu_resize | ( | coap_pdu_t * | pdu, |
size_t | new_size | ||
) |
Dynamically grows the size of pdu
to new_size
.
The new size must not exceed the PDU's configure maximum size. On success, this function returns 1, otherwise 0.
pdu | The PDU to resize. |
new_size | The new size in bytes. |
Definition at line 140 of file pdu.c.
const char* coap_response_phrase | ( | unsigned char | code | ) |
Returns a human-readable response phrase for the specified CoAP response code
.
This function returns NULL
if not found.
code | The response code for which the literal phrase should be retrieved. |
NULL
if not found. Definition at line 370 of file pdu.c.
|
static |
error_desc_t coap_error[] |