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> |
Abdellatif El Khlifi | dc3cb5d | 2023-08-04 14:33:38 +0100 | [diff] [blame] | 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> |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 9 | */ |
| 10 | #ifndef __UUID_H__ |
| 11 | #define __UUID_H__ |
| 12 | |
Heinrich Schuchardt | 6f03566 | 2019-04-29 08:08:43 +0200 | [diff] [blame] | 13 | #include <linux/bitops.h> |
| 14 | |
Przemyslaw Marczak | b428514 | 2014-04-02 10:20:04 +0200 | [diff] [blame] | 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 | |
Heinrich Schuchardt | 6f03566 | 2019-04-29 08:08:43 +0200 | [diff] [blame] | 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) |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 29 | |
Simon Glass | 4ab17ee | 2021-01-13 20:29:51 -0700 | [diff] [blame] | 30 | /* Use UUID_STR_LEN + 1 for string space */ |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 31 | #define UUID_STR_LEN 36 |
Przemyslaw Marczak | b428514 | 2014-04-02 10:20:04 +0200 | [diff] [blame] | 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 |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 41 | |
| 42 | int uuid_str_valid(const char *uuid); |
Simon Glass | 4acd4f0 | 2020-04-08 08:32:58 -0600 | [diff] [blame] | 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); |
Patrick Delaunay | 65f94ed | 2015-10-27 11:00:28 +0100 | [diff] [blame] | 47 | 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] | 48 | const char *uuid_guid_get_str(const unsigned char *guid_bin); |
Przemyslaw Marczak | b428514 | 2014-04-02 10:20:04 +0200 | [diff] [blame] | 49 | void gen_rand_uuid(unsigned char *uuid_bin); |
| 50 | void gen_rand_uuid_str(char *uuid_str, int str_format); |
Abdellatif El Khlifi | dc3cb5d | 2023-08-04 14:33:38 +0100 | [diff] [blame] | 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 | |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 62 | #endif |