Contiki-NG
Loading...
Searching...
No Matches
coap-endpoint.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016-2018, SICS, Swedish ICT AB.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30/**
31 * \file
32 * API to address CoAP endpoints
33 * \author
34 * Niclas Finne <nfi@sics.se>
35 * Joakim Eriksson <joakime@sics.se>
36 */
37
38/**
39 * \addtogroup coap-transport
40 * @{
41 */
42
43#ifndef COAP_ENDPOINT_H_
44#define COAP_ENDPOINT_H_
45
46#include "contiki.h"
47#include <stdlib.h>
48
49#ifndef COAP_ENDPOINT_CUSTOM
50#include "net/ipv6/uip.h"
51
52typedef struct {
53 uip_ipaddr_t ipaddr;
54 uint16_t port;
55 uint8_t secure;
56} coap_endpoint_t;
57#endif /* COAP_ENDPOINT_CUSTOM */
58
59/**
60 * \brief Copy a CoAP endpoint from one memory area to another.
61 *
62 * \param dest A pointer to a CoAP endpoint to copy to.
63 * \param src A pointer to a CoAP endpoint to copy from.
64 */
65void coap_endpoint_copy(coap_endpoint_t *dest, const coap_endpoint_t *src);
66
67/**
68 * \brief Compare two CoAP endpoints.
69 *
70 * \param e1 A pointer to the first CoAP endpoint.
71 * \param e2 A pointer to the second CoAP endpoint.
72 * \return Non-zero if the endpoints are identical and zero otherwise.
73 */
74int coap_endpoint_cmp(const coap_endpoint_t *e1, const coap_endpoint_t *e2);
75
76/**
77 * \brief Print a CoAP endpoint via the logging module.
78 *
79 * \param ep A pointer to the CoAP endpoint to log.
80 */
81void coap_endpoint_log(const coap_endpoint_t *ep);
82
83/**
84 * \brief Print a CoAP endpoint.
85 *
86 * \param ep A pointer to the CoAP endpoint to print.
87 */
88void coap_endpoint_print(const coap_endpoint_t *ep);
89
90/**
91 * \brief Print a CoAP endpoint to a string. The output is always
92 * null-terminated unless size is zero.
93 *
94 * \param str The string to write to.
95 * \param size The max number of characters to write.
96 * \param ep A pointer to the CoAP endpoint to print.
97 * \return Returns the number of characters needed for the output
98 * excluding the ending null-terminator or negative if an
99 * error occurred.
100 */
101int coap_endpoint_snprint(char *str, size_t size,
102 const coap_endpoint_t *ep);
103
104/**
105 * \brief Parse a CoAP endpoint.
106 *
107 * \param text The string to parse.
108 * \param size The max number of characters in the string.
109 * \param ep A pointer to the CoAP endpoint to write to.
110 * \return Returns non-zero if the endpoint was successfully parsed and
111 * zero otherwise.
112 */
113int coap_endpoint_parse(const char *text, size_t size, coap_endpoint_t *ep);
114
115/**
116 * \brief Check if a CoAP endpoint is secure (encrypted).
117 *
118 * \param ep A pointer to a CoAP endpoint.
119 * \return Returns non-zero if the endpoint is secure and zero otherwise.
120 */
121int coap_endpoint_is_secure(const coap_endpoint_t *ep);
122
123/**
124 * \brief Check if a CoAP endpoint is connected.
125 *
126 * \param ep A pointer to a CoAP endpoint.
127 * \return Returns non-zero if the endpoint is connected and zero otherwise.
128 */
129int coap_endpoint_is_connected(const coap_endpoint_t *ep);
130
131/**
132 * \brief Request a connection to a CoAP endpoint.
133 *
134 * \param ep A pointer to a CoAP endpoint.
135 * \return Returns zero if an error occured and non-zero otherwise.
136 */
137int coap_endpoint_connect(coap_endpoint_t *ep);
138
139/**
140 * \brief Request that any connection to a CoAP endpoint is discontinued.
141 *
142 * \param ep A pointer to a CoAP endpoint.
143 */
144void coap_endpoint_disconnect(coap_endpoint_t *ep);
145
146#endif /* COAP_ENDPOINT_H_ */
147/** @} */
void coap_endpoint_disconnect(coap_endpoint_t *ep)
Request that any connection to a CoAP endpoint is discontinued.
Definition coap-uip.c:312
int coap_endpoint_cmp(const coap_endpoint_t *e1, const coap_endpoint_t *e2)
Compare two CoAP endpoints.
Definition coap-uip.c:163
int coap_endpoint_parse(const char *text, size_t size, coap_endpoint_t *ep)
Parse a CoAP endpoint.
Definition coap-uip.c:201
int coap_endpoint_connect(coap_endpoint_t *ep)
Request a connection to a CoAP endpoint.
Definition coap-uip.c:287
void coap_endpoint_log(const coap_endpoint_t *ep)
Print a CoAP endpoint via the logging module.
Definition coap-uip.c:94
void coap_endpoint_print(const coap_endpoint_t *ep)
Print a CoAP endpoint.
Definition coap-uip.c:110
int coap_endpoint_snprint(char *str, size_t size, const coap_endpoint_t *ep)
Print a CoAP endpoint to a string.
Definition coap-uip.c:126
void coap_endpoint_copy(coap_endpoint_t *dest, const coap_endpoint_t *src)
Copy a CoAP endpoint from one memory area to another.
Definition coap-uip.c:154
int coap_endpoint_is_secure(const coap_endpoint_t *ep)
Check if a CoAP endpoint is secure (encrypted).
Definition coap-uip.c:244
int coap_endpoint_is_connected(const coap_endpoint_t *ep)
Check if a CoAP endpoint is connected.
Definition coap-uip.c:250
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
Definition uip-nd6.c:116
Header file for the uIP TCP/IP stack.