Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Enumerations | Functions
sol-coap.h File Reference

Routines to handle CoAP protocol. More...

#include <sol-socket.h>
#include <sol-network.h>
#include <sol-str-slice.h>

Go to the source code of this file.

Data Structures

struct  sol_coap_resource
 Description for a CoAP resource. More...
 

Macros

#define SOL_COAP_CODE_EMPTY   (0)
 Macro to indicates that the header code was not set. More...
 
#define sol_coap_make_response_code(clas, det)   ((clas << 5) | (det))
 Macro to create a response code. More...
 
#define SOL_COAP_REQUEST_MASK   0x07
 Mask of CoAP requests. More...
 
#define SOL_COAP_RESOURCE_API_VERSION   (1)
 

Typedefs

typedef struct sol_coap_packet sol_coap_packet
 Opaque handler for a CoAP packet. More...
 
typedef struct sol_coap_resource sol_coap_resource
 Description for a CoAP resource. More...
 
typedef struct sol_coap_server sol_coap_server
 Opaque handler for a CoAP server. More...
 

Enumerations

enum  sol_coap_content_type {
  SOL_COAP_CONTENT_TYPE_NONE = -1, SOL_COAP_CONTENT_TYPE_TEXT_PLAIN = 0, SOL_COAP_CONTENT_TYPE_APPLICATION_LINK_FORMAT = 40, SOL_COAP_CONTENT_TYPE_APPLICATION_CBOR = 60,
  SOL_COAP_CONTENT_TYPE_APPLICATION_JSON = 50
}
 Some content-types available for use with the CONTENT_FORMAT option. More...
 
enum  sol_coap_flags { SOL_COAP_FLAGS_NONE = 0, SOL_COAP_FLAGS_WELL_KNOWN = (1 << 1) }
 Flags accepted by a sol_coap_resource. More...
 
enum  sol_coap_message_type { SOL_COAP_MESSAGE_TYPE_CON = 0, SOL_COAP_MESSAGE_TYPE_NON_CON = 1, SOL_COAP_MESSAGE_TYPE_ACK = 2, SOL_COAP_MESSAGE_TYPE_RESET = 3 }
 CoAP packets may be of one of these types. More...
 
enum  sol_coap_method { SOL_COAP_METHOD_GET = 1, SOL_COAP_METHOD_POST = 2, SOL_COAP_METHOD_PUT = 3, SOL_COAP_METHOD_DELETE = 4 }
 Available request methods. More...
 
enum  sol_coap_option {
  SOL_COAP_OPTION_IF_MATCH = 1, SOL_COAP_OPTION_URI_HOST = 3, SOL_COAP_OPTION_ETAG = 4, SOL_COAP_OPTION_IF_NONE_MATCH = 5,
  SOL_COAP_OPTION_OBSERVE = 6, SOL_COAP_OPTION_URI_PORT = 7, SOL_COAP_OPTION_LOCATION_PATH = 8, SOL_COAP_OPTION_URI_PATH = 11,
  SOL_COAP_OPTION_CONTENT_FORMAT = 12, SOL_COAP_OPTION_MAX_AGE = 14, SOL_COAP_OPTION_URI_QUERY = 15, SOL_COAP_OPTION_ACCEPT = 17,
  SOL_COAP_OPTION_LOCATION_QUERY = 20, SOL_COAP_OPTION_PROXY_URI = 35, SOL_COAP_OPTION_PROXY_SCHEME = 39
}
 Set of CoAP packet options we are aware of. More...
 
