1241675Suqs/*-
2241675Suqs * SPDX-License-Identifier: BSD-2-Clause
3241675Suqs *
4241675Suqs * Copyright (c) 2002 Marcel Moolenaar
5241675Suqs * All rights reserved.
6241675Suqs *
7241675Suqs * Redistribution and use in source and binary forms, with or without
8241675Suqs * modification, are permitted provided that the following conditions
9241675Suqs * are met:
10241675Suqs *
11241675Suqs * 1. Redistributions of source code must retain the above copyright
12241675Suqs *    notice, this list of conditions and the following disclaimer.
13241675Suqs * 2. Redistributions in binary form must reproduce the above copyright
14241675Suqs *    notice, this list of conditions and the following disclaimer in the
15241675Suqs *    documentation and/or other materials provided with the distribution.
16241675Suqs *
17241675Suqs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18241675Suqs * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19241675Suqs * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20241675Suqs * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21241675Suqs * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22241675Suqs * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23241675Suqs * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24241675Suqs * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25241675Suqs * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26241675Suqs * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27241675Suqs */
28241675Suqs
29241675Suqs#ifndef _SYS_UUID_H_
30241675Suqs#define	_SYS_UUID_H_
31241675Suqs
32241675Suqs#include <sys/types.h>
33241675Suqs
34241675Suqs/* Length of a node address (an IEEE 802 address). */
35241675Suqs#define	_UUID_NODE_LEN		6
36
37/*
38 * See also:
39 *      http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt
40 *      http://www.opengroup.org/onlinepubs/009629399/apdxa.htm
41 *
42 * A DCE 1.1 compatible source representation of UUIDs.
43 */
44struct uuid {
45	uint32_t	time_low;
46	uint16_t	time_mid;
47	uint16_t	time_hi_and_version;
48	uint8_t		clock_seq_hi_and_reserved;
49	uint8_t		clock_seq_low;
50	uint8_t		node[_UUID_NODE_LEN];
51};
52
53#ifdef _KERNEL
54
55#define	UUID_NODE_LEN	_UUID_NODE_LEN
56
57struct sbuf;
58
59struct uuid *kern_uuidgen(struct uuid *, size_t);
60
61int uuid_ether_add(const uint8_t *);
62int uuid_ether_del(const uint8_t *);
63
64int snprintf_uuid(char *, size_t, struct uuid *);
65int printf_uuid(struct uuid *);
66int sbuf_printf_uuid(struct sbuf *, struct uuid *);
67
68/*
69 * validate_uuid will, with no flags passed, validate only the format of the
70 * passed in UUID.  Flags below are available to give it part of or all of the
71 * functionality that parse_uuid has traditionally had: acknowledging an empty
72 * string as valid, and checking the semantics of the UUID as well.
73 */
74int validate_uuid(const char *, size_t, struct uuid *, int);
75int parse_uuid(const char *, struct uuid *);
76
77/* Flags to validate_uuid(). */
78#define	VUUIDF_EMPTYOK		0x0001
79#define	VUUIDF_CHECKSEMANTICS	0x0002
80
81int uuidcmp(const struct uuid *, const struct uuid *);
82
83void be_uuid_dec(void const *buf, struct uuid *uuid);
84void be_uuid_enc(void *buf, struct uuid const *uuid);
85void le_uuid_dec(void const *buf, struct uuid *uuid);
86void le_uuid_enc(void *buf, struct uuid const *uuid);
87
88#else	/* _KERNEL */
89
90/* XXX namespace pollution? */
91typedef struct uuid uuid_t;
92
93__BEGIN_DECLS
94int	uuidgen(struct uuid *, int);
95__END_DECLS
96
97#endif	/* _KERNEL */
98
99#endif /* _SYS_UUID_H_ */
100