uuid.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2014 Samsung Electronics
  4. * Przemyslaw Marczak <p.marczak@samsung.com>
  5. * Copyright 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
  6. *
  7. * Authors:
  8. * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
  9. */
  10. #ifndef __UUID_H__
  11. #define __UUID_H__
  12. #include <linux/bitops.h>
  13. /* This is structure is in big-endian */
  14. struct uuid {
  15. unsigned int time_low;
  16. unsigned short time_mid;
  17. unsigned short time_hi_and_version;
  18. unsigned char clock_seq_hi_and_reserved;
  19. unsigned char clock_seq_low;
  20. unsigned char node[6];
  21. } __packed;
  22. /* Bits of a bitmask specifying the output format for GUIDs */
  23. #define UUID_STR_FORMAT_STD 0
  24. #define UUID_STR_FORMAT_GUID BIT(0)
  25. #define UUID_STR_UPPER_CASE BIT(1)
  26. /* Use UUID_STR_LEN + 1 for string space */
  27. #define UUID_STR_LEN 36
  28. #define UUID_BIN_LEN sizeof(struct uuid)
  29. #define UUID_VERSION_MASK 0xf000
  30. #define UUID_VERSION_SHIFT 12
  31. #define UUID_VERSION 0x4
  32. #define UUID_VARIANT_MASK 0xc0
  33. #define UUID_VARIANT_SHIFT 7
  34. #define UUID_VARIANT 0x1
  35. int uuid_str_valid(const char *uuid);
  36. int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin,
  37. int str_format);
  38. void uuid_bin_to_str(const unsigned char *uuid_bin, char *uuid_str,
  39. int str_format);
  40. int uuid_guid_get_bin(const char *guid_str, unsigned char *guid_bin);
  41. const char *uuid_guid_get_str(const unsigned char *guid_bin);
  42. void gen_rand_uuid(unsigned char *uuid_bin);
  43. void gen_rand_uuid_str(char *uuid_str, int str_format);
  44. /**
  45. * uuid_str_to_le_bin() - Convert string UUID to little endian binary data.
  46. * @uuid_str: pointer to UUID string
  47. * @uuid_bin: pointer to allocated array for little endian output [16B]
  48. * Return:
  49. * uuid_bin filled with little endian UUID data
  50. * On success 0 is returned. Otherwise, failure code.
  51. */
  52. int uuid_str_to_le_bin(const char *uuid_str, unsigned char *uuid_bin);
  53. #endif