enum  sol_coap_response_code {
  SOL_COAP_RESPONSE_CODE_OK = sol_coap_make_response_code(2, 0), SOL_COAP_RESPONSE_CODE_CREATED = sol_coap_make_response_code(2, 1), SOL_COAP_RESPONSE_CODE_DELETED = sol_coap_make_response_code(2, 2), SOL_COAP_RESPONSE_CODE_VALID = sol_coap_make_response_code(2, 3),
  SOL_COAP_RESPONSE_CODE_CHANGED = sol_coap_make_response_code(2, 4), SOL_COAP_RESPONSE_CODE_CONTENT = sol_coap_make_response_code(2, 5), SOL_COAP_RESPONSE_CODE_BAD_REQUEST = sol_coap_make_response_code(4, 0), SOL_COAP_RESPONSE_CODE_UNAUTHORIZED = sol_coap_make_response_code(4, 1),
  SOL_COAP_RESPONSE_CODE_BAD_OPTION = sol_coap_make_response_code(4, 2), SOL_COAP_RESPONSE_CODE_FORBIDDEN = sol_coap_make_response_code(4, 3), SOL_COAP_RESPONSE_CODE_NOT_FOUND = sol_coap_make_response_code(4, 4), SOL_COAP_RESPONSE_CODE_NOT_ALLOWED = sol_coap_make_response_code(4, 5),
  SOL_COAP_RESPONSE_CODE_NOT_ACCEPTABLE = sol_coap_make_response_code(4, 6), SOL_COAP_RESPONSE_CODE_PRECONDITION_FAILED = sol_coap_make_response_code(4, 12), SOL_COAP_RESPONSE_CODE_REQUEST_TOO_LARGE = sol_coap_make_response_code(4, 13), SOL_COAP_RESPONSE_CODE_UNSUPPORTED_CONTENT_FORMAT = sol_coap_make_response_code(4, 15),
  SOL_COAP_RESPONSE_CODE_INTERNAL_ERROR = sol_coap_make_response_code(5, 0), SOL_COAP_RESPONSE_CODE_NOT_IMPLEMENTED = sol_coap_make_response_code(5, 1), SOL_COAP_RESPONSE_CODE_BAD_GATEWAY = sol_coap_make_response_code(5, 2), SOL_COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE = sol_coap_make_response_code(5, 3),
  SOL_COAP_RESPONSE_CODE_GATEWAY_TIMEOUT = sol_coap_make_response_code(5, 4), SOL_COAP_RESPONSE_CODE_PROXYING_NOT_SUPPORTED = sol_coap_make_response_code(5, 5)
}
 Set of response codes available for a response packet. More...
 

Functions

int sol_coap_add_option (struct sol_coap_packet *pkt, uint16_t code, const void *value, uint16_t len)
 Adds an option to the CoAP packet. More...
 
int sol_coap_cancel_send_packet (struct sol_coap_server *server, struct sol_coap_packet *pkt, struct sol_network_link_addr *cliaddr)
 Cancel a packet sent using sol_coap_send_packet() or sol_coap_send_packet_with_reply() functions. More...
 
const void * sol_coap_find_first_option (const struct sol_coap_packet *pkt, uint16_t code, uint16_t *len)
 Finds the first apeearence of the specified option in a packet. More...
 
int sol_coap_find_options (const struct sol_coap_packet *pkt, uint16_t code, struct sol_str_slice *vec, uint16_t veclen)
 Gets a number of specified option in a packet. More...
 
int sol_coap_header_get_code (const struct sol_coap_packet *pkt, uint8_t *code)
 Gets the request/response code in the packet. More...
 
int sol_coap_header_get_id (const struct sol_coap_packet *pkt, uint16_t *id)
 Gets the message ID. More...
 
uint8_t * sol_coap_header_get_token (const struct sol_coap_packet *pkt, uint8_t *len)
 Gets the token of the packet, if any. More...
 
int sol_coap_header_get_type (const struct sol_coap_packet *pkt, uint8_t *type)
 Gets the type of the message container in the packet. More...
 
int sol_coap_header_get_version (const struct sol_coap_packet *pkt, uint8_t *version)
 Gets the CoAP protocol version of the packet. More...
 
int sol_coap_header_set_code (struct sol_coap_packet *pkt, uint8_t code)
 Sets the code of the message. More...
 
int sol_coap_header_set_id (struct sol_coap_packet *pkt, uint16_t id)
 Sets the message ID. More...
 
int sol_coap_header_set_token (struct sol_coap_packet *pkt, uint8_t *token, uint8_t tokenlen)
 Sets a token in the packet. More...
 
int sol_coap_header_set_type (struct sol_coap_packet *pkt, uint8_t type)
 Sets the message type in the packet's header. More...
 
int sol_coap_header_set_version (struct sol_coap_packet *pkt, uint8_t ver)
 Sets the CoAP protocol version in the packet's header. More...
 
int sol_coap_notify (struct sol_coap_server *server, struct sol_coap_resource *resource, struct sol_coap_packet *pkt)
 Sends the notification packet to all registered observers. More...
 
