Skip to content

BLE: Add privacy trace #14127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 8, 2021

Conversation

pan-
Copy link
Member

@pan- pan- commented Jan 7, 2021

Summary of changes

Add traces to the privacy controller and its associated PAL.
Traces of the host resolution operation are set at the debug level to not clutter the output.

Preceding PR: #14118

Impact of changes

Migration actions required

Documentation


Pull request type

[x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[x] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers


pan- added 8 commits January 6, 2021 16:20
- Prefix with Connection <id> - when appropriate.
- Display parameters after `:`.
- If multiple parameters should be displayed name then and print the value after =. They are separated by a `,`.
Only the first 8 bytes were generated from the stack.
Address resolution is set at the debug level as it is a very common operation and may clutter the output.
return BLE_ERROR_NOT_IMPLEMENTED;
}

tr_info("Add RPA to LL resolving list: peer address=%s, type=%s, peer irk=%s, local irk=%s",
to_string(peer_address_type), to_string(peer_identity_address), to_string(peer_irk), to_string(local_irk));
Copy link
Member

Choose a reason for hiding this comment

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

address and type swapped

Suggested change
to_string(peer_address_type), to_string(peer_identity_address), to_string(peer_irk), to_string(local_irk));
to_string(peer_identity_address), to_string(peer_address_type), to_string(peer_irk), to_string(local_irk));

return BLE_ERROR_NOT_IMPLEMENTED;
}

tr_info("Remove RPA from LL resolving list: peer address=%s, type=%s",
to_string(peer_address_type), to_string(peer_identity_address));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
to_string(peer_address_type), to_string(peer_identity_address));
to_string(peer_identity_address), to_string(peer_address_type));

#include "mbed-trace/mbed_trace.h"
#include "common/ble_trace_helpers.h"

#define TRACE_GROUP "BLSM"
Copy link
Member

Choose a reason for hiding this comment

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

maybe it's worth using a different tag: BLPR?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed.

