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>
This commit is contained in:
Vinicius Costa Gomes 2016-10-03 11:09:14 -03:00 committed by Jukka Rissanen
parent dc45748d50
commit ea28e4fccb
2 changed files with 16 additions and 0 deletions

View file

@ -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;
}

View file

@ -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__ */