blob: abcc325eae9a2aed554158005ebc5b249a9dc27c [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Przemyslaw Marczakd718ded2014-04-02 10:20:03 +02002/*
3 * Copyright (C) 2014 Samsung Electronics
4 * Przemyslaw Marczak <p.marczak@samsung.com>
Przemyslaw Marczakd718ded2014-04-02 10:20:03 +02005 */
6#ifndef __UUID_H__
7#define __UUID_H__
8
Heinrich Schuchardt3bad2562019-04-29 08:08:43 +02009#include <linux/bitops.h>
10
Przemyslaw Marczak4e4815f2014-04-02 10:20:04 +020011/* This is structure is in big-endian */
12struct 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 Schuchardt3bad2562019-04-29 08:08:43 +020021/* 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 Marczakd718ded2014-04-02 10:20:03 +020025
26#define UUID_STR_LEN 36
Przemyslaw Marczak4e4815f2014-04-02 10:20:04 +020027#define UUID_BIN_LEN sizeof(struct uuid)
28
29#define UUID_VERSION_MASK 0xf000
30#define UUID_VERSION_SHIFT 12
31#define UUID_VERSION 0x4
32
33#define UUID_VARIANT_MASK 0xc0
34#define UUID_VARIANT_SHIFT 7
35#define UUID_VARIANT 0x1
Przemyslaw Marczakd718ded2014-04-02 10:20:03 +020036
37int uuid_str_valid(const char *uuid);
38int uuid_str_to_bin(char *uuid_str, unsigned char *uuid_bin, int str_format);
39void uuid_bin_to_str(unsigned char *uuid_bin, char *uuid_str, int str_format);
Patrick Delaunaybcb41dc2015-10-27 11:00:28 +010040#ifdef CONFIG_PARTITION_TYPE_GUID
41int uuid_guid_get_bin(const char *guid_str, unsigned char *guid_bin);
42int uuid_guid_get_str(unsigned char *guid_bin, char *guid_str);
43#endif
Przemyslaw Marczak4e4815f2014-04-02 10:20:04 +020044void gen_rand_uuid(unsigned char *uuid_bin);
45void gen_rand_uuid_str(char *uuid_str, int str_format);
Przemyslaw Marczakd718ded2014-04-02 10:20:03 +020046#endif