summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorVinicius Costa Gomes <vinicius.gomes@intel.com>2016-10-03 11:09:14 -0300
committerJukka Rissanen <jukka.rissanen@linux.intel.com>2016-12-02 12:40:50 +0200
commitea28e4fccb54f453a946713e4573db81d4b71e98 (patch)
treed76eb99db221a5524664d6f47ecd9e41d7379285 /lib
parentdc45748d508a81e1271831717223d143521bc9de (diff)
iot/zoap: Add helper for generating tokens
Most applications will want to use randomly generated tokens, add a helper for that. Change-Id: If2a6b1d96596024afd2d2ce8e3632900adfe9c0f Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/iot/zoap/zoap.c10
-rw-r--r--lib/iot/zoap/zoap.h6
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/iot/zoap/zoap.c b/lib/iot/zoap/zoap.c
index 59f6a32ec..430d50e0a 100644
--- a/lib/iot/zoap/zoap.c
+++ b/lib/iot/zoap/zoap.c
@@ -1275,3 +1275,13 @@ size_t zoap_next_block(struct zoap_block_context *ctx)
return ctx->current;
}
+
+uint8_t *zoap_next_token(void)
+{
+ static uint32_t rand[2];
+
+ rand[0] = sys_rand32_get();
+ rand[1] = sys_rand32_get();
+
+ return (uint8_t *) rand;
+}
diff --git a/lib/iot/zoap/zoap.h b/lib/iot/zoap/zoap.h
index 6c1ca2301..451c61428 100644
--- a/lib/iot/zoap/zoap.h
+++ b/lib/iot/zoap/zoap.h
@@ -543,4 +543,10 @@ static inline uint16_t zoap_next_id(void)
return ++message_id;
}
+/**
+ * Returns a randomly generated array of 8 bytes, that can be used as a
+ * message's token.
+ */
+uint8_t *zoap_next_token(void);
+
#endif /* __ZOAP_H__ */