coap.h
1 /*
2  * Copyright (C) 2019 Kaspar Schleiser <kaspar@schleiser.de>
3  * 2019 Inria
4  * 2019 Freie Universität Berlin
5  *
6  * This file is subject to the terms and conditions of the GNU Lesser
7  * General Public License v2.1. See the file LICENSE in the top level
8  * directory for more details.
9  */
10 
25 #ifndef SUIT_TRANSPORT_COAP_H
26 #define SUIT_TRANSPORT_COAP_H
27 
28 #include "net/nanocoap.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
37 void suit_coap_run(void);
38 
47 #define SUIT_COAP_SUBTREE \
48  { \
49  .path="/suit/", \
50  .methods=COAP_MATCH_SUBTREE | COAP_METHOD_GET | COAP_METHOD_POST | COAP_METHOD_PUT, \
51  .handler=coap_subtree_handler, \
52  .context=(void*)&coap_resource_subtree_suit \
53  }
54 
55 /*
56  * Dear Reviewer,
57  *
58  * At the time of PR'ing this code, there was a pile of CoAP PR's waiting for
59  * reviews. Some of that functionality is needed in one way or another for
60  * SUIT. In order to not block software updates with CoAP refactoring, some of
61  * the work-in-progress code has been copied here. We expect this to be
62  * removed as soon as CoAP in master provides similar functionality.
63  *
64  * As this is internal code that will go soon, I exclude this from Doxygen.
65  *
66  * Kaspar (July 2019)
67  */
68 #ifndef DOXYGEN
69 
82 ssize_t coap_subtree_handler(coap_pkt_t *pkt, uint8_t *buf,
83  size_t len, void *context);
84 
88 typedef const struct {
89  const coap_resource_t *resources;
90  const size_t resources_numof;
91 } coap_resource_subtree_t;
92 
105 typedef int (*coap_blockwise_cb_t)(void *arg, size_t offset, uint8_t *buf, size_t len, int more);
106 
110 extern const coap_resource_subtree_t coap_resource_subtree_suit;
111 
115 typedef enum {
116  COAP_BLOCKSIZE_32 = 1,
117  COAP_BLOCKSIZE_64,
118  COAP_BLOCKSIZE_128,
119  COAP_BLOCKSIZE_256,
120  COAP_BLOCKSIZE_512,
121  COAP_BLOCKSIZE_1024,
122 } coap_blksize_t;
123 
140 int suit_coap_get_blockwise_url(const char *url,
141  coap_blksize_t blksize,
142  coap_blockwise_cb_t callback, void *arg);
143 
150 void suit_coap_trigger(const uint8_t *url, size_t len);
151 
152 #endif /* DOXYGEN */
153 
154 #ifdef __cplusplus
155 }
156 #endif
157 
158 #endif /* SUIT_TRANSPORT_COAP_H */
159 
nanocoap.h
nanocoap API
suit_coap_run
void suit_coap_run(void)
Start SUIT CoAP thread.
coap_resource_t
Type for CoAP resource entry.
Definition: nanocoap.h:223
coap_pkt_t
CoAP PDU parsing context structure.
Definition: nanocoap.h:185