libcoap
4.2.1
|
Pre-defined constants that reflect defaults for CoAP. More...
Go to the source code of this file.
Data Structures | |
struct | coap_option |
struct | coap_pdu_t |
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload marker (0xff), then the payload if stored inline. More... | |
Macros | |
#define | COAP_DEFAULT_PORT 5683 /* CoAP default UDP/TCP port */ |
#define | COAPS_DEFAULT_PORT 5684 /* CoAP default UDP/TCP port for secure transmission */ |
#define | COAP_DEFAULT_MAX_AGE 60 /* default maximum object lifetime in seconds */ |
#define | COAP_DEFAULT_MTU 1152 |
#define | COAP_MESSAGE_SIZE_OFFSET_TCP8 13 |
#define | COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */ |
#define | COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */ |
#define | COAP_MAX_MESSAGE_SIZE_TCP0 (COAP_MESSAGE_SIZE_OFFSET_TCP8-1) /* 12 */ |
#define | COAP_MAX_MESSAGE_SIZE_TCP8 (COAP_MESSAGE_SIZE_OFFSET_TCP16-1) /* 268 */ |
#define | COAP_MAX_MESSAGE_SIZE_TCP16 (COAP_MESSAGE_SIZE_OFFSET_TCP32-1) /* 65804 */ |
#define | COAP_MAX_MESSAGE_SIZE_TCP32 (COAP_MESSAGE_SIZE_OFFSET_TCP32+0xFFFFFFFF) |
#define | COAP_DEFAULT_MAX_PDU_RX_SIZE (8*1024*1024+256) |
#define | COAP_DEBUG_BUF_SIZE (8 + 1024 * 2) |
#define | COAP_DEFAULT_VERSION 1 /* version of CoAP supported */ |
#define | COAP_DEFAULT_SCHEME "coap" /* the default scheme for CoAP URIs */ |
#define | COAP_DEFAULT_URI_WELLKNOWN ".well-known/core" |
well-known resources URI More... | |
#define | COAP_MESSAGE_CON 0 /* confirmable message (requires ACK/RST) */ |
#define | COAP_MESSAGE_NON 1 /* non-confirmable message (one-shot message) */ |
#define | COAP_MESSAGE_ACK 2 /* used to acknowledge confirmable messages */ |
#define | COAP_MESSAGE_RST 3 /* indicates error in received messages */ |
#define | COAP_REQUEST_GET 1 |
#define | COAP_REQUEST_POST 2 |
#define | COAP_REQUEST_PUT 3 |
#define | COAP_REQUEST_DELETE 4 |
#define | COAP_REQUEST_FETCH 5 /* RFC 8132 */ |
#define | COAP_REQUEST_PATCH 6 /* RFC 8132 */ |
#define | COAP_REQUEST_IPATCH 7 /* RFC 8132 */ |
#define | COAP_OPTION_IF_MATCH 1 /* C, opaque, 0-8 B, (none) */ |
#define | COAP_OPTION_URI_HOST 3 /* C, String, 1-255 B, destination address */ |
#define | COAP_OPTION_ETAG 4 /* E, opaque, 1-8 B, (none) */ |
#define | COAP_OPTION_IF_NONE_MATCH 5 /* empty, 0 B, (none) */ |
#define | COAP_OPTION_URI_PORT 7 /* C, uint, 0-2 B, destination port */ |
#define | COAP_OPTION_LOCATION_PATH 8 /* E, String, 0-255 B, - */ |
#define | COAP_OPTION_URI_PATH 11 /* C, String, 0-255 B, (none) */ |
#define | COAP_OPTION_CONTENT_FORMAT 12 /* E, uint, 0-2 B, (none) */ |
#define | COAP_OPTION_CONTENT_TYPE COAP_OPTION_CONTENT_FORMAT |
#define | COAP_OPTION_MAXAGE 14 /* E, uint, 0--4 B, 60 Seconds */ |
#define | COAP_OPTION_URI_QUERY 15 /* C, String, 1-255 B, (none) */ |
#define | COAP_OPTION_ACCEPT 17 /* C, uint, 0-2 B, (none) */ |
#define | COAP_OPTION_LOCATION_QUERY 20 /* E, String, 0-255 B, (none) */ |
#define | COAP_OPTION_SIZE2 28 /* E, uint, 0-4 B, (none) */ |
#define | COAP_OPTION_PROXY_URI 35 /* C, String, 1-1034 B, (none) */ |
#define | COAP_OPTION_PROXY_SCHEME 39 /* C, String, 1-255 B, (none) */ |
#define | COAP_OPTION_SIZE1 60 /* E, uint, 0-4 B, (none) */ |
#define | COAP_OPTION_OBSERVE 6 /* E, empty/uint, 0 B/0-3 B, (none) */ |
#define | COAP_OPTION_SUBSCRIPTION COAP_OPTION_OBSERVE |
#define | COAP_OPTION_BLOCK2 23 /* C, uint, 0--3 B, (none) */ |
#define | COAP_OPTION_BLOCK1 27 /* C, uint, 0--3 B, (none) */ |
#define | COAP_OPTION_NORESPONSE 258 /* N, uint, 0--1 B, 0 */ |
#define | COAP_MAX_OPT 65535 |
the highest option number we know More... | |
#define | COAP_RESPONSE_CODE(N) (((N)/100 << 5) | (N)%100) |
#define | COAP_RESPONSE_CLASS(C) (((C) >> 5) & 0xFF) |
#define | COAP_ERROR_PHRASE_LENGTH 32 |
maximum length of error phrase More... | |
#define | COAP_RESPONSE_200 COAP_RESPONSE_CODE(200) /* 2.00 OK */ |
#define | COAP_RESPONSE_201 COAP_RESPONSE_CODE(201) /* 2.01 Created */ |
#define | COAP_RESPONSE_304 COAP_RESPONSE_CODE(203) /* 2.03 Valid */ |
#define | COAP_RESPONSE_400 COAP_RESPONSE_CODE(400) /* 4.00 Bad Request */ |
#define | COAP_RESPONSE_404 COAP_RESPONSE_CODE(404) /* 4.04 Not Found */ |
#define | COAP_RESPONSE_405 COAP_RESPONSE_CODE(405) /* 4.05 Method Not Allowed */ |
#define | COAP_RESPONSE_415 COAP_RESPONSE_CODE(415) /* 4.15 Unsupported Media Type */ |
#define | COAP_RESPONSE_500 COAP_RESPONSE_CODE(500) /* 5.00 Internal Server Error */ |
#define | COAP_RESPONSE_501 COAP_RESPONSE_CODE(501) /* 5.01 Not Implemented */ |
#define | COAP_RESPONSE_503 COAP_RESPONSE_CODE(503) /* 5.03 Service Unavailable */ |
#define | COAP_RESPONSE_504 COAP_RESPONSE_CODE(504) /* 5.04 Gateway Timeout */ |
#define | COAP_RESPONSE_X_242 COAP_RESPONSE_CODE(402) /* Critical Option not supported */ |
#define | COAP_SIGNALING_CODE(N) (((N)/100 << 5) | (N)%100) |
#define | COAP_SIGNALING_CSM COAP_SIGNALING_CODE(701) |
#define | COAP_SIGNALING_PING COAP_SIGNALING_CODE(702) |
#define | COAP_SIGNALING_PONG COAP_SIGNALING_CODE(703) |
#define | COAP_SIGNALING_RELEASE COAP_SIGNALING_CODE(704) |
#define | COAP_SIGNALING_ABORT COAP_SIGNALING_CODE(705) |
#define | COAP_SIGNALING_OPTION_MAX_MESSAGE_SIZE 2 |
#define | COAP_SIGNALING_OPTION_BLOCK_WISE_TRANSFER 4 |
#define | COAP_SIGNALING_OPTION_CUSTODY 2 |
#define | COAP_SIGNALING_OPTION_ALTERNATIVE_ADDRESS 2 |
#define | COAP_SIGNALING_OPTION_HOLD_OFF 4 |
#define | COAP_SIGNALING_OPTION_BAD_CSM_OPTION 2 |
#define | COAP_MEDIATYPE_TEXT_PLAIN 0 /* text/plain (UTF-8) */ |
#define | COAP_MEDIATYPE_APPLICATION_LINK_FORMAT 40 /* application/link-format */ |
#define | COAP_MEDIATYPE_APPLICATION_XML 41 /* application/xml */ |
#define | COAP_MEDIATYPE_APPLICATION_OCTET_STREAM 42 /* application/octet-stream */ |
#define | COAP_MEDIATYPE_APPLICATION_RDF_XML 43 /* application/rdf+xml */ |
#define | COAP_MEDIATYPE_APPLICATION_EXI 47 /* application/exi */ |
#define | COAP_MEDIATYPE_APPLICATION_JSON 50 /* application/json */ |
#define | COAP_MEDIATYPE_APPLICATION_CBOR 60 /* application/cbor */ |
#define | COAP_MEDIATYPE_APPLICATION_COSE_SIGN 98 /* application/cose; cose-type="cose-sign" */ |
#define | COAP_MEDIATYPE_APPLICATION_COSE_SIGN1 18 /* application/cose; cose-type="cose-sign1" */ |
#define | COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT 96 /* application/cose; cose-type="cose-encrypt" */ |
#define | COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT0 16 /* application/cose; cose-type="cose-encrypt0" */ |
#define | COAP_MEDIATYPE_APPLICATION_COSE_MAC 97 /* application/cose; cose-type="cose-mac" */ |
#define | COAP_MEDIATYPE_APPLICATION_COSE_MAC0 17 /* application/cose; cose-type="cose-mac0" */ |
#define | COAP_MEDIATYPE_APPLICATION_COSE_KEY 101 /* application/cose-key */ |
#define | COAP_MEDIATYPE_APPLICATION_COSE_KEY_SET 102 /* application/cose-key-set */ |
#define | COAP_MEDIATYPE_APPLICATION_SENML_JSON 110 /* application/senml+json */ |
#define | COAP_MEDIATYPE_APPLICATION_SENSML_JSON 111 /* application/sensml+json */ |
#define | COAP_MEDIATYPE_APPLICATION_SENML_CBOR 112 /* application/senml+cbor */ |
#define | COAP_MEDIATYPE_APPLICATION_SENSML_CBOR 113 /* application/sensml+cbor */ |
#define | COAP_MEDIATYPE_APPLICATION_SENML_EXI 114 /* application/senml-exi */ |
#define | COAP_MEDIATYPE_APPLICATION_SENSML_EXI 115 /* application/sensml-exi */ |
#define | COAP_MEDIATYPE_APPLICATION_SENML_XML 310 /* application/senml+xml */ |
#define | COAP_MEDIATYPE_APPLICATION_SENSML_XML 311 /* application/sensml+xml */ |
#define | COAP_MEDIATYPE_ANY 0xff /* any media type */ |
#define | COAP_INVALID_TID -1 |
Indicates an invalid transaction id. More... | |
#define | COAP_DROPPED_RESPONSE -2 |
Indicates that a response is suppressed. More... | |
#define | COAP_PDU_DELAYED -3 |
#define | COAP_OPT_LONG |
#define | COAP_OPT_END 0xF0 /* end marker */ |
#define | COAP_PAYLOAD_START 0xFF /* payload marker */ |
#define | COAP_OPTION_KEY(option) (option).key |
#define | COAP_OPTION_LENGTH(option) (option).length |
#define | COAP_OPTION_DATA(option) ((unsigned char *)&(option) + sizeof(coap_option)) |
#define | COAP_PDU_IS_EMPTY(pdu) ((pdu)->code == 0) |
#define | COAP_PDU_IS_REQUEST(pdu) (!COAP_PDU_IS_EMPTY(pdu) && (pdu)->code < 32) |
#define | COAP_PDU_IS_RESPONSE(pdu) ((pdu)->code >= 64 && (pdu)->code < 224) |
#define | COAP_PDU_IS_SIGNALING(pdu) ((pdu)->code >= 224) |
#define | COAP_PDU_MAX_UDP_HEADER_SIZE 4 |
#define | COAP_PDU_MAX_TCP_HEADER_SIZE 6 |
#define | COAP_PROTO_NONE 0 |
coap_proto_t values More... | |
#define | COAP_PROTO_UDP 1 |
#define | COAP_PROTO_DTLS 2 |
#define | COAP_PROTO_TCP 3 |
#define | COAP_PROTO_TLS 4 |
Typedefs | |
typedef int | coap_tid_t |
coap_tid_t is used to store CoAP transaction id, i.e. More... | |
typedef struct coap_pdu_t | coap_pdu_t |
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload marker (0xff), then the payload if stored inline. More... | |
typedef uint8_t | coap_proto_t |
Functions | |
const char * | coap_response_phrase (unsigned char code) |
Returns a human-readable response phrase for the specified CoAP response code . 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... | |
int | coap_pdu_resize (coap_pdu_t *pdu, size_t new_size) |
Dynamically grows the size of pdu to new_size . More... | |
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_new_pdu (const struct coap_session_t *session) |
Creates a new CoAP PDU. More... | |
void | coap_delete_pdu (coap_pdu_t *) |
Dispose of an CoAP PDU and frees associated storage. 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... | |
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... | |
size_t | coap_pdu_encode_header (coap_pdu_t *pdu, coap_proto_t proto) |
Compose the protocol specific header for the specified PDU. More... | |
Pre-defined constants that reflect defaults for CoAP.
Definition in file pdu.h.
#define COAP_DEFAULT_MAX_AGE 60 /* default maximum object lifetime in seconds */ |
#define COAP_DEFAULT_SCHEME "coap" /* the default scheme for CoAP URIs */ |
#define COAP_DEFAULT_URI_WELLKNOWN ".well-known/core" |
#define COAP_DROPPED_RESPONSE -2 |
#define COAP_ERROR_PHRASE_LENGTH 32 |
#define COAP_INVALID_TID -1 |
#define COAP_MAX_MESSAGE_SIZE_TCP0 (COAP_MESSAGE_SIZE_OFFSET_TCP8-1) /* 12 */ |
#define COAP_MAX_MESSAGE_SIZE_TCP16 (COAP_MESSAGE_SIZE_OFFSET_TCP32-1) /* 65804 */ |
#define COAP_MAX_MESSAGE_SIZE_TCP32 (COAP_MESSAGE_SIZE_OFFSET_TCP32+0xFFFFFFFF) |
#define COAP_MAX_MESSAGE_SIZE_TCP8 (COAP_MESSAGE_SIZE_OFFSET_TCP16-1) /* 268 */ |
#define COAP_MEDIATYPE_APPLICATION_CBOR 60 /* application/cbor */ |
#define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT 96 /* application/cose; cose-type="cose-encrypt" */ |
#define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT0 16 /* application/cose; cose-type="cose-encrypt0" */ |
#define COAP_MEDIATYPE_APPLICATION_COSE_KEY 101 /* application/cose-key */ |
#define COAP_MEDIATYPE_APPLICATION_COSE_KEY_SET 102 /* application/cose-key-set */ |
#define COAP_MEDIATYPE_APPLICATION_COSE_MAC 97 /* application/cose; cose-type="cose-mac" */ |
#define COAP_MEDIATYPE_APPLICATION_COSE_MAC0 17 /* application/cose; cose-type="cose-mac0" */ |
#define COAP_MEDIATYPE_APPLICATION_COSE_SIGN 98 /* application/cose; cose-type="cose-sign" */ |
#define COAP_MEDIATYPE_APPLICATION_COSE_SIGN1 18 /* application/cose; cose-type="cose-sign1" */ |
#define COAP_MEDIATYPE_APPLICATION_EXI 47 /* application/exi */ |
#define COAP_MEDIATYPE_APPLICATION_JSON 50 /* application/json */ |
#define COAP_MEDIATYPE_APPLICATION_LINK_FORMAT 40 /* application/link-format */ |
#define COAP_MEDIATYPE_APPLICATION_OCTET_STREAM 42 /* application/octet-stream */ |
#define COAP_MEDIATYPE_APPLICATION_RDF_XML 43 /* application/rdf+xml */ |
#define COAP_MEDIATYPE_APPLICATION_SENML_CBOR 112 /* application/senml+cbor */ |
#define COAP_MEDIATYPE_APPLICATION_SENML_EXI 114 /* application/senml-exi */ |
#define COAP_MEDIATYPE_APPLICATION_SENML_JSON 110 /* application/senml+json */ |
#define COAP_MEDIATYPE_APPLICATION_SENML_XML 310 /* application/senml+xml */ |
#define COAP_MEDIATYPE_APPLICATION_SENSML_CBOR 113 /* application/sensml+cbor */ |
#define COAP_MEDIATYPE_APPLICATION_SENSML_EXI 115 /* application/sensml-exi */ |
#define COAP_MEDIATYPE_APPLICATION_SENSML_JSON 111 /* application/sensml+json */ |
#define COAP_MEDIATYPE_APPLICATION_SENSML_XML 311 /* application/sensml+xml */ |
#define COAP_MEDIATYPE_APPLICATION_XML 41 /* application/xml */ |
#define COAP_MESSAGE_ACK 2 /* used to acknowledge confirmable messages */ |
#define COAP_MESSAGE_CON 0 /* confirmable message (requires ACK/RST) */ |
#define COAP_MESSAGE_NON 1 /* non-confirmable message (one-shot message) */ |
#define COAP_MESSAGE_RST 3 /* indicates error in received messages */ |
#define COAP_OPT_LONG |
#define COAP_OPTION_CONTENT_FORMAT 12 /* E, uint, 0-2 B, (none) */ |
#define COAP_OPTION_CONTENT_TYPE COAP_OPTION_CONTENT_FORMAT |
#define COAP_OPTION_DATA | ( | option | ) | ((unsigned char *)&(option) + sizeof(coap_option)) |
#define COAP_OPTION_LOCATION_PATH 8 /* E, String, 0-255 B, - */ |
#define COAP_OPTION_LOCATION_QUERY 20 /* E, String, 0-255 B, (none) */ |
#define COAP_OPTION_MAXAGE 14 /* E, uint, 0--4 B, 60 Seconds */ |
#define COAP_OPTION_OBSERVE 6 /* E, empty/uint, 0 B/0-3 B, (none) */ |
#define COAP_OPTION_PROXY_SCHEME 39 /* C, String, 1-255 B, (none) */ |
#define COAP_OPTION_PROXY_URI 35 /* C, String, 1-1034 B, (none) */ |
#define COAP_OPTION_SUBSCRIPTION COAP_OPTION_OBSERVE |
#define COAP_OPTION_URI_HOST 3 /* C, String, 1-255 B, destination address */ |
#define COAP_OPTION_URI_PATH 11 /* C, String, 0-255 B, (none) */ |
#define COAP_OPTION_URI_PORT 7 /* C, uint, 0-2 B, destination port */ |
#define COAP_OPTION_URI_QUERY 15 /* C, String, 1-255 B, (none) */ |
#define COAP_PDU_IS_REQUEST | ( | pdu | ) | (!COAP_PDU_IS_EMPTY(pdu) && (pdu)->code < 32) |
#define COAP_PDU_IS_RESPONSE | ( | pdu | ) | ((pdu)->code >= 64 && (pdu)->code < 224) |
#define COAP_RESPONSE_200 COAP_RESPONSE_CODE(200) /* 2.00 OK */ |
#define COAP_RESPONSE_201 COAP_RESPONSE_CODE(201) /* 2.01 Created */ |
#define COAP_RESPONSE_304 COAP_RESPONSE_CODE(203) /* 2.03 Valid */ |
#define COAP_RESPONSE_400 COAP_RESPONSE_CODE(400) /* 4.00 Bad Request */ |
#define COAP_RESPONSE_404 COAP_RESPONSE_CODE(404) /* 4.04 Not Found */ |
#define COAP_RESPONSE_405 COAP_RESPONSE_CODE(405) /* 4.05 Method Not Allowed */ |
#define COAP_RESPONSE_415 COAP_RESPONSE_CODE(415) /* 4.15 Unsupported Media Type */ |
#define COAP_RESPONSE_500 COAP_RESPONSE_CODE(500) /* 5.00 Internal Server Error */ |
#define COAP_RESPONSE_501 COAP_RESPONSE_CODE(501) /* 5.01 Not Implemented */ |
#define COAP_RESPONSE_503 COAP_RESPONSE_CODE(503) /* 5.03 Service Unavailable */ |
#define COAP_RESPONSE_504 COAP_RESPONSE_CODE(504) /* 5.04 Gateway Timeout */ |
#define COAP_RESPONSE_X_242 COAP_RESPONSE_CODE(402) /* Critical Option not supported */ |
#define COAP_SIGNALING_ABORT COAP_SIGNALING_CODE(705) |
#define COAP_SIGNALING_CSM COAP_SIGNALING_CODE(701) |
#define COAP_SIGNALING_PING COAP_SIGNALING_CODE(702) |
#define COAP_SIGNALING_PONG COAP_SIGNALING_CODE(703) |
#define COAP_SIGNALING_RELEASE COAP_SIGNALING_CODE(704) |
#define COAPS_DEFAULT_PORT 5684 /* CoAP default UDP/TCP port for secure transmission */ |
typedef struct coap_pdu_t coap_pdu_t |
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload marker (0xff), then the payload if stored inline.
Memory layout is: <—header—>|<—token—><—options—>0xff<—payload—> header is addressed with a negative offset to token, its maximum size is max_hdr_size. options starts at token + token_length payload starts at data, its length is used_size - (data - token)
typedef uint8_t coap_proto_t |
typedef int coap_tid_t |
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 | ) |
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.