summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorVinicius Costa Gomes <vinicius.gomes@intel.com>2016-11-04 18:31:15 -0200
committerJukka Rissanen <jukka.rissanen@linux.intel.com>2016-12-02 12:41:05 +0200
commitec184107befbdf2c0121974401f8b28746fba948 (patch)
tree6f8e7c090b40fbc6923697b0acbf1ddd55d79549 /lib
parent1d86b236afa5129e0263b6ccc34599415f7c175c (diff)
zoap: Add support for retrieving the underlying net_buf
Add an alternative to zoap_packet_get_payload(), that instead of returning a byte array, returns the net_buf (with the COAP_MARKER added, if needed) associated with the packet, positioned so the application can add more data. Change-Id: I7c955ef42f5ef8406d77da994d1673e6a69b0b6b Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/iot/zoap/zoap.c14
-rw-r--r--lib/iot/zoap/zoap.h6
2 files changed, 20 insertions, 0 deletions
diff --git a/lib/iot/zoap/zoap.c b/lib/iot/zoap/zoap.c
index 430d50e0a..fd479236e 100644
--- a/lib/iot/zoap/zoap.c
+++ b/lib/iot/zoap/zoap.c
@@ -795,6 +795,20 @@ int zoap_packet_set_used(struct zoap_packet *pkt, uint16_t len)
return 0;
}
+struct net_buf *zoap_packet_get_buf(struct zoap_packet *pkt)
+{
+ struct net_buf *frag = pkt->buf->frags;
+ uint8_t *str;
+
+ if (!pkt->start) {
+ str = net_buf_add(frag, 1);
+ *str = COAP_MARKER;
+ pkt->start = str + 1;
+ }
+
+ return frag;
+}
+
int zoap_add_option(struct zoap_packet *pkt, uint16_t code,
const void *value, uint16_t len)
{
diff --git a/lib/iot/zoap/zoap.h b/lib/iot/zoap/zoap.h
index 451c61428..2d5251136 100644
--- a/lib/iot/zoap/zoap.h
+++ b/lib/iot/zoap/zoap.h
@@ -371,6 +371,12 @@ bool zoap_request_is_observe(const struct zoap_packet *request);
uint8_t *zoap_packet_get_payload(struct zoap_packet *pkt, uint16_t *len);
/**
+ * Returns the internal buffer of the CoAP packet, appending the
+ * COAP_MARKER to the buffer if necessary.
+ */
+struct net_buf *zoap_packet_get_buf(struct zoap_packet *pkt);
+
+/**
* Sets how much space was used by the payload.
*/
int zoap_packet_set_used(struct zoap_packet *pkt, uint16_t len);