Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / resource / csdk / ocrandom / include / ocrandom.h
index d516520..c4d219e 100644 (file)
@@ -36,6 +36,17 @@ extern "C" {
 #define ANALOG_IN (10)
 #endif
 
+#define UUID_SIZE (16)
+// The characters are 36 long, 37 for the null-term
+#define UUID_STRING_SIZE (37)
+
+typedef enum
+{
+    RAND_UUID_OK = 0,
+    RAND_UUID_INVALID_PARAM = -1,
+    RAND_UUID_READ_ERROR = -2,
+    RAND_UUID_CONVERT_ERROR = -3
+} OCRandomUuidResult;
 /**
  * Seed the random number generator. Seeding depends on platform.
  * Android and Linux uses current time. Arduino uses Analog reading on pin ANALOG_IN
@@ -73,6 +84,46 @@ void OCFillRandomMem(uint8_t * location, uint16_t len);
  */
 uint32_t OCGetRandomRange(uint32_t firstBound, uint32_t secondBound);
 
+/**
+ * Generate a Uniformly Unique Identifier based on RFC4122 and
+ * provide it as a 16 byte byte-array
+ *
+ * @param[out] uuid
+ *               the 16 byte array to fill with the UUID data
+ *               of a new UUID
+ *
+ * @retval RAND_UUID_OK for success, otherwise an error value
+ */
+OCRandomUuidResult OCGenerateUuid(uint8_t uuid[UUID_SIZE]);
+
+/**
+ * Generate a Uniformly Unique Identifier based on RFC4122 and
+ * provide it as a C style string.
+ *
+ * @param[out] uuidString
+ *               a 37-byte length string to fill with the string
+ *               representation of a new UUID.  Size is 32 chars
+ *               for the hex data, 4 for '-' characters, and 1
+ *               for the NULL terminator
+ *
+ * @retval RAND_UUID_OK for success, otherwise an error value
+ */
+OCRandomUuidResult OCGenerateUuidString(char uuidString[UUID_STRING_SIZE]);
+
+/**
+ * Convert a UUID generated by OCGenerateUuid to a C style string
+ * based on RFC 4122
+ *
+ * @param[in]  uuid
+ *              The 16 byte array filled with UUID data by OCGenerateUuid
+ * @param[out] uuidString
+ *              a 37 byte length string to fill with the string
+ *              representation of the passed UUID.
+ * @retval RAND_UUID_OK for success, otherwise an error value
+ */
+OCRandomUuidResult OCConvertUuidToString(const uint8_t uuid[UUID_SIZE],
+        char uuidString[UUID_STRING_SIZE]);
+
 #ifdef __cplusplus
 }
 #endif