Skip to content

Commit

Permalink
[nrf fromtree] Bluetooth: Shell: Add support for EAD
Browse files Browse the repository at this point in the history
Add new commands to manage the Encrypted Advertising Data feature.

Overview of those new commands:

- `bt encrypted-ad set-keys`: set key materials (session key and
  initialisation vector) used for encrypted and decryption of EAD;
- `bt encrypted-ad add-ad`: store a given advertising data structure;
- `bt encrypted-ad add-ead`: encrypt the given advertising data
  structres and store the generated AD structure;
- `bt encrypted-ad commit-ad`: set the AD of the selected advertiser
  with the stored AD;
- `bt encrypted-ad clear-ad`: remove all stored AD;
- `bt encrypted-ad decrypt-scan`: decrypt data using the previously set
  key materials when receiving AD with type `0x31`.

The documentation of the Bluetooth Shell has been updated to include
those new commands.

Signed-off-by: Théo Battrel <[email protected]>
(cherry picked from commit 4a55bc0)
  • Loading branch information
theob-pro committed Mar 14, 2024
1 parent d96769f commit f40fdcd
Show file tree
Hide file tree
Showing 3 changed files with 426 additions and 0 deletions.
84 changes: 84 additions & 0 deletions doc/connectivity/bluetooth/bluetooth-shell.rst
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,90 @@ Let's now have a look at some extended advertising features. To enable extended
This will create an extended advertiser, that is connectable and non-scannable.

Encrypted Advertising Data
==========================

Zephyr has support for the Encrypted Advertising Data feature. The :code:`bt encrypted-ad`
sub-commands allow managing the advertising data of a given advertiser.

To encrypt the advertising data, key materials need to be provided, that can be done with :code:`bt
encrypted-ad set-keys <session key> <init vector>`. The session key is 16 bytes long and the
initialisation vector is 8 bytes long.

You can add advertising data by using :code:`bt encrypted-ad add-ad` and :code:`bt encrypted-ad
add-ead`. The former will take add one advertising data structure (as defined in the Core
Specification), when the later will read the given data, encrypt them and then add the generated
encrypted advertising data structure. It's possible to mix encrypted and non-encrypted data, when
done adding advertising data, :code:`bt encrypted-ad commit-ad` can be used to apply the change to
the data to the selected advertiser. After that the advertiser can be started as described
previously. It's possible to clear the advertising data by using :code:`bt encrypted-ad clear-ad`.

On the Central side, it's possible to decrypt the received encrypted advertising data by setting the
correct keys material as described earlier and then enabling the decrypting of the data with
:code:`bt encrypted-ad decrypt-scan on`.

.. note::

To see the advertising data in the scan report :code:`bt scan-verbose-output` need to be
enabled.

.. note::

It's possible to increase the length of the advertising data by increasing the value of
:kconfig:option:`CONFIG_BT_CTLR_ADV_DATA_LEN_MAX` and
:kconfig:option:`CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX`.

Here is a simple example demonstrating the usage of EAD:

.. tabs::

.. group-tab:: Peripheral

.. code-block:: console
uart:~$ bt init
...
uart:~$ bt adv-create conn-nscan ext-adv
Created adv id: 0, adv: 0x81769a0
uart:~$ bt encrypted-ad set-keys 9ba22d3824efc70feb800c80294cba38 2e83f3d4d47695b6
session key set to:
00000000: 9b a2 2d 38 24 ef c7 0f eb 80 0c 80 29 4c ba 38 |..-8$... ....)L.8|
initialisation vector set to:
00000000: 2e 83 f3 d4 d4 76 95 b6 |.....v.. |
uart:~$ bt encrypted-ad add-ad 06097368656C6C
uart:~$ bt encrypted-ad add-ead 03ffdead03ffbeef
uart:~$ bt encrypted-ad commit-ad
Advertising data for Advertiser[0] 0x81769a0 updated.
uart:~$ bt adv-start
Advertiser[0] 0x81769a0 set started
.. group-tab:: Central

.. code-block:: console
uart:~$ bt init
...
uart:~$ bt scan-verbose-output on
uart:~$ bt encrypted-ad set-keys 9ba22d3824efc70feb800c80294cba38 2e83f3d4d47695b6
session key set to:
00000000: 9b a2 2d 38 24 ef c7 0f eb 80 0c 80 29 4c ba 38 |..-8$... ....)L.8|
initialisation vector set to:
00000000: 2e 83 f3 d4 d4 76 95 b6 |.....v.. |
uart:~$ bt encrypted-ad decrypt-scan on
Received encrypted advertising data will now be decrypted using provided key materials.
uart:~$ bt scan on
Bluetooth active scan enabled
[DEVICE]: 68:49:30:68:49:30 (random), AD evt type 5, RSSI -59 shell C:1 S:0 D:0 SR:0 E:1 Prim: LE 1M, Secn: LE 2M, Interval: 0x0000 (0 us), SID: 0x0
[SCAN DATA START - EXT_ADV]
Type 0x09: shell
Type 0x31: Encrypted Advertising Data: 0xe2, 0x17, 0xed, 0x04, 0xe7, 0x02, 0x1d, 0xc9, 0x40, 0x07, uart:~0x18, 0x90, 0x6c, 0x4b, 0xfe, 0x34, 0xad
[START DECRYPTED DATA]
Type 0xff: 0xde, 0xad
Type 0xff: 0xbe, 0xef
[END DECRYPTED DATA]
[SCAN DATA END]
...
Filter Accept List
******************

Expand Down
Loading

0 comments on commit f40fdcd

Please sign in to comment.