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);
Defines the application visible session information.
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
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...
unsigned int coap_event_t
Scalar type to represent different events, e.g.
uint16_t coap_opt_filter_t[COAP_OPT_FILTER_SIZE]
Fixed-size vector we use for option filtering.
COAP_STATIC_INLINE int coap_option_setb(coap_opt_filter_t filter, uint16_t type)
Sets the corresponding bit for type in filter.
#define COAP_STATIC_INLINE
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_queue_t * coap_peek_next(coap_context_t *context)
Returns the next pdu to send without removing from sendqeue.
void coap_read(coap_context_t *ctx, coap_tick_t now)
For applications with their own message loop, reads all data from the network.
int coap_join_mcast_group(coap_context_t *ctx, const char *groupname)
Function interface for joining a multicast group for listening.
unsigned int coap_adjust_basetime(coap_context_t *ctx, coap_tick_t now)
Set sendqueue_basetime in the given context object ctx to now.
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.
void coap_delete_all(coap_queue_t *queue)
Removes all items from given queue and frees the allocated storage.
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...
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.
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...
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.
int coap_delete_node(coap_queue_t *node)
Destroys specified node.
coap_queue_t * coap_new_node(void)
Creates a new node suitable for adding to the CoAP sendqueue.
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_queue_t * coap_pop_next(coap_context_t *context)
Returns the next pdu to send and removes it from the sendqeue.
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...
void coap_free_context(coap_context_t *context)
CoAP stack context must be released with coap_free_context().
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_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.
struct coap_queue_t coap_queue_t
Queue entry.
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.
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.
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.
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_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.
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).
void coap_ticks(coap_tick_t *)
Returns the current value of an internal tick counter.
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.
void coap_io_do_events(coap_context_t *ctx, struct epoll_event *events, size_t nevents)
Process all the epoll events.
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.
coap_tid_t coap_wait_ack(coap_context_t *context, coap_session_t *session, coap_queue_t *node)
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...
int coap_insert_node(coap_queue_t **queue, coap_queue_t *node)
Adds node to given queue, ordered by variable t in 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',...
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.
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_run_once(coap_context_t *ctx, unsigned int timeout_ms)
The main message processing loop.
coap_queue_t * coap_find_transaction(coap_queue_t *queue, coap_session_t *session, coap_tid_t id)
Retrieves transaction from the queue.
coap_tid_t coap_retransmit(coap_context_t *context, coap_queue_t *node)
Handles retransmissions of confirmable messages.
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.
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...
coap_tid_t coap_send(coap_session_t *session, coap_pdu_t *pdu)
Sends a CoAP message to given peer.
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_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.
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_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.
struct coap_context_t coap_context_t
The CoAP stack's global state is stored in a coap_context_t object.
void coap_context_set_keepalive(coap_context_t *context, unsigned int seconds)
Set the context keepalive timer for sessions.
void coap_set_app_data(coap_context_t *context, void *data)
Stores data with the given CoAP context.
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.
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_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...
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.
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.
Helpers for handling options in CoAP PDUs.
Pre-defined constants that reflect defaults for CoAP.
int coap_tid_t
coap_tid_t is used to store CoAP transaction id, i.e.
multi-purpose address abstraction
The CoAP stack's global state is stored in a coap_context_t object.
coap_tick_t sendqueue_basetime
The time stamp in the first element of the sendqeue is relative to sendqueue_basetime.
coap_pong_handler_t pong_handler
ssize_t(* network_read)(coap_socket_t *sock, struct coap_packet_t *packet)
unsigned int csm_timeout
Timeout for waiting for a CSM from the remote side.
void * app
application-specific data
struct coap_resource_t * unknown_resource
can be used for handling unknown resources
struct coap_async_state_t * async_state
list of asynchronous transactions
coap_session_t * sessions
client sessions
coap_nack_handler_t nack_handler
unsigned int ping_timeout
Minimum inactivity time before sending a ping message.
size_t(* get_server_psk)(const coap_session_t *session, const uint8_t *identity, size_t identity_len, uint8_t *psk, size_t max_psk_len)
ssize_t(* network_send)(coap_socket_t *sock, const coap_session_t *session, const uint8_t *data, size_t datalen)
coap_opt_filter_t known_options
coap_ping_handler_t ping_handler
unsigned int max_handshake_sessions
Maximum number of simultaneous negotating sessions per endpoint.
coap_response_handler_t response_handler
struct coap_resource_t * resources
hash table or list of known resources
coap_endpoint_t * endpoint
the endpoints used for listening
size_t(* get_server_hint)(const coap_session_t *session, uint8_t *hint, size_t max_hint_len)
coap_event_handler_t handle_event
Callback function that is used to signal events to the application.
unsigned int session_timeout
Number of seconds of inactivity after which an unused session will be closed.
size_t(* get_client_psk)(const coap_session_t *session, const uint8_t *hint, size_t hint_len, uint8_t *identity, size_t *identity_len, size_t max_identity_len, uint8_t *psk, size_t max_psk_len)
unsigned int max_idle_sessions
Maximum number of simultaneous unused sessions per endpoint.
The structure used for defining the PKI setup data to be used.
Abstraction of virtual endpoint that can be attached to coap_context_t.
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
coap_session_t * session
the CoAP session
coap_pdu_t * pdu
the CoAP PDU to send
unsigned int timeout
the randomized timeout value
struct coap_queue_t * next
coap_tick_t t
when to send PDU for the next time
coap_tid_t id
CoAP transaction id.
unsigned char retransmit_cnt
retransmission counter, will be removed when zero
uint16_t tx_mid
the last message id that was used in this session