/* * Copyright (C) 2019 Kaspar Schleiser * 2019 Inria * 2019 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level * directory for more details. */ /** * @ingroup sys_suit * @defgroup sys_suit_transport_coap SUIT firmware CoAP transport * @brief SUIT secure firmware updates over CoAP * * @{ * * @brief SUIT CoAP helper API * @author Kaspar Schleiser * @author Francisco Molina * @author Alexandre Abadie * */ #ifndef SUIT_TRANSPORT_COAP_H #define SUIT_TRANSPORT_COAP_H #include "net/nanocoap.h" #ifdef __cplusplus extern "C" { #endif /** * @brief Start SUIT CoAP thread */ void suit_coap_run(void); /** * @brief SUIT CoAP endpoint entry. * * In order to use, include this header, then add SUIT_COAP_SUBTREE to the nanocoap endpoint array. * Mind the alphanumerical sorting! * * See examples/suit_update for an example. */ #define SUIT_COAP_SUBTREE \ { \ .path="/suit/", \ .methods=COAP_MATCH_SUBTREE | COAP_METHOD_GET | COAP_METHOD_POST | COAP_METHOD_PUT, \ .handler=coap_subtree_handler, \ .context=(void*)&coap_resource_subtree_suit \ } /* * Dear Reviewer, * * At the time of PR'ing this code, there was a pile of CoAP PR's waiting for * reviews. Some of that functionality is needed in one way or another for * SUIT. In order to not block software updates with CoAP refactoring, some of * the work-in-progress code has been copied here. We expect this to be * removed as soon as CoAP in master provides similar functionality. * * As this is internal code that will go soon, I exclude this from Doxygen. * * Kaspar (July 2019) */ #ifndef DOXYGEN /** * @brief Coap subtree handler * * @param[in,out] pkt Packet struct containing the request. Is reused for * the response * @param[in] buf Buffer to write reply to * @param[in] len Total length of the buffer associated with the * request * @param[in] buf Buffer to write reply to * * @returns ssize_t Size of the reply */ ssize_t coap_subtree_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len, void *context); /** * @brief Type for CoAP resource subtrees */ typedef const struct { const coap_resource_t *resources; /**< ptr to resource array */ const size_t resources_numof; /**< nr of entries in array */ } coap_resource_subtree_t; /** * @brief Reference to the coap resource subtree */ extern const coap_resource_subtree_t coap_resource_subtree_suit; /** * @brief Coap block-wise-transfer size used for SUIT */ #ifndef CONFIG_SUIT_COAP_BLOCKSIZE #define CONFIG_SUIT_COAP_BLOCKSIZE COAP_BLOCKSIZE_64 #endif /** * @brief Trigger a SUIT udate * * @param[in] url url pointer containing the full coap url to the manifest * @param[in] len length of the url */ void suit_coap_trigger(const uint8_t *url, size_t len); #endif /* DOXYGEN */ #ifdef __cplusplus } #endif #endif /* SUIT_TRANSPORT_COAP_H */ /** @} */