int sol_coap_notify_by_callback (struct sol_coap_server *server, struct sol_coap_resource *resource, int(*cb)(void *cb_data, struct sol_coap_server *server, struct sol_coap_resource *resource, struct sol_network_link_addr *addr, struct sol_coap_packet **pkt), const void *cb_data)
 Sends the notification packet returned by a callback to all registered observers. More...
 
int sol_coap_packet_add_uri_path_option (struct sol_coap_packet *pkt, const char *uri)
 Convenience function to add the the SOL_COAP_OPTION_URI_PATH from a string. More...
 
static void sol_coap_packet_debug (struct sol_coap_packet *pkt)
 Print information about the packet pkt. More...
 
int sol_coap_packet_get_payload (struct sol_coap_packet *pkt, struct sol_buffer **buf, size_t *offset)
 Gets a pointer to the packet's payload. More...
 
bool sol_coap_packet_has_payload (struct sol_coap_packet *pkt)
 Checks if the given packet contains a payload. More...
 
struct sol_coap_packetsol_coap_packet_new (struct sol_coap_packet *old)
 Creates a new CoAP packet. More...
 
struct sol_coap_packetsol_coap_packet_new_notification (struct sol_coap_server *server, struct sol_coap_resource *resource)
 Convenience function to create a packet suitable to send as a notification. More...
 
struct sol_coap_packetsol_coap_packet_new_request (enum sol_coap_method method, enum sol_coap_message_type type)
 Convenience function to create a new packet for a request. More...
 
struct sol_coap_packetsol_coap_packet_ref (struct sol_coap_packet *pkt)
 Take a reference of the given packet. More...
 
void sol_coap_packet_unref (struct sol_coap_packet *pkt)
 Release a reference from the given packet. More...
 
int sol_coap_path_to_buffer (const struct sol_str_slice path[], struct sol_buffer *buf, size_t offset, size_t *size)
 Inserts a path given in slices form to a sol-buffer, at a given offset. More...
 
int sol_coap_send_packet (struct sol_coap_server *server, struct sol_coap_packet *pkt, const struct sol_network_link_addr *cliaddr)
 Sends a packet to the given address. More...
 
int sol_coap_send_packet_with_reply (struct sol_coap_server *server, struct sol_coap_packet *pkt, const struct sol_network_link_addr *cliaddr, bool(*reply_cb)(void *data, struct sol_coap_server *server, struct sol_coap_packet *req, const struct sol_network_link_addr *cliaddr), const void *data)
 Sends a packet to the given address. More...
 
bool sol_coap_server_is_secure (const struct sol_coap_server *server)
 Check if a given CoAP server instance is running over DTLS or not. More...
 
struct sol_coap_serversol_coap_server_new (const struct sol_network_link_addr *addr, bool secure)
 Creates a new CoAP server instance. More...
 
struct sol_coap_serversol_coap_server_new_by_cipher_suites (const struct sol_network_link_addr *addr, enum sol_socket_dtls_cipher *cipher_suites, uint16_t cipher_suites_len)
 Creates a new DTLS-Secured CoAP server instance. More...
 
struct sol_coap_serversol_coap_server_ref (struct sol_coap_server *server)
 Take a reference of the given server. More...
 
int sol_coap_server_register_resource (struct sol_coap_server *server, const struct sol_coap_resource *resource, const void *data)
 Register a sol_coap_resource with the server. More...
 
int sol_coap_server_set_unknown_resource_handler (struct sol_coap_server *server, int(*handler)(void *data, struct sol_coap_server *server, struct sol_coap_packet *req, const struct sol_network_link_addr *cliaddr), const void *data)
 Register a unknown handler callback. More...
 
void sol_coap_server_unref (struct sol_coap_server *server)
 Release a reference from the given server. More...
 
int sol_coap_server_unregister_resource (struct sol_coap_server *server, const struct sol_coap_resource *resource)
 Unregisters a resource from the server. More...
 
int sol_coap_unobserve_by_token (struct sol_coap_server *server, const struct sol_network_link_addr *cliaddr, uint8_t *token, uint8_t tkl)
 Remove observation identified by token from server. More...
 

Detailed Description

Routines to handle CoAP protocol.

The Constrained Application Protocol (CoAP) is a specialized web transfer protocol for use with constrained nodes and constrained (e.g., low-power, lossy) networks.

Macro Definition Documentation

#define SOL_COAP_RESOURCE_API_VERSION   (1)