20 #include <lwip/ip_addr.h> 69 #define COAP_MID_CACHE_SIZE 3 98 struct uip_udp_conn *conn;
99 struct etimer retransmit_timer;
100 struct etimer notify_timer;
104 uint8_t timer_configured;
127 unsigned char *data,
size_t datalen);
188 static inline unsigned short 454 const unsigned char *token,
455 size_t token_length);
unsigned int observe
The next value to be used for Observe.
unsigned char coap_key_t[4]
coap_queue_t * coap_pop_next(coap_context_t *context)
Returns the next pdu to send and removes it from the sendqeue.
void coap_dispatch(coap_context_t *context, coap_queue_t *rcvd)
Dispatches the PDUs from the receive queue in given context.
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.
void(* coap_response_handler_t)(struct coap_context_t *, const coap_endpoint_t *local_interface, const coap_address_t *remote, coap_pdu_t *sent, coap_pdu_t *received, const coap_tid_t id)
Message handler that is used as call-back in coap_context_t.
unsigned char retransmit_cnt
retransmission counter, will be removed when zero
ssize_t(* network_read)(coap_endpoint_t *ep, coap_packet_t **packet)
coap_endpoint_t * endpoint
the endpoint used for listening
multi-purpose address abstraction
int coap_tid_t
coap_tid_t is used to store CoAP transaction id, i.e.
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.
static void coap_register_option(coap_context_t *ctx, unsigned char type)
Registers the option type type with the given context object ctx.
coap_endpoint_t local_if
the local address interface
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.
static int coap_remove_transaction(coap_queue_t **queue, coap_tid_t id)
Removes the transaction identified by id from given queue.
static coap_tid_t coap_send_rst(coap_context_t *context, const coap_endpoint_t *local_interface, const coap_address_t *dst, coap_pdu_t *request)
Sends an RST message with code 0 for the specified request to dst.
coap_address_t remote
remote address
struct coap_context_t coap_context_t
The CoAP stack's global state is stored in a coap_context_t object.
coap_queue_t * coap_find_transaction(coap_queue_t *queue, coap_tid_t id)
Retrieves transaction from the queue.
struct coap_async_state_t * async_state
list of asynchronous transactions
Helpers for handling options in CoAP PDUs.
static int coap_option_setb(coap_opt_filter_t filter, unsigned short type)
Sets the corresponding bit for type in filter.
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.
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_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.
Abstraction of virtual endpoint that can be attached to coap_context_t.
coap_tid_t coap_retransmit(coap_context_t *context, coap_queue_t *node)
Handles retransmissions of confirmable messages.
coap_tid_t id
unique transaction id
static void coap_register_response_handler(coap_context_t *context, coap_response_handler_t handler)
Registers a new message handler that is called whenever a response was received that matches an ongoi...
coap_tick_t sendqueue_basetime
The time stamp in the first element of the sendqeue is relative to sendqueue_basetime.
coap_pdu_t * pdu
the CoAP PDU to send
coap_tick_t t
when to send PDU for the next time
#define COAP_MID_CACHE_SIZE
Header structure for CoAP PDUs.
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_response_handler_t response_handler
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.
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.
struct coap_queue_t * next
void coap_ticks(coap_tick_t *)
Returns the current value of an internal tick counter.
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.
unsigned int timeout
the randomized timeout value
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.
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.
int coap_delete_node(coap_queue_t *node)
Destroys specified node.
int coap_handle_message(coap_context_t *ctx, coap_packet_t *packet)
Parses and interprets a CoAP message with context ctx.
Pre-defined constants that reflect defaults for CoAP.
uint16_t coap_opt_filter_t[COAP_OPT_FILTER_SIZE]
Fixed-size vector we use for option filtering.
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).
static unsigned short coap_new_message_id(coap_context_t *context)
Returns a new message id and updates context->message_id accordingly.
coap_queue_t * coap_peek_next(coap_context_t *context)
Returns the next pdu to send without removing from sendqeue.
int sockfd
send/receive socket
int coap_read(coap_context_t *context)
Reads data from the network and tries to parse as CoAP PDU.
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_delete_all(coap_queue_t *queue)
Removes all items from given queue and frees the allocated storage.
coap_queue_t * coap_new_node(void)
Creates a new node suitable for adding to the CoAP sendqueue.
struct coap_queue_t coap_queue_t
void coap_free_context(coap_context_t *context)
CoAP stack context must be released with coap_free_context().
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.
The CoAP stack's global state is stored in a coap_context_t object.
struct coap_resource_t * resources
hash table or list of known resources
int coap_insert_node(coap_queue_t **queue, coap_queue_t *node)
Adds node to given queue, ordered by node->t.
coap_opt_filter_t known_options