Skip to content

Conversation

@theob-pro
Copy link
Contributor

@theob-pro theob-pro commented Feb 27, 2023

Create a new Bluetooth library and add Encrypted Advertising Data to it.

Encrypted Advertising Data is a new feature from the Bluetooth Core Specification 5.4. It provides a way to communicate encrypted data in advertising, scan response and EIR packets. To do that it introduce a new advertising data type called Encrypted Advertising Data. Also, it introduce a new characteristic called Encrypted Data Key Material, this provides a way to share the key material.

The library add two main functions bt_ead_encrypt and bt_ead_decrypt.

Also, add a new BabbleSim test that use the sample data from the Supplement to the Bluetooth Core Specification to validate the encryption, decryption and authentication.

Related issue: #55081

Copy link
Contributor

@Thalley Thalley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second commit should be tests: bluetooth:

Why is this being added as a library, instead of just an API in bluetooth.h?

@theob-pro theob-pro force-pushed the add-encrypted-advertising branch from e281606 to bfec8d5 Compare February 27, 2023 13:57
@jori-nordic
Copy link
Contributor

Why is this being added as a library, instead of just an API in bluetooth.h?

The host is pretty bloated and tries to be too nice to the user. This pushes functionality that shouldn't be in the host to be inside the host (settings usage, a bunch of gatt functionality, adv resume comes to mind). That functionality then makes use of the internal state and functions, because why not, it's more efficient and that results in:

  • more bugs, because more complex and internal state is used all over the place
  • the API being not that nice to use in practice, because the user still has to be pretty familiar with the host's inner workings to use the 'user-friendly' functionality

That's why we'd like to slim down the host to a maintainable core + some libraries on top.
Encrypted advertising can be implemented fully outside of the host, that's why we're making it a library.

@hermabe
Copy link
Member

hermabe commented Feb 27, 2023

The current tests only check that the advdata encrypts and decrypts back to itself. It would be nice to have some tests that checks that the encrypted data is correct as well. I suggest we use the "Encrypted Advertising Data Sample Data" from the CSS.

@theob-pro theob-pro force-pushed the add-encrypted-advertising branch from bfec8d5 to 004f862 Compare February 27, 2023 14:18
@theob-pro theob-pro force-pushed the add-encrypted-advertising branch from 004f862 to e809c6b Compare February 27, 2023 14:41
@jori-nordic
Copy link
Contributor

but we should also look at what we already have and see if it makes sense to group this new functionality with existing Bluetooth sub-modules that can also be considered libraries (in the sense that there'd be multiple "library submodules" under the same directory.

This sounds like it should be done in a separate PR. Having this lib/ folder will make it easier to move functionality out of the 'core' host in the near future anyway.

@theob-pro theob-pro force-pushed the add-encrypted-advertising branch from e809c6b to 0110c3a Compare February 27, 2023 15:17
alwa-nordic
alwa-nordic previously approved these changes Feb 27, 2023
@theob-pro theob-pro force-pushed the add-encrypted-advertising branch 4 times, most recently from 617ef27 to 6e6ef05 Compare February 27, 2023 17:01
@jhedberg
Copy link
Member

@theob-pro I think it might make sense to rename the header file simply to ead.h, so that it's in line with the API naming. Probably same with the c-file. Application developers will be primarily referencing the generated documentation, so I don't think this will make the API any less discoverable for them.

@theob-pro theob-pro force-pushed the add-encrypted-advertising branch from 6fbedab to 42224c6 Compare March 10, 2023 13:32
@alwa-nordic alwa-nordic added area: Bluetooth Host Bluetooth Host (excluding BR/EDR) Feature A planned feature with a milestone labels Mar 14, 2023
@theob-pro theob-pro force-pushed the add-encrypted-advertising branch from 42224c6 to e6bc5ca Compare March 16, 2023 12:50
@theob-pro
Copy link
Contributor Author

Rebased to resolve file conflict (tests/bluetooth/bsim/host/compile.sh).

@theob-pro theob-pro force-pushed the add-encrypted-advertising branch from e6bc5ca to 625b8a5 Compare March 16, 2023 13:42
alwa-nordic
alwa-nordic previously approved these changes Mar 16, 2023
jori-nordic
jori-nordic previously approved these changes Mar 16, 2023
@theob-pro theob-pro dismissed stale reviews from jori-nordic and alwa-nordic via a2f4789 March 20, 2023 14:38
@theob-pro theob-pro force-pushed the add-encrypted-advertising branch from 625b8a5 to a2f4789 Compare March 20, 2023 14:38
@theob-pro
Copy link
Contributor Author

Rebased to resolve file conflict (tests/bluetooth/bsim/host/compile.sh).

Thalley
Thalley previously approved these changes Mar 20, 2023
Copy link
Contributor

@Thalley Thalley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My remaining comments are about undocumented/required formatting changes, and one comment about a LOG_WRN that I think should be LOG_DBG, but it's not bad enough that I will block this PR anymore :)

@jori-nordic
Copy link
Contributor

I agree, let's get this in, and @theob-pro and @Thalley can discuss the small stuff in a new PR.

jori-nordic
jori-nordic previously approved these changes Mar 21, 2023
Copy link
Member

@jhedberg jhedberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being slow to review this. I've tried to keep my comments restricted to things which require more effort/pain to fix later in the game, i.e. the API details.

@theob-pro theob-pro dismissed stale reviews from jori-nordic and Thalley via 60cb6c9 March 21, 2023 09:33
@theob-pro theob-pro force-pushed the add-encrypted-advertising branch from a2f4789 to 60cb6c9 Compare March 21, 2023 09:33
Create a new Bluetooth library and add Encrypted Advertising Data to it. Encrypted Advertising Data is a new feature from the Bluetooth Core Specification 5.4. It provides a way to communicate encrypted data in advertising, scan response and EIR packets. To do that it introduce a new advertising data type called `Encrypted Advertising Data`. Also, it introduce a new characteristic called `Encrypted Data Key Material`, this provides a way to share the key material. The library add two main functions `bt_ead_encrypt` and `bt_ead_decrypt`. Two helper functions are added to `bluetooth.h`. `bt_data_get_len` and `bt_data_serialize`, the first one allow the user to get the total size of a set of `bt_data` structures; the second one generate a spec compliant bytes array from a `bt_data` structure. The last one is useful because `bt_ead_encrypt` take as input those kind of bytes array. Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
Add a new BabbleSim test that use the sample data from the Supplement to the Bluetooth Core Specification to validate the Encrypted Advertising Data feature implementation. Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
@theob-pro theob-pro force-pushed the add-encrypted-advertising branch from 60cb6c9 to 30e6665 Compare March 21, 2023 09:46
@jhedberg jhedberg merged commit acfe688 into zephyrproject-rtos:main Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Bluetooth Host Bluetooth Host (excluding BR/EDR) area: Bluetooth Feature A planned feature with a milestone

8 participants