21 #include <lwip/ip_addr.h> 154 #ifndef WITHOUT_ASYNC 169 struct uip_udp_conn *conn;
170 struct etimer retransmit_timer;
171 struct etimer notify_timer;
212 #ifdef COAP_EPOLL_SUPPORT 319 const uint8_t *key,
size_t key_len );
557 unsigned int max_sockets,
558 unsigned int *num_sockets,
570 #define COAP_RUN_BLOCK 0 571 #define COAP_RUN_NONBLOCK 1 702 size_t token_length);
COAP_STATIC_INLINE void coap_register_nack_handler(coap_context_t *context, coap_nack_handler_t handler)
Registers a new message handler that is called whenever a confirmable message (request or response) i...
unsigned int coap_write(coap_context_t *ctx, coap_socket_t *sockets[], unsigned int max_sockets, unsigned int *num_sockets, coap_tick_t now)
For applications with their own message loop, send all pending retransmits and return the list of soc...
void(* coap_pong_handler_t)(struct coap_context_t *context, coap_session_t *session, coap_pdu_t *received, const coap_tid_t id)
Recieved Pong handler that is used as call-back in coap_context_t.
int coap_context_set_pki_root_cas(coap_context_t *context, const char *ca_file, const char *ca_dir)
Set the context's default Root CA information for a client or server.
coap_queue_t * coap_find_transaction(coap_queue_t *queue, coap_session_t *session, coap_tid_t id)
Retrieves transaction from the queue.
coap_ping_handler_t ping_handler
void * coap_get_app_data(const coap_context_t *context)
Returns any application-specific data that has been stored with context using the function coap_set_a...
coap_queue_t * coap_pop_next(coap_context_t *context)
Returns the next pdu to send and removes it from the sendqeue.
coap_tid_t coap_send(coap_session_t *session, coap_pdu_t *pdu)
Sends a CoAP message to given peer.
unsigned char retransmit_cnt
retransmission counter, will be removed when zero
coap_endpoint_t * endpoint
the endpoints used for listening
COAP_STATIC_INLINE int coap_option_setb(coap_opt_filter_t filter, uint16_t type)
Sets the corresponding bit for type in filter.
multi-purpose address abstraction
uint16_t tx_mid
the last message id that was used in this session
coap_tid_t coap_send_error(coap_session_t *session, coap_pdu_t *request, unsigned char code, coap_opt_filter_t opts)
Sends an error response with code code for request request to dst.
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.
int coap_context_set_pki(coap_context_t *context, coap_dtls_pki_t *setup_data)
Set the context's default PKI information for a server.
struct coap_context_t coap_context_t
The CoAP stack's global state is stored in a coap_context_t object.
coap_nack_handler_t nack_handler
struct coap_async_state_t * async_state
list of asynchronous transactions
Helpers for handling options in CoAP PDUs.
void coap_io_do_events(coap_context_t *ctx, struct epoll_event *events, size_t nevents)
Process all the epoll events.
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.
int coap_context_get_coap_fd(coap_context_t *context)
Get the libcoap internal file descriptor for using in an application's select() or returned as an eve...
Abstraction of virtual endpoint that can be attached to coap_context_t.
COAP_STATIC_INLINE uint16_t coap_new_message_id(coap_session_t *session)
Returns a new message id and updates session->tx_mid accordingly.
coap_tid_t coap_retransmit(coap_context_t *context, coap_queue_t *node)
Handles retransmissions of confirmable messages.
unsigned int coap_io_prepare_epoll(coap_context_t *ctx, coap_tick_t now)
Any now timed out delayed packet is transmitted, along with any packets associated with requested obs...
coap_pong_handler_t pong_handler
coap_tid_t id
CoAP transaction id.
COAP_STATIC_INLINE 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_STATIC_INLINE void coap_register_ping_handler(coap_context_t *context, coap_ping_handler_t handler)
Registers a new message handler that is called whenever a CoAP Ping message is received.
coap_tick_t sendqueue_basetime
The time stamp in the first element of the sendqeue is relative to sendqueue_basetime.
COAP_STATIC_INLINE coap_tid_t coap_send_rst(coap_session_t *session, coap_pdu_t *request)
Sends an RST message with code 0 for the specified request to dst.
coap_pdu_t * pdu
the CoAP PDU to send
int coap_join_mcast_group(coap_context_t *ctx, const char *groupname)
Function interface for joining a multicast group for listening.
void coap_cancel_all_messages(coap_context_t *context, coap_session_t *session, const uint8_t *token, size_t token_length)
Cancels all outstanding messages for session session that have the specified token.
coap_tick_t t
when to send PDU for the next time
unsigned int ping_timeout
Minimum inactivity time before sending a ping message.
COAP_STATIC_INLINE void coap_register_pong_handler(coap_context_t *context, coap_pong_handler_t handler)
Registers a new message handler that is called whenever a CoAP Pong message is received.
void coap_ticks(coap_tick_t *)
Returns the current value of an internal tick counter.
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
int coap_handle_dgram(coap_context_t *ctx, coap_session_t *session, uint8_t *data, size_t data_len)
Parses and interprets a CoAP datagram with context ctx.
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
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
int coap_run_once(coap_context_t *ctx, unsigned int timeout_ms)
The main message processing loop.
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.
int coap_remove_from_queue(coap_queue_t **queue, coap_session_t *session, 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_send_ack(coap_session_t *session, coap_pdu_t *request)
Sends an ACK message with code 0 for the specified request to dst.
void(* coap_ping_handler_t)(struct coap_context_t *context, coap_session_t *session, coap_pdu_t *received, const coap_tid_t id)
Recieved Ping handler that is used as call-back in coap_context_t.
struct coap_queue_t * next
coap_event_handler_t handle_event
Callback function that is used to signal events to the application.
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_nack_handler_t)(struct coap_context_t *context, coap_session_t *session, coap_pdu_t *sent, coap_nack_reason_t reason, const coap_tid_t id)
Negative Acknowedge handler that is used as call-back in coap_context_t.
coap_pdu_t * coap_wellknown_response(coap_context_t *context, coap_session_t *session, coap_pdu_t *request)
Creates a new response for given request with the contents of .well-known/core.
int coap_delete_node(coap_queue_t *node)
Destroys specified node.
int coap_context_set_psk(coap_context_t *context, const char *hint, const uint8_t *key, size_t key_len)
Set the context's default PSK hint and/or key for a server.
Defines the application visible session information.
#define COAP_STATIC_INLINE
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.
unsigned int coap_event_t
Scalar type to represent different events, e.g.
struct coap_resource_t * unknown_resource
can be used for handling unknown resources
The structure used for defining the PKI setup data to be used.
int coap_handle_event(coap_context_t *context, coap_event_t event, coap_session_t *session)
Invokes the event handler of context for the given event and data.
coap_queue_t * coap_peek_next(coap_context_t *context)
Returns the next pdu to send without removing from sendqeue.
unsigned int csm_timeout
Timeout for waiting for a CSM from the remote side.
void coap_context_set_keepalive(coap_context_t *context, unsigned int seconds)
Set the context keepalive timer for sessions.
unsigned int max_handshake_sessions
Maximum number of simultaneous negotating sessions per endpoint.
void(* coap_response_handler_t)(struct coap_context_t *context, coap_session_t *session, coap_pdu_t *sent, coap_pdu_t *received, const coap_tid_t id)
Response handler that is used as call-back in coap_context_t.
int(* coap_event_handler_t)(struct coap_context_t *, coap_event_t event, struct coap_session_t *session)
Type for event handler functions that can be registered with a CoAP context using the unction coap_se...
void * app
application-specific data
void coap_delete_all(coap_queue_t *queue)
Removes all items from given queue and frees the allocated storage.
coap_session_t * sessions
client sessions
coap_session_t * session
the CoAP session
void coap_read(coap_context_t *ctx, coap_tick_t now)
For applications with their own message loop, reads all data from the network.
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
Queue entry.
void coap_cancel_session_messages(coap_context_t *context, coap_session_t *session, coap_nack_reason_t reason)
Cancels all outstanding messages for session session.
void coap_dispatch(coap_context_t *context, coap_session_t *session, coap_pdu_t *pdu)
Dispatches the PDUs from the receive queue in given context.
void coap_free_context(coap_context_t *context)
CoAP stack context must be released with coap_free_context().
void coap_set_app_data(coap_context_t *context, void *data)
Stores data with the given CoAP context.
COAP_STATIC_INLINE void coap_register_option(coap_context_t *ctx, uint16_t type)
Registers the option type type with the given context object ctx.
coap_tid_t coap_send_message_type(coap_session_t *session, coap_pdu_t *request, unsigned char type)
Helper funktion to create and send a message with type (usually ACK or RST).
The CoAP stack's global state is stored in a coap_context_t object.
unsigned int max_idle_sessions
Maximum number of simultaneous unused sessions per endpoint.
struct coap_resource_t * resources
hash table or list of known resources
coap_tid_t coap_wait_ack(coap_context_t *context, coap_session_t *session, coap_queue_t *node)
unsigned int coap_calc_timeout(coap_session_t *session, unsigned char r)
Calculates the initial timeout based on the session CoAP transmission parameters 'ack_timeout', 'ack_random_factor', and COAP_TICKS_PER_SECOND.
unsigned int session_timeout
Number of seconds of inactivity after which an unused session will be closed.
int coap_insert_node(coap_queue_t **queue, coap_queue_t *node)
Adds node to given queue, ordered by variable t in node.
coap_opt_filter_t known_options