Prepare v2023.10
[platform/kernel/u-boot.git] / include / uuid.h
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
13 #include <linux/bitops.h>
14
15 /* This is structure is in big-endian */
16 struct uuid {
17         unsigned int time_low;
18         unsigned short time_mid;
19         unsigned short time_hi_and_version;
20         unsigned char clock_seq_hi_and_reserved;
21         unsigned char clock_seq_low;
22         unsigned char node[6];
23 } __packed;
24
25 /* Bits of a bitmask specifying the output format for GUIDs */
26 #define UUID_STR_FORMAT_STD     0
27 #define UUID_STR_FORMAT_GUID    BIT(0)
28 #define UUID_STR_UPPER_CASE     BIT(1)
29
30 /* Use UUID_STR_LEN + 1 for string space */
31 #define UUID_STR_LEN            36
32 #define UUID_BIN_LEN            sizeof(struct uuid)
33
34 #define UUID_VERSION_MASK       0xf000
35 #define UUID_VERSION_SHIFT      12
36 #define UUID_VERSION            0x4
37
38 #define UUID_VARIANT_MASK       0xc0
39 #define UUID_VARIANT_SHIFT      7
40 #define UUID_VARIANT            0x1
41
42 int uuid_str_valid(const char *uuid);
43 int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin,
44                     int str_format);
45 void uuid_bin_to_str(const unsigned char *uuid_bin, char *uuid_str,
46                      int str_format);
47 int uuid_guid_get_bin(const char *guid_str, unsigned char *guid_bin);
48 const char *uuid_guid_get_str(const unsigned char *guid_bin);
49 void gen_rand_uuid(unsigned char *uuid_bin);
50 void gen_rand_uuid_str(char *uuid_str, int str_format);
51
52 /**
53  * uuid_str_to_le_bin() - Convert string UUID to little endian binary data.
54  * @uuid_str:   pointer to UUID string
55  * @uuid_bin:   pointer to allocated array for little endian output [16B]
56  * Return:
57  *    uuid_bin filled with little endian UUID data
58  *    On success 0 is returned. Otherwise, failure code.
59  */
60 int uuid_str_to_le_bin(const char *uuid_str, unsigned char *uuid_bin);
61
62 #endif