diff --git a/sys/include/net/nanocoap_sock.h b/sys/include/net/nanocoap_sock.h index 9594323f9c54..9af486c206cc 100644 --- a/sys/include/net/nanocoap_sock.h +++ b/sys/include/net/nanocoap_sock.h @@ -633,6 +633,29 @@ ssize_t nanocoap_get_blockwise_url_to_buf(const char *url, coap_blksize_t blksize, void *buf, size_t len); +/** + * @brief Performs a blockwise CoAP GET request, store the response + * in a buffer. + * + * This function will fetch the content of the specified resource path via + * block-wise-transfer. + * The blocks will be re-assembled into @p buf + * + * @param[in] sock socket to use for the request + * @param[in] path pointer to source path + * @param[in] blksize sender suggested SZX for the COAP block request + * @param[in] buf Target buffer + * @param[in] len Target buffer length + * + * @returns <0 on error + * @returns -EINVAL if an invalid url is provided + * @returns -ENOBUFS if the provided buffer was too small + * @returns size of the response payload on success + */ +ssize_t nanocoap_get_blockwise_to_buf(nanocoap_sock_t *sock, const char *path, + coap_blksize_t blksize, + void *buf, size_t len); + /** * @brief Simple synchronous CoAP request * diff --git a/sys/net/application_layer/nanocoap/sock.c b/sys/net/application_layer/nanocoap/sock.c index 20d5c369540b..157ee3097e21 100644 --- a/sys/net/application_layer/nanocoap/sock.c +++ b/sys/net/application_layer/nanocoap/sock.c @@ -826,6 +826,17 @@ ssize_t nanocoap_get_blockwise_url_to_buf(const char *url, return (res < 0) ? (ssize_t)res : (ssize_t)_buf.len; } +ssize_t nanocoap_get_blockwise_to_buf(nanocoap_sock_t *sock, const char *path, + coap_blksize_t blksize, + void *buf, size_t len) +{ + _buf_t _buf = { .ptr = buf, .len = len }; + + int res = nanocoap_sock_get_blockwise(sock, path, blksize, _2buf, &_buf); + + return (res < 0) ? (ssize_t)res : (ssize_t)_buf.len; +} + int nanocoap_server(sock_udp_ep_t *local, uint8_t *buf, size_t bufsize) { sock_udp_t sock;