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 
27 #ifndef SUIT_COAP_H
28 #define SUIT_COAP_H
29 
30 #include "net/nanocoap.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
39 void suit_coap_run(void);
40 
49 #define SUIT_COAP_SUBTREE \
50  { \
51  .path="/suit/", \
52  .methods=COAP_MATCH_SUBTREE | COAP_METHOD_GET | COAP_METHOD_POST | COAP_METHOD_PUT, \
53  .handler=coap_subtree_handler, \
54  .context=(void*)&coap_resource_subtree_suit \
55  }
56 
57 /*
58  * Dear Reviewer,
59  *
60  * At the time of PR'ing this code, there was a pile of CoAP PR's waiting for
61  * reviews. Some of that functionality is needed in one way or another for
62  * SUIT. In order to not block software updates with CoAP refactoring, some of
63  * the work-in-progress code has been copied here. We expect this to be
64  * removed as soon as CoAP in master provides similar functionality.
65  *
66  * As this is internal code that will go soon, I exclude this from Doxygen.
67  *
68  * Kaspar (July 2019)
69  */
70 #ifndef DOXYGEN
71 
84 ssize_t coap_subtree_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len,
85  void *context);
86 
90 typedef const struct {
91  const coap_resource_t *resources;
92  const size_t resources_numof;
93 } coap_resource_subtree_t;
94 
107 typedef int (*coap_blockwise_cb_t)(void *arg, size_t offset, uint8_t *buf, size_t len, int more);
108 
112 extern const coap_resource_subtree_t coap_resource_subtree_suit;
113 
117 typedef enum {
118  COAP_BLOCKSIZE_32 = 1,
119  COAP_BLOCKSIZE_64,
120  COAP_BLOCKSIZE_128,
121  COAP_BLOCKSIZE_256,
122  COAP_BLOCKSIZE_512,
123  COAP_BLOCKSIZE_1024,
124 } coap_blksize_t;
125 
142 int suit_coap_get_blockwise_url(const char *url,
143  coap_blksize_t blksize,
144  coap_blockwise_cb_t callback, void *arg);
145 
152 void suit_coap_trigger(const uint8_t *url, size_t len);
153 
154 #endif /* DOXYGEN */
155 
156 #ifdef __cplusplus
157 }
158 #endif
159 
160 #endif /* SUIT_COAP_H */
161 
Type for CoAP resource entry.
Definition: nanocoap.h:222
nanocoap API
void suit_coap_run(void)
Start SUIT CoAP thread.
CoAP PDU parsing context structure.
Definition: nanocoap.h:184