Skip to content

Commit a910195

Browse files
kartbenMaureenHelm
authored andcommitted
doc: services: uuid: Add dedicated page for UUID API
Add more complete/dedicated documentation page for UUID API. Drop the old services/misc page as it's empty/deleted now Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
1 parent 9ac587c commit a910195

File tree

4 files changed

+100
-22
lines changed

4 files changed

+100
-22
lines changed

‎doc/_scripts/redirects.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@
329329
('samples/subsys/video/tcpserversink/README', 'samples/drivers/video/tcpserversink/README'),
330330
('samples/subsys/video/video', 'samples/drivers/video/video'),
331331
('services/file_system/index', 'services/storage/file_system/index'),
332+
('services/misc', 'services/index'),
332333
('services/modbus/index', 'connectivity/modbus/index'),
333334
('services/nvmem/index', 'services/storage/nvmem/index'),
334335
('services/portability/posix', 'services/portability/posix/index'),

‎doc/services/index.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ OS Services
3939
sensing/index.rst
4040
task_wdt/index.rst
4141
tfm/index
42+
uuid/index.rst
4243
virtualization/index.rst
4344
rtio/index.rst
4445
zbus/index.rst
45-
misc.rst

‎doc/services/misc.rst‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎doc/services/uuid/index.rst‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
.. _uuid_api:
2+
3+
UUID
4+
####
5+
6+
Overview
7+
********
8+
9+
Universally Unique Identifiers (UUID), also known as Globally Unique IDentifiers (GUIDs), are
10+
128-bit identifiers intended to guarantee uniqueness across space and time. They are defined by
11+
:rfc:`9562`.
12+
13+
The UUID subsystem provides utility functions for the generation, parsing, and manipulation of
14+
UUIDs. It supports generating version 4 (random) and version 5 (name-based) UUIDs.
15+
16+
Usage
17+
=====
18+
19+
To use the UUID API, include the header file:
20+
21+
.. code-block:: c
22+
23+
#include <zephyr/sys/uuid.h>
24+
25+
Generating a UUIDv4
26+
-------------------
27+
28+
UUIDv4 is based on random numbers (hence requires an entropy generator), and can be generated using
29+
the :c:func:`uuid_generate_v4` function. :kconfig:option:`CONFIG_UUID_V4` must also be enabled.
30+
31+
.. code-block:: c
32+
33+
struct uuid my_uuid;
34+
char uuid_str[UUID_STR_LEN];
35+
36+
int ret = uuid_generate_v4(&my_uuid);
37+
38+
if (ret != 0) {
39+
printk("Failed to generate UUID v4 (err %d)\n", ret);
40+
return ret;
41+
}
42+
43+
ret = uuid_to_string(&my_uuid, uuid_str);
44+
if (ret != 0) {
45+
printk("Failed to convert UUID to string (err %d)\n", ret);
46+
return ret;
47+
}
48+
49+
printk("UUID: %s\n", uuid_str);
50+
51+
Generating a UUIDv5
52+
-------------------
53+
54+
UUIDv5 is generated from a namespace UUID and a name (binary data), and can be generated using the
55+
:c:func:`uuid_generate_v5` function. :kconfig:option:`CONFIG_UUID_V5` must also be enabled.
56+
57+
UUIDv5 is deterministic: the same namespace and name will always result in the same UUID.
58+
59+
.. code-block:: c
60+
61+
struct uuid ns_uuid;
62+
struct uuid my_uuid;
63+
char uuid_str[UUID_STR_LEN];
64+
65+
/* Well-known namespace ID for URLs (RFC 9562) */
66+
uuid_from_string("6ba7b811-9dad-11d1-80b4-00c04fd430c8", &ns_uuid);
67+
68+
const char *name = "https://zephyrproject.org/";
69+
int ret = uuid_generate_v5(&ns_uuid, name, strlen(name), &my_uuid);
70+
71+
if (ret != 0) {
72+
printk("Failed to generate UUID v5 (err %d)\n", ret);
73+
return ret;
74+
}
75+
76+
ret = uuid_to_string(&my_uuid, uuid_str);
77+
if (ret != 0) {
78+
printk("Failed to convert UUID to string (err %d)\n", ret);
79+
return ret;
80+
}
81+
82+
/* outputs: "UUID: abdb72b5-b342-5882-925b-4ce0e3cb4790" */
83+
printk("UUID: %s\n", uuid_str);
84+
85+
Configuration
86+
*************
87+
88+
Related configuration options:
89+
90+
* :kconfig:option:`CONFIG_UUID`
91+
* :kconfig:option:`CONFIG_UUID_V4`
92+
* :kconfig:option:`CONFIG_UUID_V5`
93+
* :kconfig:option:`CONFIG_UUID_BASE64`
94+
95+
API Reference
96+
*************
97+
98+
.. doxygengroup:: uuid

0 commit comments

Comments
 (0)