blob: 89b93e642b730ae9a57dcd33a3bf6a3de57dac50 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Przemyslaw Marczak0c813362014-04-02 10:20:03 +02002/*
3 * Copyright (C) 2014 Samsung Electronics
4 * Przemyslaw Marczak <p.marczak@samsung.com>
Abdellatif El Khlifidc3cb5d2023-08-04 14:33:38 +01005 * 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>
Przemyslaw Marczak0c813362014-04-02 10:20:03 +02009 */
10#ifndef __UUID_H__
11#define __UUID_H__
12
Heinrich Schuchardt6f035662019-04-29 08:08:43 +020013#include <linux/bitops.h>
14
Przemyslaw Marczakb4285142014-04-02 10:20:04 +020015/* This is structure is in big-endian */
16struct 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
Heinrich Schuchardt6f035662019-04-29 08:08:43 +020025/* 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)
Przemyslaw Marczak0c813362014-04-02 10:20:03 +020029
Simon Glass4ab17ee2021-01-13 20:29:51 -070030/* Use UUID_STR_LEN + 1 for string space */
Przemyslaw Marczak0c813362014-04-02 10:20:03 +020031#define UUID_STR_LEN 36
Przemyslaw Marczakb4285142014-04-02 10:20:04 +020032#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
Przemyslaw Marczak0c813362014-04-02 10:20:03 +020041
42int uuid_str_valid(const char *uuid);
Simon Glass4acd4f02020-04-08 08:32:58 -060043int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin,
44 int str_format);
45void uuid_bin_to_str(const unsigned char *uuid_bin, char *uuid_str,
46 int str_format);
Patrick Delaunay65f94ed2015-10-27 11:00:28 +010047int uuid_guid_get_bin(const char *guid_str, unsigned char *guid_bin);
Rasmus Villemoes7b70bdc2020-11-20 11:45:35 +010048const char *uuid_guid_get_str(const unsigned char *guid_bin);
Przemyslaw Marczakb4285142014-04-02 10:20:04 +020049void gen_rand_uuid(unsigned char *uuid_bin);
50void gen_rand_uuid_str(char *uuid_str, int str_format);
Abdellatif El Khlifidc3cb5d2023-08-04 14:33:38 +010051
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 */
60int uuid_str_to_le_bin(const char *uuid_str, unsigned char *uuid_bin);
61
Przemyslaw Marczak0c813362014-04-02 10:20:03 +020062#endif