9 #include "coap_config.h" 19 #elif HAVE_SYS_UNISTD_H 20 #include <sys/unistd.h> 22 #include <sys/types.h> 23 #ifdef HAVE_SYS_SOCKET_H 24 #include <sys/socket.h> 26 #ifdef HAVE_NETINET_IN_H 27 #include <netinet/in.h> 29 #ifdef HAVE_ARPA_INET_H 30 #include <arpa/inet.h> 34 #include <lwip/pbuf.h> 36 #include <lwip/timers.h> 57 #ifndef COAP_DEFAULT_ACK_TIMEOUT 62 #define COAP_DEFAULT_ACK_TIMEOUT 2 65 #ifndef COAP_DEFAULT_ACK_RANDOM_FACTOR 70 #define COAP_DEFAULT_ACK_RANDOM_FACTOR 1.5 73 #ifndef COAP_DEFAULT_MAX_RETRANSMIT 77 #define COAP_DEFAULT_MAX_RETRANSMIT 4 80 #ifndef COAP_DEFAULT_NSTART 85 #define COAP_DEFAULT_NSTART 1 103 #error FRAC_BITS must be less or equal 8 107 #define Q(frac,fval) ((unsigned short)(((1 << (frac)) * (fval)))) 110 #define ACK_RANDOM_FACTOR \ 111 Q(FRAC_BITS, COAP_DEFAULT_ACK_RANDOM_FACTOR) 114 #define ACK_TIMEOUT Q(FRAC_BITS, COAP_DEFAULT_ACK_TIMEOUT) 116 #if defined(WITH_POSIX) 132 #include <lwip/memp.h> 134 static void coap_retransmittimer_execute(
void *arg);
144 memp_free(MEMP_COAP_NODE, node);
150 # define DEBUG DEBUG_PRINT 154 #include "net/ip/uip-debug.h" 158 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) 159 #define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLIPH_LEN]) 161 void coap_resources_init();
163 unsigned char initialized = 0;
166 PROCESS(coap_retransmit_process,
"message retransmit process");
181 unsigned int result = 0;
219 if ( !queue || !node )
230 if (node->
t < q->
t) {
242 }
while (q && q->
t <= node->
t);
285 memset(node, 0,
sizeof(*node));
313 #ifdef COAP_DEFAULT_WKC_HASHKEY 315 #define is_wkc(Key) \ 316 (memcmp((Key), COAP_DEFAULT_WKC_HASHKEY, sizeof(coap_key_t)) == 0) 323 static unsigned char _initialized = 0;
328 return memcmp(k, wkc,
sizeof(
coap_key_t)) == 0;
357 prng_init((
unsigned long)listen_addr ^ clock_offset);
369 coap_resources_init();
372 c = &the_coap_context;
393 #if defined(WITH_POSIX) || defined(WITH_CONTIKI) 399 process_start(&coap_retransmit_process, (
char *)c);
401 PROCESS_CONTEXT_BEGIN(&coap_retransmit_process);
402 #ifndef WITHOUT_OBSERVE 406 etimer_set(&the_coap_context.retransmit_timer, 0xFFFF);
407 PROCESS_CONTEXT_END(&coap_retransmit_process);
427 coap_retransmittimer_restart(context);
460 if (opt_iter.
type & 0x01) {
462 switch (opt_iter.
type) {
477 debug(
"unknown critical option %d\n", opt_iter.
type);
504 switch (peer->
addr.
sa.sa_family) {
507 sizeof(peer->
addr.
sin.sin_port), h);
509 sizeof(peer->
addr.
sin.sin_addr), h);
513 sizeof(peer->
addr.
sin6.sin6_port), h);
515 sizeof(peer->
addr.
sin6.sin6_addr), h);
521 #if defined(WITH_LWIP) || defined(WITH_CONTIKI) 523 coap_hash((
const unsigned char *)&peer->port,
sizeof(peer->port), h);
527 coap_hash((
const unsigned char *)&pdu->
hdr->
id,
sizeof(
unsigned short), h);
529 *
id = (((h[0] << 8) | h[1]) ^ ((h[2] << 8) | h[3])) & INT_MAX;
544 result =
coap_send(context, local_interface, dst, response);
551 #if defined(WITH_POSIX) || defined(WITH_CONTIKI) 557 ssize_t bytes_written;
560 if ( !context || !dst || !pdu )
572 bytes_written = context->
network_send(context, local_interface, dst,
575 if (bytes_written >= 0) {
592 if ( !context || !dst || !pdu )
601 pbuf_realloc(pdu->pbuf, pdu->
length);
605 udp_sendto(context->
endpoint->pcb, pdu->pbuf,
606 &dst->
addr, dst->port);
635 result =
coap_send(context, local_interface, dst, response);
647 unsigned char type) {
654 result =
coap_send(context, local_interface, dst, response);
672 static inline unsigned int 677 #define FP1 Q(FRAC_BITS, 1) 680 #define SHR_FP(val,frac) (((val) + (1 << ((frac) - 1))) >> (frac)) 709 debug(
"coap_send_confirmed: insufficient memory\n");
715 debug(
"coap_send_confirmed: error sending pdu\n");
720 prng((
unsigned char *)&r,
sizeof(r));
750 coap_retransmittimer_restart(context);
761 PROCESS_CONTEXT_BEGIN(&coap_retransmit_process);
762 etimer_set(&context->retransmit_timer, nextpdu->
t);
763 PROCESS_CONTEXT_END(&coap_retransmit_process);
772 if (!context || !node)
782 coap_retransmittimer_restart(context);
785 debug(
"** retransmission #%d of transaction %d\n",
796 debug(
"** removed transaction %d\n", ntohs(node->
id));
799 #ifndef WITHOUT_OBSERVE 803 str token = { 0, NULL };
823 ssize_t bytes_read = -1;
832 if ( bytes_read < 0 ) {
833 warn(
"coap_read: recvfrom");
854 enum result_t { RESULT_OK, RESULT_ERR_EARLY, RESULT_ERR };
855 int result = RESULT_ERR_EARLY;
860 debug(
"coap_handle_message: discarded invalid frame\n" );
866 debug(
"coap_handle_message: unknown protocol version %d\n", (*msg >> 6) & 0x03);
879 node->
pdu = coap_pdu_from_pbuf(coap_packet_extract_pbuf(packet));
888 warn(
"discard malformed PDU\n");
902 #ifndef INET6_ADDRSTRLEN 903 #define INET6_ADDRSTRLEN 40 933 if ( !queue || !*queue)
938 if (
id == (*queue)->id ) {
940 *queue = (*queue)->
next;
942 (*queue)->
t += (*node)->t;
944 (*node)->next = NULL;
946 debug(
"*** removed transaction %u\n",
id);
955 }
while ( q &&
id != q->
id );
965 debug(
"*** removed transaction %u\n",
id);
975 const unsigned char *b,
size_t blen) {
976 return alen == blen && (alen == 0 || memcmp(a, b, alen) == 0);
981 const unsigned char *token,
size_t token_length) {
993 debug(
"**** removed transaction %d\n", ntohs(q->
pdu->
hdr->
id));
1009 debug(
"**** removed transaction %d\n", ntohs(q->
pdu->
hdr->
id));
1021 while (queue && queue->
id !=
id)
1022 queue = queue->
next;
1035 unsigned short opt_type = 0;
1042 size += strlen(phrase) + 1;
1064 unsigned short delta = opt_iter.
type - opt_type;
1068 }
else if (delta < 269) {
1078 switch (*option & 0x0f) {
1089 opt_type = opt_iter.
type;
1098 debug(
"cannot add token to error response\n");
1110 #if COAP_ERROR_PHRASE_LENGTH > 0 1113 coap_add_data(response, strlen(phrase), (
unsigned char *)phrase);
1124 static inline size_t 1126 unsigned char buf[1];
1131 warn(
"cannot determine length of /.well-known/core\n");
1135 debug(
"get_wkc_len: coap_print_wellknown() returned %zu\n", len);
1140 #define SZX_TO_BYTES(SZX) ((size_t)(1 << ((SZX) + 4))) 1146 size_t len, wkc_len;
1147 unsigned char buf[2];
1149 int need_block2 = 0;
1160 debug(
"coap_wellknown_response: cannot create PDU\n");
1165 debug(
"coap_wellknown_response: cannot add token\n");
1174 debug(
"coap_wellknown_response: undefined resource\n");
1183 debug(
"create block\n");
1184 offset = block.
num << (block.
szx + 4);
1185 if (block.
szx > 6) {
1190 block.
num = offset >> (block.
szx + 4);
1201 debug(
"coap_wellknown_response: insufficient storage space\n");
1214 if (!need_block2 && (resp->
max_size - (
size_t)resp->
length < wkc_len)) {
1222 if (block.
szx == 0) {
1223 debug(
"coap_wellknown_response: message to small even for szx == 0\n");
1236 debug(
"coap_wellknown_response: cannot add Block2 option\n");
1252 debug(
"coap_print_wellknown failed\n");
1278 #ifndef WITHOUT_OBSERVE 1279 str token = { 0, NULL };
1280 int num_cancelled = 0;
1293 return num_cancelled;
1367 #define WANT_WKC(Pdu,Key) \ 1368 (((Pdu)->hdr->code == COAP_REQUEST_GET) && is_wkc(Key)) 1399 debug(
"method not allowed for .well-known/core\n");
1405 debug(
"request for unknown resource 0x%02x%02x%02x%02x, return 4.04\n",
1406 key[0], key[1], key[2], key[3]);
1416 warn(
"cannot send response for transaction %u\n", node->
id);
1430 debug(
"call custom handler for resource 0x%02x%02x%02x%02x\n",
1431 key[0], key[1], key[2], key[3]);
1471 node->
pdu, &token, response);
1485 && (response->
hdr->
code == 0)) {
1493 (response->
hdr->
type != COAP_MESSAGE_NON ||
1499 debug(
"cannot send response for message %d\n", node->
pdu->
hdr->
id);
1506 warn(
"cannot generate response\r\n");
1512 debug(
"have wellknown response %p\n", (
void *)response);
1520 debug(
"cannot send response for transaction %u\n", node->
id);
1527 assert(response == NULL);
1548 rcvd->
pdu, rcvd->
id);
1604 #ifndef WITH_CONTIKI 1631 warn(
"coap_dispatch: cannot create error response\n");
1635 warn(
"coap_dispatch: error sending response\n");
1653 debug(
"dropped message with invalid code (%d.%02d)\n",
1672 return !context || (context->
sendqueue == NULL);
1680 PROCESS_THREAD(coap_retransmit_process, ev, data)
1687 debug(
"Started retransmit process\r\n");
1691 if (ev == PROCESS_EVENT_TIMER) {
1692 if (etimer_expired(&the_coap_context.retransmit_timer)) {
1697 while (nextpdu && nextpdu->
t <= now) {
1703 etimer_set(&the_coap_context.retransmit_timer,
1704 nextpdu ? nextpdu->
t - now : 0xFFFF);
1706 #ifndef WITHOUT_OBSERVE 1707 if (etimer_expired(&the_coap_context.notify_timer)) {
1709 etimer_reset(&the_coap_context.notify_timer);
1735 static void coap_retransmittimer_execute(
void *arg)
1742 ctx->timer_configured = 0;
1749 while (nextinqueue != NULL)
1751 if (nextinqueue->
t > elapsed) {
1752 nextinqueue->
t -= elapsed;
1755 elapsed -= nextinqueue->
t;
1763 coap_retransmittimer_restart(ctx);
1770 if (ctx->timer_configured)
1772 printf(
"clearing\n");
1773 sys_untimeout(coap_retransmittimer_execute, (
void*)ctx);
1774 ctx->timer_configured = 0;
1797 printf(
"scheduling for %d ticks\n", delay);
1798 sys_timeout(delay, coap_retransmittimer_execute, (
void*)ctx);
1799 ctx->timer_configured = 1;
int coap_get_block(coap_pdu_t *pdu, unsigned short type, coap_block_t *block)
Initializes block from pdu.
#define COAP_OPTION_IF_MATCH
coap_tid_t coap_send_confirmed(coap_context_t *context, const coap_endpoint_t *local_interface, const coap_address_t *dst, coap_pdu_t *pdu)
Sends a confirmed CoAP message to given destination.
int coap_handle_message(coap_context_t *ctx, coap_packet_t *packet)
Parses and interprets a CoAP message with context ctx.
void coap_check_notify(coap_context_t *context)
Checks for all known resources, if they are dirty and notifies subscribed observers.
int coap_write_block_opt(coap_block_t *block, unsigned short type, coap_pdu_t *pdu, size_t data_length)
Writes a block option of type type to message pdu.
unsigned char coap_key_t[4]
int coap_option_filter_set(coap_opt_filter_t filter, unsigned short type)
Sets the corresponding entry for type in filter.
ssize_t coap_network_send(struct coap_context_t *context UNUSED_PARAM, const coap_endpoint_t *local_interface, const coap_address_t *dst, unsigned char *data, size_t datalen)
int coap_delete_observer(coap_resource_t *resource, const coap_address_t *observer, const str *token)
Removes any subscription for observer from resource and releases the allocated storage.
#define COAP_RESPONSE_CODE(N)
#define COAP_DEFAULT_URI_WELLKNOWN
well-known resources URI
#define COAP_OPTION_PROXY_URI
#define COAP_OPTION_CONTENT_FORMAT
coap_address_t addr
local interface address
static coap_queue_t * coap_malloc_node(void)
unsigned char retransmit_cnt
retransmission counter, will be removed when zero
ssize_t(* network_read)(coap_endpoint_t *ep, coap_packet_t **packet)
void coap_packet_get_memmapped(coap_packet_t *packet, unsigned char **address, size_t *length)
Given a packet, set msg and msg_len to an address and length of the packet's data in memory...
coap_endpoint_t * endpoint
the endpoint used for listening
void coap_show_pdu(const coap_pdu_t *pdu)
#define COAP_OPTION_NORESPONSE
unsigned char * coap_opt_value(coap_opt_t *opt)
Returns a pointer to the value of the given option.
multi-purpose address abstraction
#define COAP_PRINT_OUTPUT_LENGTH(v)
State management for asynchronous messages.
#define SHR_FP(val, frac)
int coap_tid_t
coap_tid_t is used to store CoAP transaction id, i.e.
void coap_free_endpoint(coap_endpoint_t *ep)
unsigned short length
PDU length (including header, options, data)
#define COAP_OPT_ALL
Pre-defined filter that includes all options.
int coap_add_token(coap_pdu_t *pdu, size_t len, const unsigned char *data)
Adds token of length len to pdu.
coap_endpoint_t local_if
the local address interface
#define COAP_OPTION_OBSERVE
void coap_clock_init(void)
Initializes the internal clock.
coap_endpoint_t * coap_new_endpoint(const coap_address_t *addr, int flags)
#define COAP_OPTION_BLOCK1
int coap_pdu_parse(unsigned char *data, size_t length, coap_pdu_t *pdu)
Parses data into the CoAP PDU structure given in result.
coap_address_t remote
remote address
coap_pdu_t * coap_wellknown_response(coap_context_t *context, coap_pdu_t *request)
Creates a new response for given request with the contents of .well-known/core.
#define prng_init(Value)
Called to set the PRNG seed.
coap_opt_t * coap_option_next(coap_opt_iterator_t *oi)
Updates the iterator oi to point to the next option.
#define COAP_OPTION_CONTENT_TYPE
Helpers for handling options in CoAP PDUs.
coap_hdr_t * hdr
Address of the first byte of the CoAP message.
coap_context_t * coap_new_context(const coap_address_t *listen_addr)
Creates a new coap_context_t object that will hold the CoAP stack status.
#define WANT_WKC(Pdu, Key)
unsigned short message_id
The last message id that was used is stored in this field.
unsigned long coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
coap_queue_t * coap_peek_next(coap_context_t *context)
Returns the next pdu to send without removing from sendqeue.
void coap_transaction_id(const coap_address_t *peer, const coap_pdu_t *pdu, coap_tid_t *id)
Calculates a unique transaction id from given arguments peer and pdu.
#define COAP_OPTION_PROXY_SCHEME
Abstraction of virtual endpoint that can be attached to coap_context_t.
#define COAP_RESOURCE_CHECK_TIME
The interval in seconds to check if resources have changed.
#define COAP_SET_STR(st, l, v)
void coap_hash_request_uri(const coap_pdu_t *request, coap_key_t key)
Calculates the hash key for the resource requested by the Uri-Options of request. ...
#define SZX_TO_BYTES(SZX)
coap_queue_t * coap_find_transaction(coap_queue_t *queue, coap_tid_t id)
Retrieves transaction from the queue.
coap_tid_t id
unique transaction id
static size_t get_wkc_len(coap_context_t *context, coap_opt_t *query_filter)
Quick hack to determine the size of the resource description for .well-known/core.
coap_tick_t sendqueue_basetime
The time stamp in the first element of the sendqeue is relative to sendqueue_basetime.
coap_pdu_t * coap_new_error_response(coap_pdu_t *request, unsigned char code, coap_opt_filter_t opts)
Creates a new ACK PDU with specified error code.
coap_pdu_t * pdu
the CoAP PDU to send
coap_tick_t t
when to send PDU for the next time
#define COAP_DEFAULT_VERSION
#define COAP_TICKS_PER_SECOND
Use ms resolution on POSIX systems.
#define FRAC_BITS
The number of bits for the fractional part of ACK_TIMEOUT and ACK_RANDOM_FACTOR.
#define ACK_TIMEOUT
creates a Qx.FRAC_BITS from COAP_DEFAULT_ACK_TIMEOUT
#define COAP_INVALID_TID
Indicates an invalid transaction id.
long coap_tick_diff_t
This data type is used to represent the difference between two clock_tick_t values.
void coap_cancel_all_messages(coap_context_t *context, const coap_address_t *dst, const unsigned char *token, size_t token_length)
Cancels all outstanding messages for peer dst that have the specified token.
void coap_packet_populate_endpoint(coap_packet_t *packet, coap_endpoint_t *target)
Populate the coap_endpoint_t *target from the incoming packet's destination data. ...
#define RESOURCES_ITER(r, tmp)
coap_tid_t coap_send_ack(coap_context_t *context, const coap_endpoint_t *local_interface, const coap_address_t *dst, coap_pdu_t *request)
Sends an ACK message with code 0 for the specified request to dst.
Header structure for CoAP PDUs.
int coap_insert_node(coap_queue_t **queue, coap_queue_t *node)
Adds node to given queue, ordered by node->t.
int coap_can_exit(coap_context_t *context)
Returns 1 if there are no messages to send or to dispatch in the context's queues.
coap_opt_iterator_t * coap_option_iterator_init(coap_pdu_t *pdu, coap_opt_iterator_t *oi, const coap_opt_filter_t filter)
Initializes the given option iterator oi to point to the beginning of the pdu's option list...
coap_tid_t coap_send(coap_context_t *context, const coap_endpoint_t *local_interface, const coap_address_t *dst, coap_pdu_t *pdu)
Sends a non-confirmed CoAP message to given destination.
void coap_free_packet(coap_packet_t *packet)
Releases the storage allocated for packet.
#define COAP_MAX_BLOCK_SZX
The largest value for the SZX component in a Block option.
coap_response_handler_t response_handler
#define COAP_OPTION_URI_PORT
unsigned int observable
can be observed
ssize_t(* network_send)(struct coap_context_t *context, const coap_endpoint_t *local_interface, const coap_address_t *dst, unsigned char *data, size_t datalen)
static unsigned int calc_timeout(unsigned char r)
Calculates the initial timeout based on the global CoAP transmission parameters ACK_TIMEOUT, ACK_RANDOM_FACTOR, and COAP_TICKS_PER_SECOND.
unsigned int coap_encode_var_bytes(unsigned char *buf, unsigned int val)
Encodes multiple-length byte sequences.
size_t max_size
allocated storage for options and data
ssize_t coap_network_read(coap_endpoint_t *ep, coap_packet_t **packet)
Function interface for reading data.
struct coap_queue_t * next
void coap_ticks(coap_tick_t *t)
Sets t to the internal time with COAP_TICKS_PER_SECOND resolution.
#define COAP_RESPONSE_CLASS(C)
#define COAP_OPTION_IF_NONE_MATCH
#define COAP_OBSERVE_CANCEL
The value COAP_OBSERVE_CANCEL in a GET request indicates that the observe relationship for (sender ad...
Iterator to run through PDU options.
#define COAP_MEDIATYPE_APPLICATION_LINK_FORMAT
size_t coap_add_option(coap_pdu_t *pdu, unsigned short type, unsigned int len, const unsigned char *data)
de-duplicate code with coap_add_option_later
unsigned int timeout
the randomized timeout value
static void handle_request(coap_context_t *context, coap_queue_t *node)
#define coap_mcast_interface(Local)
Generic resource handling.
#define COAP_MAX_PDU_SIZE
int coap_add_data(coap_pdu_t *pdu, unsigned int len, const unsigned char *data)
Adds given data to the pdu that is passed as first parameter.
coap_subscription_t * coap_add_observer(coap_resource_t *resource, const coap_endpoint_t *local_interface, const coap_address_t *observer, const str *token)
Adds the specified peer as observer for resource.
#define coap_hash(String, Length, Result)
unsigned short type
decoded option type
uint16_t coap_opt_filter_t[COAP_OPT_FILTER_SIZE]
Fixed-size vector we use for option filtering.
int coap_address_equals(const coap_address_t *a, const coap_address_t *b)
Compares given address objects a and b.
#define COAP_OPTION_BLOCK2
void coap_delete_pdu(coap_pdu_t *pdu)
static void coap_address_init(coap_address_t *addr)
Resets the given coap_address_t object addr to its default values.
void coap_delete_all(coap_queue_t *queue)
Removes all items from given queue and frees the allocated storage.
coap_pdu_t * coap_pdu_init(unsigned char type, unsigned char code, unsigned short id, size_t size)
Creates a new CoAP PDU of given size (must be large enough to hold the basic CoAP message header (coa...
coap_tid_t coap_send_message_type(coap_context_t *context, const coap_endpoint_t *local_interface, const coap_address_t *dst, coap_pdu_t *request, unsigned char type)
Helper funktion to create and send a message with type (usually ACK or RST).
Structure of Block options.
static int handle_locally(coap_context_t *context, coap_queue_t *node)
static void coap_option_filter_clear(coap_opt_filter_t f)
Clears filter f.
int coap_hash_path(const unsigned char *path, size_t len, coap_key_t key)
Calculates a hash over the given path and stores the result in key.
#define COAP_PAYLOAD_START
void coap_free_context(coap_context_t *context)
CoAP stack context must be released with coap_free_context().
void coap_packet_copy_source(coap_packet_t *packet, coap_address_t *target)
Given an incoming packet, copy its source address into an address struct.
void coap_dispatch(coap_context_t *context, coap_queue_t *rcvd)
Dispatches the PDUs from the receive queue in given context.
int coap_option_check_critical(coap_context_t *ctx, coap_pdu_t *pdu, coap_opt_filter_t unknown)
Verifies that pdu contains no unknown critical options.
#define COAP_OPT_LENGTH(opt)
unsigned int token_length
void coap_delete_all_resources(coap_context_t *context)
Deletes all resources from given context and frees their storage.
#define COAP_OPTION_URI_PATH
void coap_touch_observer(coap_context_t *context, const coap_address_t *observer, const str *token)
Marks an observer as alive.
static enum respond_t no_response(coap_pdu_t *request, coap_pdu_t *response)
Checks for No-Response option in given request and returns 1 if response should be suppressed accordi...
#define COAP_ERROR_PHRASE_LENGTH
maximum length of error phrase
int sockfd
send/receive socket
void * coap_malloc_type(coap_memory_tag_t type, size_t size)
Allocates a chunk of size bytes and returns a pointer to the newly allocated memory.
#define ACK_RANDOM_FACTOR
creates a Qx.FRAC_BITS from COAP_DEFAULT_ACK_RANDOM_FACTOR
static coap_tid_t coap_send_impl(coap_context_t *context, const coap_endpoint_t *local_interface, const coap_address_t *dst, coap_pdu_t *pdu)
#define COAP_PRINT_STATUS_ERROR
#define COAP_OPTION_URI_QUERY
int coap_option_filter_get(const coap_opt_filter_t filter, unsigned short type)
Checks if type is contained in filter.
unsigned char coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
#define COAP_MESSAGE_IS_REQUEST(MSG)
union coap_address_t::@0 addr
#define COAP_OPTION_ACCEPT
coap_print_status_t coap_print_wellknown(coap_context_t *context, unsigned char *buf, size_t *buflen, size_t offset, coap_opt_t *query_filter)
Prints the names of all known resources to buf.
coap_opt_t * coap_check_option(coap_pdu_t *pdu, unsigned short type, coap_opt_iterator_t *oi)
Retrieves the first option of type type from pdu.
void coap_memory_init(void)
Initializes libcoap's memory management.
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
static int token_match(const unsigned char *a, size_t alen, const unsigned char *b, size_t blen)
char * coap_response_phrase(unsigned char code)
Returns a human-readable response phrase for the specified CoAP response code.
int coap_read(coap_context_t *ctx)
Reads data from the network and tries to parse as CoAP PDU.
int coap_is_mcast(const coap_address_t *a)
Checks if given address a denotes a multicast address.
#define prng(Buf, Length)
Fills Buf with Length bytes of random data.
static int coap_cancel(coap_context_t *context, const coap_queue_t *sent)
This function cancels outstanding messages for the remote peer and token specified in sent...
union coap_endpoint_t::@1 handle
opaque handle to identify this endpoint
#define MAX_BITS
The maximum number of bits for fixed point integers that are used for retransmission time calculation...
static int coap_option_clrb(coap_opt_filter_t filter, unsigned short type)
Clears the corresponding bit for type in filter.
coap_tid_t coap_send_error(coap_context_t *context, coap_pdu_t *request, const coap_endpoint_t *local_interface, const coap_address_t *dst, unsigned char code, coap_opt_filter_t opts)
Sends an error response with code code for request request to dst.
coap_log_t coap_get_log_level(void)
Returns the current log level.
int coap_remove_from_queue(coap_queue_t **queue, coap_tid_t id, coap_queue_t **node)
This function removes the element with given id from the list given list.
coap_tid_t coap_retransmit(coap_context_t *context, coap_queue_t *node)
Handles retransmissions of confirmable messages.
void(* coap_method_handler_t)(coap_context_t *, struct coap_resource_t *, const coap_endpoint_t *, coap_address_t *, coap_pdu_t *, str *, coap_pdu_t *)
Definition of message handler function (.
void coap_handle_failed_notify(coap_context_t *context, const coap_address_t *peer, const str *token)
unsigned int coap_decode_var_bytes(unsigned char *buf, unsigned int len)
Decodes multiple-length byte sequences.
#define COAP_OPTION_URI_HOST
#define COAP_ENDPOINT_NOSEC
coap_queue_t * coap_pop_next(coap_context_t *context)
Returns the next pdu to send and removes it from the sendqeue.
unsigned short coap_opt_length(const coap_opt_t *opt)
Returns the length of the given option.
unsigned char * data
payload
coap_queue_t * coap_new_node(void)
Creates a new node suitable for adding to the CoAP sendqueue.
respond_t
Internal flags to control the treatment of responses (specifically in presence of the No-Response opt...
#define COAP_OPT_VALUE(opt)
The CoAP stack's global state is stored in a coap_context_t object.
#define COAP_DEFAULT_MAX_RETRANSMIT
Number of message retransmissions before message sending is stopped.
#define COAP_MESSAGE_IS_RESPONSE(MSG)
int coap_delete_node(coap_queue_t *node)
Destroys specified node.
coap_resource_t * coap_get_resource_from_key(coap_context_t *context, coap_key_t key)
Returns the resource identified by the unique string key.
struct coap_resource_t * resources
hash table or list of known resources
unsigned int coap_adjust_basetime(coap_context_t *ctx, coap_tick_t now)
Set sendqueue_basetime in the given context object ctx to now.
coap_method_handler_t handler[4]
Used to store handlers for the four coap methods GET, POST, PUT, and DELETE.
static void handle_response(coap_context_t *context, coap_queue_t *sent, coap_queue_t *rcvd)
unsigned int m
1 if more blocks follow, 0 otherwise
unsigned int szx
block size
static void coap_free_node(coap_queue_t *node)
unsigned int num
block number
coap_opt_filter_t known_options
#define COAP_DROPPED_RESPONSE
Indicates that a response is suppressed.