Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2014 Samsung Electronics |
| 4 | * Przemyslaw Marczak <p.marczak@samsung.com> |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 5 | */ |
| 6 | #ifndef __UUID_H__ |
| 7 | #define __UUID_H__ |
| 8 | |
Heinrich Schuchardt | 6f03566 | 2019-04-29 08:08:43 +0200 | [diff] [blame] | 9 | #include <linux/bitops.h> |
| 10 | |
Przemyslaw Marczak | b428514 | 2014-04-02 10:20:04 +0200 | [diff] [blame] | 11 | /* This is structure is in big-endian */ |
| 12 | struct uuid { |
| 13 | unsigned int time_low; |
| 14 | unsigned short time_mid; |
| 15 | unsigned short time_hi_and_version; |
| 16 | unsigned char clock_seq_hi_and_reserved; |
| 17 | unsigned char clock_seq_low; |
| 18 | unsigned char node[6]; |
| 19 | } __packed; |
| 20 | |
Heinrich Schuchardt | 6f03566 | 2019-04-29 08:08:43 +0200 | [diff] [blame] | 21 | /* Bits of a bitmask specifying the output format for GUIDs */ |
| 22 | #define UUID_STR_FORMAT_STD 0 |
| 23 | #define UUID_STR_FORMAT_GUID BIT(0) |
| 24 | #define UUID_STR_UPPER_CASE BIT(1) |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 25 | |
Simon Glass | 4ab17ee | 2021-01-13 20:29:51 -0700 | [diff] [blame] | 26 | /* Use UUID_STR_LEN + 1 for string space */ |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 27 | #define UUID_STR_LEN 36 |
Przemyslaw Marczak | b428514 | 2014-04-02 10:20:04 +0200 | [diff] [blame] | 28 | #define UUID_BIN_LEN sizeof(struct uuid) |
| 29 | |
| 30 | #define UUID_VERSION_MASK 0xf000 |
| 31 | #define UUID_VERSION_SHIFT 12 |
| 32 | #define UUID_VERSION 0x4 |
| 33 | |
| 34 | #define UUID_VARIANT_MASK 0xc0 |
| 35 | #define UUID_VARIANT_SHIFT 7 |
| 36 | #define UUID_VARIANT 0x1 |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 37 | |
| 38 | int uuid_str_valid(const char *uuid); |
Simon Glass | 4acd4f0 | 2020-04-08 08:32:58 -0600 | [diff] [blame] | 39 | int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin, |
| 40 | int str_format); |
| 41 | void uuid_bin_to_str(const unsigned char *uuid_bin, char *uuid_str, |
| 42 | int str_format); |
Patrick Delaunay | 65f94ed | 2015-10-27 11:00:28 +0100 | [diff] [blame] | 43 | int uuid_guid_get_bin(const char *guid_str, unsigned char *guid_bin); |
Rasmus Villemoes | 7b70bdc | 2020-11-20 11:45:35 +0100 | [diff] [blame] | 44 | const char *uuid_guid_get_str(const unsigned char *guid_bin); |
Przemyslaw Marczak | b428514 | 2014-04-02 10:20:04 +0200 | [diff] [blame] | 45 | void gen_rand_uuid(unsigned char *uuid_bin); |
| 46 | void gen_rand_uuid_str(char *uuid_str, int str_format); |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 47 | #endif |