@@ -444,6 +482,7 @@ ble_error_t PalSecurityManager::cancel_pairing(
ble_error_t PalSecurityManager::get_random_data(byte_array_t<8> &random_data)
{
SecRand(random_data.data(), random_data.size());
tr_info("Stack generated random data: %s", to_string(random_data));
Copy link
Member

Choose a reason for hiding this comment

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

don't think this is useful, if the data is relevant the caller will log it

Copy link
Member Author

Choose a reason for hiding this comment

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

That still useful, the caller will log things like set CSRK: ..... It doesn't say much about the origin of the bytes.
I'd keep it, it help me in identifying the issue fixed by #14125

@@ -697,6 +752,7 @@ bool PalSecurityManager::sm_handler(const wsfMsgHdr_t *msg)
}

case DM_SEC_LTK_REQ_IND: {
tr_info("Handling event DM_SEC_LTK_REQ_IND");
Copy link
Member

Choose a reason for hiding this comment

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

traces stop here, but there are a few more events below

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I don't know what I was thinking.

@@ -340,6 +370,7 @@ ble_error_t PrivateAddressController::resolve_address_on_host(

void PrivateAddressController::on_resolving_list_action_complete()
{
tr_info("Resolving list action conpleted");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
tr_info("Resolving list action conpleted");
tr_info("Resolving list action completed");

if (!_db) return BLE_ERROR_INITIALIZATION_INCOMPLETE;
tr_info("Connection %d - Accept pairing request", connection);
if (!_db) {
tr_error("Failure, db not initialized");
Copy link
Member

Choose a reason for hiding this comment

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

So it can be collapsed with the rest of them

Suggested change
tr_error("Failure, db not initialized");
tr_error("Failure, DB not initialized");

Copy link
Member

Choose a reason for hiding this comment

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

I guess same below, some copy pasting would solve this to avoid accidental differences in lines.

return;
}

SecurityDistributionFlags_t* flags = _db->get_distribution_flags(cb->db_entry);
if (!flags) {
tr_error("Connection %d - Cannot enable encryption, no distribution flags found for entry %p", cb->connection, cb->db_entry);
Copy link
Member

Choose a reason for hiding this comment

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

honestly, if you're fixing things, this whole if statement should just be an MBED_ASSERT(flags);

Copy link
Member

@paul-szczepanek-arm paul-szczepanek-arm Jan 8, 2021

Choose a reason for hiding this comment

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

Same below and other instances

Copy link
Member Author

Choose a reason for hiding this comment

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

The fix would be to validate the DB when it is loaded. I'm not doing it now.

PasskeyAscii ascii_passkey(passkey);
tr_info("Connection %d - Received passkey display %.*s",
connection, ascii_passkey.PASSKEY_LEN, ascii_passkey.value());
eventHandler->passkeyDisplay(connection, ascii_passkey.value());
Copy link
Member

Choose a reason for hiding this comment

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

should we null check eventHandler? you added the check to other places

Copy link
Member

Choose a reason for hiding this comment

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

and another one below

set_mitm_performed(connection);
if (!eventHandler) {
tr_error("Impossible to forward Keypress notification to application, no event handler registered");
Copy link
Member

Choose a reason for hiding this comment

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

the call below proceeds, needs to be in else block

Copy link
Member

Choose a reason for hiding this comment

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

same below

Copy link
Member

@paul-szczepanek-arm paul-szczepanek-arm left a comment

Choose a reason for hiding this comment

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

we should just merge and I'll make a separate PR to fix the issues listed above

- Put privacy traces in BLPR
- Add missing traces in PALSecurityManagerImpl.cpp
- Add missing EventHandler null pointer check
- Typo and parameters order fix.
@pan-
Copy link
Member Author

pan- commented Jan 8, 2021

Thanks @paul-szczepanek-arm . I addressed your changes.

@pan- pan- merged commit fd3a4a7 into ARMmbed:feature-bluetooth-traces Jan 8, 2021
pan- added a commit that referenced this pull request Jan 27, 2021
Add traces to the Bluetooth Security Manager and Privacy controller.
The traces are made to be comprehensive to improve the ux when users submit bugs.
A centralized set of helpers has been created to convert BLE types to string.

* BLE: Add SM traces

* BLE: Add traces to Security Manager PAL

* BLE: Make SM traces consistent.
- Prefix with Connection <id> - when appropriate.
- Display parameters after `:`.
- If multiple parameters should be displayed name then and print the value after =. They are separated by a `,`.

* BLE: Fix SM random number generation.

Only the first 8 bytes were generated from the stack.

* BLE: Regenerate CSRK if it is all zeroes.

* BLE: Add trace into privacy modules

Address resolution is set at the debug level as it is a very common operation and may clutter the output.

* Address trace review for SM:

- Put privacy traces in BLPR
- Add missing traces in PALSecurityManagerImpl.cpp
- Add missing EventHandler null pointer check
- Typo and parameters order fix.
pan- added a commit that referenced this pull request Feb 9, 2021
Add traces to the Bluetooth Security Manager and Privacy controller.
The traces are made to be comprehensive to improve the ux when users submit bugs.
A centralized set of helpers has been created to convert BLE types to string.

* BLE: Add SM traces

* BLE: Add traces to Security Manager PAL

* BLE: Make SM traces consistent.
- Prefix with Connection <id> - when appropriate.
- Display parameters after `:`.
- If multiple parameters should be displayed name then and print the value after =. They are separated by a `,`.

* BLE: Fix SM random number generation.

Only the first 8 bytes were generated from the stack.

* BLE: Regenerate CSRK if it is all zeroes.

* BLE: Add trace into privacy modules

Address resolution is set at the debug level as it is a very common operation and may clutter the output.

* Address trace review for SM:

- Put privacy traces in BLPR
- Add missing traces in PALSecurityManagerImpl.cpp
- Add missing EventHandler null pointer check
- Typo and parameters order fix.
paul-szczepanek-arm pushed a commit that referenced this pull request Mar 15, 2021
Add traces to the Bluetooth Security Manager and Privacy controller.
The traces are made to be comprehensive to improve the ux when users submit bugs.
A centralized set of helpers has been created to convert BLE types to string.

* BLE: Add SM traces

* BLE: Add traces to Security Manager PAL

* BLE: Make SM traces consistent.
- Prefix with Connection <id> - when appropriate.
- Display parameters after `:`.
- If multiple parameters should be displayed name then and print the value after =. They are separated by a `,`.

* BLE: Fix SM random number generation.

Only the first 8 bytes were generated from the stack.

* BLE: Regenerate CSRK if it is all zeroes.

* BLE: Add trace into privacy modules

Address resolution is set at the debug level as it is a very common operation and may clutter the output.

* Address trace review for SM:

- Put privacy traces in BLPR
- Add missing traces in PALSecurityManagerImpl.cpp
- Add missing EventHandler null pointer check
- Typo and parameters order fix.
pennam pushed a commit to pennam/mbed-os that referenced this pull request Mar 25, 2021
Add traces to the Bluetooth Security Manager and Privacy controller.
The traces are made to be comprehensive to improve the ux when users submit bugs.
A centralized set of helpers has been created to convert BLE types to string.

* BLE: Add SM traces

* BLE: Add traces to Security Manager PAL

* BLE: Make SM traces consistent.
- Prefix with Connection <id> - when appropriate.
- Display parameters after `:`.
- If multiple parameters should be displayed name then and print the value after =. They are separated by a `,`.

* BLE: Fix SM random number generation.

Only the first 8 bytes were generated from the stack.

* BLE: Regenerate CSRK if it is all zeroes.

* BLE: Add trace into privacy modules

Address resolution is set at the debug level as it is a very common operation and may clutter the output.

* Address trace review for SM:

- Put privacy traces in BLPR
- Add missing traces in PALSecurityManagerImpl.cpp
- Add missing EventHandler null pointer check
- Typo and parameters order fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants