Contiki-NG
coap-uip.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, 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  * CoAP transport implementation for uIPv6
33  * \author
34  * Niclas Finne <nfi@sics.se>
35  * Joakim Eriksson <joakime@sics.se>
36  */
37 
38 /**
39  * \addtogroup coap-transport
40  * @{
41  *
42  * \defgroup coap-uip CoAP transport implementation for uIP
43  * @{
44  *
45  * This is an implementation of CoAP transport and CoAP endpoint over uIP
46  * with DTLS support.
47  */
48 
49 #include "contiki.h"
51 #include "net/ipv6/uiplib.h"
52 #include "net/routing/routing.h"
53 #include "coap.h"
54 #include "coap-engine.h"
55 #include "coap-endpoint.h"
56 #include "coap-transport.h"
57 #include "coap-transactions.h"
58 #include "coap-constants.h"
59 #include "coap-keystore.h"
60 #include "coap-keystore-simple.h"
61 
62 /* Log configuration */
63 #include "coap-log.h"
64 #define LOG_MODULE "coap-uip"
65 #define LOG_LEVEL LOG_LEVEL_COAP
66 
67 #ifdef WITH_DTLS
68 #include "tinydtls.h"
69 #include "dtls.h"
70 #endif /* WITH_DTLS */
71 
72 /* sanity check for configured values */
73 #if COAP_MAX_PACKET_SIZE > (UIP_BUFSIZE - UIP_LLH_LEN - UIP_IPH_LEN - UIP_UDPH_LEN)
74 #error "UIP_CONF_BUFFER_SIZE too small for COAP_MAX_CHUNK_SIZE"
75 #endif
76 
77 #define SERVER_LISTEN_PORT UIP_HTONS(COAP_DEFAULT_PORT)
78 #define SERVER_LISTEN_SECURE_PORT UIP_HTONS(COAP_DEFAULT_SECURE_PORT)
79 
80 /* direct access into the buffer */
81 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
82 #if NETSTACK_CONF_WITH_IPV6
83 #define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
84 #else
85 #define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
86 #endif
87 
88 #ifdef WITH_DTLS
89 static dtls_handler_t cb;
90 static dtls_context_t *dtls_context = NULL;
91 
92 static const coap_keystore_t *dtls_keystore = NULL;
93 static struct uip_udp_conn *dtls_conn = NULL;
94 #endif /* WITH_DTLS */
95 
96 PROCESS(coap_engine, "CoAP Engine");
97 
98 static struct uip_udp_conn *udp_conn = NULL;
99 
100 /*---------------------------------------------------------------------------*/
101 void
102 coap_endpoint_log(const coap_endpoint_t *ep)
103 {
104  if(ep == NULL) {
105  LOG_OUTPUT("(NULL EP)");
106  return;
107  }
108  if(ep->secure) {
109  LOG_OUTPUT("coaps://[");
110  } else {
111  LOG_OUTPUT("coap://[");
112  }
113  log_6addr(&ep->ipaddr);
114  LOG_OUTPUT("]:%u", uip_ntohs(ep->port));
115 }
116 /*---------------------------------------------------------------------------*/
117 void
118 coap_endpoint_print(const coap_endpoint_t *ep)
119 {
120  if(ep == NULL) {
121  printf("(NULL EP)");
122  return;
123  }
124  if(ep->secure) {
125  printf("coaps://[");
126  } else {
127  printf("coap://[");
128  }
129  uiplib_ipaddr_print(&ep->ipaddr);
130  printf("]:%u", uip_ntohs(ep->port));
131 }
132 /*---------------------------------------------------------------------------*/
133 int
134 coap_endpoint_snprint(char *buf, size_t size, const coap_endpoint_t *ep)
135 {
136  int n;
137  if(buf == NULL || size == 0) {
138  return 0;
139  }
140  if(ep == NULL) {
141  n = snprintf(buf, size - 1, "(NULL EP)");
142  } else {
143  if(ep->secure) {
144  n = snprintf(buf, size - 1, "coaps://[");
145  } else {
146  n = snprintf(buf, size - 1, "coap://[");
147  }
148  if(n < size - 1) {
149  n += uiplib_ipaddr_snprint(&buf[n], size - n - 1, &ep->ipaddr);
150  }
151  if(n < size - 1) {
152  n += snprintf(&buf[n], size -n - 1, "]:%u", uip_ntohs(ep->port));
153  }
154  }
155  if(n >= size - 1) {
156  buf[size - 1] = '\0';
157  }
158  return n;
159 }
160 /*---------------------------------------------------------------------------*/
161 void
162 coap_endpoint_copy(coap_endpoint_t *destination,
163  const coap_endpoint_t *from)
164 {
165  uip_ipaddr_copy(&destination->ipaddr, &from->ipaddr);
166  destination->port = from->port;
167  destination->secure = from->secure;
168 }
169 /*---------------------------------------------------------------------------*/
170 int
171 coap_endpoint_cmp(const coap_endpoint_t *e1, const coap_endpoint_t *e2)
172 {
173  if(!uip_ipaddr_cmp(&e1->ipaddr, &e2->ipaddr)) {
174  return 0;
175  }
176  return e1->port == e2->port && e1->secure == e2->secure;
177 }
178 /*---------------------------------------------------------------------------*/
179 static int
180 index_of(const char *data, int offset, int len, uint8_t c)
181 {
182  if(offset < 0) {
183  return offset;
184  }
185  for(; offset < len; offset++) {
186  if(data[offset] == c) {
187  return offset;
188  }
189  }
190  return -1;
191 }
192 /*---------------------------------------------------------------------------*/
193 static int
194 get_port(const char *inbuf, size_t len, uint32_t *value)
195 {
196  int i;
197  *value = 0;
198  for(i = 0; i < len; i++) {
199  if(inbuf[i] >= '0' && inbuf[i] <= '9') {
200  *value = *value * 10 + (inbuf[i] - '0');
201  } else {
202  break;
203  }
204  }
205  return i;
206 }
207 /*---------------------------------------------------------------------------*/
208 int
209 coap_endpoint_parse(const char *text, size_t size, coap_endpoint_t *ep)
210 {
211  /* Only IPv6 supported */
212  int start = index_of(text, 0, size, '[');
213  int end = index_of(text, start, size, ']');
214  uint32_t port;
215 
216  ep->secure = strncmp(text, "coaps:", 6) == 0;
217  if(start >= 0 && end > start &&
218  uiplib_ipaddrconv(&text[start], &ep->ipaddr)) {
219  if(text[end + 1] == ':' &&
220  get_port(text + end + 2, size - end - 2, &port)) {
221  ep->port = UIP_HTONS(port);
222  } else if(ep->secure) {
223  /* Use secure CoAP port by default for secure endpoints. */
224  ep->port = SERVER_LISTEN_SECURE_PORT;
225  } else {
226  ep->port = SERVER_LISTEN_PORT;
227  }
228  return 1;
229  } else if(size < UIPLIB_IPV6_MAX_STR_LEN) {
230  char buf[UIPLIB_IPV6_MAX_STR_LEN];
231  memcpy(buf, text, size);
232  buf[size] = '\0';
233  if(uiplib_ipaddrconv(buf, &ep->ipaddr)) {
234  ep->port = SERVER_LISTEN_PORT;
235  return 1;
236  }
237  }
238  return 0;
239 }
240 /*---------------------------------------------------------------------------*/
241 static const coap_endpoint_t *
242 get_src_endpoint(uint8_t secure)
243 {
244  static coap_endpoint_t src;
245  uip_ipaddr_copy(&src.ipaddr, &UIP_IP_BUF->srcipaddr);
246  src.port = UIP_UDP_BUF->srcport;
247  src.secure = secure;
248  return &src;
249 }
250 /*---------------------------------------------------------------------------*/
251 int
252 coap_endpoint_is_secure(const coap_endpoint_t *ep)
253 {
254  return ep->secure;
255 }
256 /*---------------------------------------------------------------------------*/
257 int
258 coap_endpoint_is_connected(const coap_endpoint_t *ep)
259 {
260 #ifndef CONTIKI_TARGET_NATIVE
261  if(!uip_is_addr_linklocal(&ep->ipaddr)
262  && NETSTACK_ROUTING.node_is_reachable() == 0) {
263  return 0;
264  }
265 #endif
266 
267 #ifdef WITH_DTLS
268  if(ep != NULL && ep->secure != 0) {
269  dtls_peer_t *peer;
270  if(dtls_context == NULL) {
271  return 0;
272  }
273  peer = dtls_get_peer(dtls_context, ep);
274  if(peer != NULL) {
275  /* only if handshake is done! */
276  LOG_DBG("DTLS peer state for ");
277  LOG_DBG_COAP_EP(ep);
278  LOG_DBG_(" is %d (%sconnected)\n", peer->state,
279  dtls_peer_is_connected(peer) ? "" : "not ");
280  return dtls_peer_is_connected(peer);
281  } else {
282  LOG_DBG("DTLS did not find peer ");
283  LOG_DBG_COAP_EP(ep);
284  LOG_DBG_("\n");
285  return 0;
286  }
287  }
288 #endif /* WITH_DTLS */
289 
290  /* Assume connected */
291  return 1;
292 }
293 /*---------------------------------------------------------------------------*/
294 int
295 coap_endpoint_connect(coap_endpoint_t *ep)
296 {
297  if(ep->secure == 0) {
298  LOG_DBG("connect to ");
299  LOG_DBG_COAP_EP(ep);
300  LOG_DBG_("\n");
301  return 1;
302  }
303 
304 #ifdef WITH_DTLS
305  LOG_DBG("DTLS connect to ");
306  LOG_DBG_COAP_EP(ep);
307  LOG_DBG_("\n");
308 
309  /* setup all address info here... should be done to connect */
310  if(dtls_context) {
311  dtls_connect(dtls_context, ep);
312  return 1;
313  }
314 #endif /* WITH_DTLS */
315 
316  return 0;
317 }
318 /*---------------------------------------------------------------------------*/
319 void
320 coap_endpoint_disconnect(coap_endpoint_t *ep)
321 {
322 #ifdef WITH_DTLS
323  if(ep && ep->secure && dtls_context) {
324  dtls_close(dtls_context, ep);
325  }
326 #endif /* WITH_DTLS */
327 }
328 /*---------------------------------------------------------------------------*/
329 uint8_t *
331 {
332  return uip_appdata;
333 }
334 /*---------------------------------------------------------------------------*/
335 void
337 {
338  process_start(&coap_engine, NULL);
339 #ifdef WITH_DTLS
340  dtls_init();
341 
342 #if COAP_DTLS_KEYSTORE_CONF_WITH_SIMPLE
344 #endif /* COAP_DTLS_KEYSTORE_CONF_WITH_SIMPLE */
345 
346 #endif /* WITH_DTLS */
347 }
348 /*---------------------------------------------------------------------------*/
349 #ifdef WITH_DTLS
350 static void
351 process_secure_data(void)
352 {
353  LOG_INFO("receiving secure UDP datagram from [");
354  LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr);
355  LOG_INFO_("]:%u\n", uip_ntohs(UIP_UDP_BUF->srcport));
356  LOG_INFO(" Length: %u\n", uip_datalen());
357 
358  if(dtls_context) {
359  dtls_handle_message(dtls_context, (coap_endpoint_t *)get_src_endpoint(1),
361  }
362 }
363 #endif /* WITH_DTLS */
364 /*---------------------------------------------------------------------------*/
365 static void
366 process_data(void)
367 {
368  LOG_INFO("receiving UDP datagram from [");
369  LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr);
370  LOG_INFO_("]:%u\n", uip_ntohs(UIP_UDP_BUF->srcport));
371  LOG_INFO(" Length: %u\n", uip_datalen());
372 
373  coap_receive(get_src_endpoint(0), uip_appdata, uip_datalen());
374 }
375 /*---------------------------------------------------------------------------*/
376 int
377 coap_sendto(const coap_endpoint_t *ep, const uint8_t *data, uint16_t length)
378 {
379  if(ep == NULL) {
380  LOG_WARN("failed to send - no endpoint\n");
381  return -1;
382  }
383 
384  if(!coap_endpoint_is_connected(ep)) {
385  LOG_WARN("endpoint ");
386  LOG_WARN_COAP_EP(ep);
387  LOG_WARN_(" not connected - dropping packet\n");
388  return -1;
389  }
390 
391 #ifdef WITH_DTLS
392  if(coap_endpoint_is_secure(ep)) {
393  if(dtls_context) {
394  int ret;
395 
396  ret = dtls_write(dtls_context, (session_t *)ep, (uint8_t *)data, length);
397  LOG_INFO("sent DTLS to ");
398  LOG_INFO_COAP_EP(ep);
399  if(ret < 0) {
400  LOG_INFO_(" - error %d\n", ret);
401  } else {
402  LOG_INFO_(" %d/%u bytes\n", ret, length);
403  }
404  return ret;
405  } else {
406  LOG_WARN("no DTLS context\n");
407  return -1;
408  }
409  }
410 #endif /* WITH_DTLS */
411 
412  uip_udp_packet_sendto(udp_conn, data, length, &ep->ipaddr, ep->port);
413  LOG_INFO("sent to ");
414  LOG_INFO_COAP_EP(ep);
415  LOG_INFO_(" %u bytes\n", length);
416  return length;
417 }
418 /*---------------------------------------------------------------------------*/
419 PROCESS_THREAD(coap_engine, ev, data)
420 {
421  PROCESS_BEGIN();
422 
423  /* new connection with remote host */
424  udp_conn = udp_new(NULL, 0, NULL);
425  udp_bind(udp_conn, SERVER_LISTEN_PORT);
426  LOG_INFO("Listening on port %u\n", uip_ntohs(udp_conn->lport));
427 
428 #ifdef WITH_DTLS
429  /* create new context with app-data */
430  dtls_conn = udp_new(NULL, 0, NULL);
431  if(dtls_conn != NULL) {
432  udp_bind(dtls_conn, SERVER_LISTEN_SECURE_PORT);
433  LOG_INFO("DTLS listening on port %u\n", uip_ntohs(dtls_conn->lport));
434  dtls_context = dtls_new_context(dtls_conn);
435  }
436  if(!dtls_context) {
437  LOG_WARN("DTLS: cannot create context\n");
438  } else {
439  dtls_set_handler(dtls_context, &cb);
440  }
441 #endif /* WITH_DTLS */
442 
443  while(1) {
444  PROCESS_YIELD();
445 
446  if(ev == tcpip_event) {
447  if(uip_newdata()) {
448 #ifdef WITH_DTLS
449  if(uip_udp_conn == dtls_conn) {
450  process_secure_data();
451  continue;
452  }
453 #endif /* WITH_DTLS */
454  process_data();
455  }
456  }
457  } /* while (1) */
458 
459  PROCESS_END();
460 }
461 /*---------------------------------------------------------------------------*/
462 
463 /* DTLS */
464 #ifdef WITH_DTLS
465 
466 /* This is input coming from the DTLS code - e.g. de-crypted input from
467  the other side - peer */
468 static int
469 input_from_peer(struct dtls_context_t *ctx,
470  session_t *session, uint8_t *data, size_t len)
471 {
472  size_t i;
473 
474  if(LOG_DBG_ENABLED) {
475  LOG_DBG("received DTLS data:");
476  for(i = 0; i < len; i++) {
477  LOG_DBG_("%c", data[i]);
478  }
479  LOG_DBG_("\n");
480  LOG_DBG("Hex:");
481  for(i = 0; i < len; i++) {
482  LOG_DBG_("%02x", data[i]);
483  }
484  LOG_DBG_("\n");
485  }
486 
487  /* Ensure that the endpoint is tagged as secure */
488  session->secure = 1;
489 
490  coap_receive(session, data, len);
491 
492  return 0;
493 }
494 
495 /* This is output from the DTLS code to be sent to peer (encrypted) */
496 static int
497 output_to_peer(struct dtls_context_t *ctx,
498  session_t *session, uint8_t *data, size_t len)
499 {
500  struct uip_udp_conn *udp_connection = dtls_get_app_data(ctx);
501  LOG_DBG("output_to DTLS peer [");
502  LOG_DBG_6ADDR(&session->ipaddr);
503  LOG_DBG_("]:%u %ld bytes\n", uip_ntohs(session->port), (long)len);
504  uip_udp_packet_sendto(udp_connection, data, len,
505  &session->ipaddr, session->port);
506  return len;
507 }
508 
509 /* This defines the key-store set API since we hookup DTLS here */
510 void
511 coap_set_keystore(const coap_keystore_t *keystore)
512 {
513  dtls_keystore = keystore;
514 }
515 
516 /* This function is the "key store" for tinyDTLS. It is called to
517  * retrieve a key for the given identity within this particular
518  * session. */
519 static int
520 get_psk_info(struct dtls_context_t *ctx,
521  const session_t *session,
522  dtls_credentials_type_t type,
523  const unsigned char *id, size_t id_len,
524  unsigned char *result, size_t result_length)
525 {
527 
528  if(dtls_keystore == NULL) {
529  LOG_DBG("--- No key store available ---\n");
530  return 0;
531  }
532 
533  memset(&ks, 0, sizeof(ks));
534  LOG_DBG("---===>>> Getting the Key or ID <<<===---\n");
535  switch(type) {
536  case DTLS_PSK_IDENTITY:
537  if(id && id_len) {
538  ks.identity_hint = id;
539  ks.identity_hint_len = id_len;
540  LOG_DBG("got psk_identity_hint: '");
541  LOG_DBG_COAP_STRING((const char *)id, id_len);
542  LOG_DBG_("'\n");
543  }
544 
545  if(dtls_keystore->coap_get_psk_info) {
546  /* we know that session is a coap endpoint */
547  dtls_keystore->coap_get_psk_info((coap_endpoint_t *)session, &ks);
548  }
549  if(ks.identity == NULL || ks.identity_len == 0) {
550  LOG_DBG("no psk_identity found\n");
551  return 0;
552  }
553 
554  if(result_length < ks.identity_len) {
555  LOG_DBG("cannot return psk_identity -- buffer too small\n");
556  return dtls_alert_fatal_create(DTLS_ALERT_INTERNAL_ERROR);
557  }
558  memcpy(result, ks.identity, ks.identity_len);
559  LOG_DBG("psk_identity with %u bytes found\n", ks.identity_len);
560  return ks.identity_len;
561 
562  case DTLS_PSK_KEY:
563  if(dtls_keystore->coap_get_psk_info) {
564  ks.identity = id;
565  ks.identity_len = id_len;
566  /* we know that session is a coap endpoint */
567  dtls_keystore->coap_get_psk_info((coap_endpoint_t *)session, &ks);
568  }
569  if(ks.key == NULL || ks.key_len == 0) {
570  LOG_DBG("PSK for unknown id requested, exiting\n");
571  return dtls_alert_fatal_create(DTLS_ALERT_ILLEGAL_PARAMETER);
572  }
573 
574  if(result_length < ks.key_len) {
575  LOG_DBG("cannot return psk -- buffer too small\n");
576  return dtls_alert_fatal_create(DTLS_ALERT_INTERNAL_ERROR);
577  }
578  memcpy(result, ks.key, ks.key_len);
579  LOG_DBG("psk with %u bytes found\n", ks.key_len);
580  return ks.key_len;
581 
582  default:
583  LOG_WARN("unsupported key store request type: %d\n", type);
584  }
585 
586  return dtls_alert_fatal_create(DTLS_ALERT_INTERNAL_ERROR);
587 }
588 
589 
590 static dtls_handler_t cb = {
591  .write = output_to_peer,
592  .read = input_from_peer,
593  .event = NULL,
594 #ifdef DTLS_PSK
595  .get_psk_info = get_psk_info,
596 #endif /* DTLS_PSK */
597 #ifdef DTLS_ECC
598  /* .get_ecdsa_key = get_ecdsa_key, */
599  /* .verify_ecdsa_key = verify_ecdsa_key */
600 #endif /* DTLS_ECC */
601 };
602 
603 #endif /* WITH_DTLS */
604 /*---------------------------------------------------------------------------*/
605 /** @} */
606 /** @} */
Log support for CoAP
int coap_endpoint_connect(coap_endpoint_t *ep)
Request a connection to a CoAP endpoint.
Definition: coap-uip.c:295
#define UIP_IP_BUF
Pointer to IP header.
Definition: uip-nd6.c:97
void coap_endpoint_print(const coap_endpoint_t *ep)
Print a CoAP endpoint.
Definition: coap-uip.c:118
#define PROCESS(name, strname)
Declare a process.
Definition: process.h:307
void coap_endpoint_log(const coap_endpoint_t *ep)
Print a CoAP endpoint via the logging module.
Definition: coap-uip.c:102
void coap_endpoint_copy(coap_endpoint_t *destination, const coap_endpoint_t *from)
Copy a CoAP endpoint from one memory area to another.
Definition: coap-uip.c:162
API to address CoAP endpoints
static bool start(void)
Start measurement.
A simple keystore with fixed credentials.
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition: process.h:120
CoAP engine implementation.
#define PROCESS_END()
Define the end of a process.
Definition: process.h:131
process_event_t tcpip_event
The uIP event.
Definition: tcpip.c:66
int coap_endpoint_snprint(char *buf, size_t size, const coap_endpoint_t *ep)
Print a CoAP endpoint to a string.
Definition: coap-uip.c:134
Header file for module for sending UDP packets through uIP.
uint16_t lport
The local port number in network byte order.
Definition: uip.h:1399
int coap_endpoint_is_connected(const coap_endpoint_t *ep)
Check if a CoAP endpoint is connected.
Definition: coap-uip.c:258
Header file for the IP address manipulation library.
#define uip_newdata()
Is new incoming data available?
Definition: uip.h:729
The structure of a CoAP keystore.
Definition: coap-keystore.h:75
void coap_set_keystore(const coap_keystore_t *keystore)
Set the CoAP keystore to use by CoAP.
struct uip_udp_conn * udp_new(const uip_ipaddr_t *ripaddr, uint16_t port, void *appstate)
Create a new UDP connection.
Definition: tcpip.c:265
int coap_sendto(const coap_endpoint_t *ep, const uint8_t *data, uint16_t length)
Send a message to the specified CoAP endpoint.
Definition: coap-uip.c:377
Routing driver header file
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
Definition: uip.h:1018
int coap_endpoint_parse(const char *text, size_t size, coap_endpoint_t *ep)
Parse a CoAP endpoint.
Definition: coap-uip.c:209
uint8_t * coap_databuf(void)
Returns a common data buffer that can be used when generating CoAP messages for transmission.
Definition: coap-uip.c:330
#define PROCESS_YIELD()
Yield the currently running process.
Definition: process.h:164
void coap_transport_init(void)
Initialize the CoAP transport.
Definition: coap-uip.c:336
The structure of a CoAP pre-shared key info.
Definition: coap-keystore.h:59
void log_6addr(const uip_ipaddr_t *ipaddr)
Logs an IPv6 address.
Definition: log.c:87
#define UIP_HTONS(n)
Convert 16-bit quantity from host byte order to network byte order.
Definition: uip.h:1230
int coap_endpoint_cmp(const coap_endpoint_t *e1, const coap_endpoint_t *e2)
Compare two CoAP endpoints.
Definition: coap-uip.c:171
void coap_endpoint_disconnect(coap_endpoint_t *ep)
Request that any connection to a CoAP endpoint is discontinued.
Definition: coap-uip.c:320
int coap_endpoint_is_secure(const coap_endpoint_t *ep)
Check if a CoAP endpoint is secure (encrypted).
Definition: coap-uip.c:252
void coap_keystore_simple_init(void)
Registers a simple CoAP DTLS keystore with fixed pre-shared key credentials.
void uiplib_ipaddr_print(const uip_ipaddr_t *addr)
Print an IP address using printf().
Definition: uiplib.c:160
API for CoAP keystore
CoAP module for reliable transport
An implementation of the Constrained Application Protocol (RFC 7252).
PROCESS_THREAD(cc2538_rf_process, ev, data)
Implementation of the cc2538 RF driver process.
Definition: cc2538-rf.c:1035
#define uiplib_ipaddrconv
Convert a textual representation of an IP address to a numerical representation.
Definition: uiplib.h:72
#define uip_is_addr_linklocal(a)
is addr (a) a link local unicast address, see RFC 4291 i.e.
Definition: uip.h:2023
#define udp_bind(conn, port)
Bind a UDP connection to a local port.
Definition: tcpip.h:261
void * uip_appdata
Pointer to the application data in the packet buffer.
Definition: uip6.c:168
int(* node_is_reachable)(void)
Tells whether the node is currently reachable as part of the network.
Definition: routing.h:107
Collection of constants specified in the CoAP standard.
#define uip_datalen()
The length of any incoming data that is currently available (if available) in the uip_appdata buffer...
Definition: uip.h:642
void process_start(struct process *p, process_data_t data)
Start a process.
Definition: process.c:99
Representation of a uIP UDP connection.
Definition: uip.h:1397
API for CoAP transport
int uiplib_ipaddr_snprint(char *buf, size_t size, const uip_ipaddr_t *addr)
Write at most size - 1 characters of the IP address to the output string.
Definition: uiplib.c:168