1.. zephyr:code-sample:: bluetooth_encrypted_advertising
2   :name: Encrypted Advertising
3   :relevant-api: bluetooth
4
5   Use the Bluetooth LE encrypted advertising feature.
6
7Overview
8********
9
10This sample demonstrates the use of the encrypted advertising feature, such as:
11
12 - the exchange of the session key and the initialization vector using the Key
13   Material characteristic,
14 - the encryption of advertising payloads,
15 - the decryption of those advertising payloads,
16 - and the update of the Randomizer field whenever the RPA is changed.
17
18To use the :c:func:`bt_ead_encrypt` and :c:func:`bt_ead_decrypt` functions, you must enable
19the Kconfig symbol :kconfig:option:`CONFIG_BT_EAD`.
20
21While this sample uses extended advertising, it is **not** mandatory when using
22the encrypted advertising. The feature can be used with legacy advertising as
23well.
24
25Requirements
26************
27
28* Two boards with Bluetooth Low Energy support
29* Two boards with a push button connected via a GPIO pin, see the :zephyr:code-sample:`button`
30  sample for more details
31
32Building and Running
33********************
34
35This sample can be found under
36:zephyr_file:`samples/bluetooth/encrypted_advertising` in the Zephyr tree.
37
38See :zephyr:code-sample-category:`bluetooth` samples for details.
39
40This sample uses two applications, so two devices need to be setup.
41Flash one device with the central application, and another device with the
42peripheral application.
43
44The two devices should automatically connect if they are close enough.
45
46After the boards are connected, you will be asked to press the configured push
47button on both boards to confirm the pairing request.
48
49Here are the outputs you should get by default:
50
51Peripheral:
52
53.. code-block:: console
54
55        *** Booting Zephyr OS build zephyr-v3.3.0-1872-g6fac3c7581dc ***
56        <inf> ead_peripheral_sample: Advertising data size: 64
57        Passkey for 46:04:2E:6F:80:12 (random): 059306
58        Confirm passkey by pressing button at gpio@50000000 pin 11...
59        Passkey confirmed.
60        <inf> ead_peripheral_sample: Advertising data size: 64
61
62
63Central:
64
65.. code-block:: console
66
67        *** Booting Zephyr OS build zephyr-v3.3.0-1872-g6fac3c7581dc ***
68        Passkey for 6C:7F:67:C2:8B:29 (random): 059306
69        Confirm passkey by pressing button at gpio@50000000 pin 11...
70        Passkey confirmed.
71        <inf> ead_central_sample: Received data size: 64
72        <inf> ead_central_sample: len : 10
73        <inf> ead_central_sample: type: 0x09
74        <inf> ead_central_sample: data:
75                                  45 41 44 20 53 61 6d 70  6c 65                   |EAD Samp le
76        <inf> ead_central_sample: len : 8
77        <inf> ead_central_sample: type: 0xff
78        <inf> ead_central_sample: data:
79                                  05 f1 5a 65 70 68 79 72                          |..Zephyr
80        <inf> ead_central_sample: len : 7
81        <inf> ead_central_sample: type: 0xff
82        <inf> ead_central_sample: data:
83                                  05 f1 49 d2 f4 55 76                             |..I..Uv
84        <inf> ead_central_sample: len : 4
85        <inf> ead_central_sample: type: 0xff
86        <inf> ead_central_sample: data:
87                                  05 f1 c1 25                                      |...%
88        <inf> ead_central_sample: len : 3
89        <inf> ead_central_sample: type: 0xff
90        <inf> ead_central_sample: data:
91                                  05 f1 17                                         |...
92