Skip to content
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

Improve central_uart sample application #12537

Closed
wants to merge 3 commits into from

Conversation

pideu-mh
Copy link

@pideu-mh pideu-mh commented Oct 5, 2023

This patch set tries to make the central_uart sample application more similar to the peripheral_uart sample application in the following ways:

  • Introduce Kconfig options to get rid of hard-coded values, so that the build can be customized
  • Add support for unsecure connections, to avoid error and warning messages in the log when connecting to a peer that only supports unsecure connections
  • Fix timeout value for UART_RX_TIMEOUT which was probably an oversight

Please check out the individual commit messages for more details.

In contrast to the peripheral_uart sample application the central_uart
application uses hard-coded values for buffer size, UART Rx wait time
and NUS write timeout.

This patch replaces the hard-coded values with proper entries in a
Kconfig file to make this sample match the peripheral_uart sample
application.

Signed-off-by: Michael Hunold <michael.hunold@eu.panasonic.com>
The peripheral_uart supports the Kconfig option BT_NUS_SECURITY_ENABLED
which allows the sample application to be built with or without support
for a secure connection.

This option is not present in the central_uart sample, it
unconditionally enforces a secure connection.

If the peripheral_uart sample application is built without support for a
secure connection, this leads to the following error and warning
messages in the log file for the central_uart sample application when a
connection is established:

<err> bt_smp: pairing failed (peer reason 0x5)
<wrn> central_uart:  Security failed: xx:xx:xx:xx:xx:xx (random)
      level 1 err 5
<wrn> central_uart: Pairing failed conn: xx:xx:xx:xx:xx:xx (random),
      reason 5

This patch adds BT_NUS_SECURITY_ENABLED to the central_uart sample
application similarly to the peripheral_uart sample application, but the
default behaviour when building the sample application is unchanged.

Signed-off-by: Michael Hunold <michael.hunold@eu.panasonic.com>
@github-actions github-actions bot added the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Oct 5, 2023
@NordicBuilder
Copy link
Contributor

Thank you for your contribution!
It seems you are not a member of the nrfconnect GitHub organization. External contributions are handled as follows:
Large contributions, affecting multiple subsystems for example, may be rejected if they are complex, may introduce regressions due to lack of test coverage, or if they are not consistent with the architecture of nRF Connect SDK.
PRs will be run in our continuous integration (CI) test system.
If CI passes, PRs will be tagged for review and merged on successful completion of review. You may be asked to make some modifications to your contribution during review.
If CI fails, PRs may be rejected or may be tagged for review and rework.
PRs that become outdated due to other changes in the repository may be rejected or rework requested.
External contributions will be prioritized for review based on the relevance to current development efforts in nRF Connect SDK. Bug fix PRs will be prioritized.
You may raise issues or ask for help from our Technical Support team by visiting https://devzone.nordicsemi.com/.

Note: This comment is automatically posted and updated by the Contribs GitHub Action.

@NordicBuilder NordicBuilder added the external External contribution label Oct 5, 2023
@alwa-nordic alwa-nordic added the CI-Requested Approves single commit for CI tests on Internal HW label Oct 5, 2023
The peripheral_uart and central_uart sample applications use almost
identical code for the UART handling.

But one difference is the usage of the UART_RX_TIMEOUT value. It is used
in uart_rx_enable() and is expected to be a value in microseconds.

The peripheral_uart sample application uses a value of 50000 for
UART_RX_TIMEOUT which corresponds to a timeout of 50ms, which is
pretty reasonable for a timeout value for the UART.

Due to whatever reasons the central_uart application uses a value of 50
for UART_RX_TIMEOUT which corresponds to a timeout of just 50
microseconds, which looks unreasonable.

The assumption here now is that this was simply an oversight and really
50000 should have been used right from the beginning.

This patch fixes this and makes the handling of peripheral_uart and
central_uart identical when it comes to UART_RX_TIMEOUT.

Signed-off-by: Michael Hunold <michael.hunold@eu.panasonic.com>
@github-actions github-actions bot removed the CI-Requested Approves single commit for CI tests on Internal HW label Oct 5, 2023
@pideu-mh
Copy link
Author

pideu-mh commented Oct 5, 2023

Unfortunately the compliance checks on the patch series failed, because one commend in the commit message exceeded the max. line length.

I reformatted the commit message and updated the patch series. No other changes were done.

@alwa-nordic alwa-nordic added the CI-Requested Approves single commit for CI tests on Internal HW label Oct 5, 2023
@KAGA164
Copy link
Contributor

KAGA164 commented Oct 5, 2023

Please add entry in sample.yaml:

sample.bluetooth.central_uart.security_disabled:
build_only: true
integration_platforms:
- nrf52840dk_nrf52840
platform_allow: nrf52dk_nrf52832 nrf52840dk_nrf52840 nrf52dk_nrf52810
nrf5340dk_nrf5340_cpuapp nrf5340dk_nrf5340_cpuapp_ns nrf21540dk_nrf52840
tags: bluetooth ci_build
extra_configs:
- CONFIG_BT_NUS_SECURITY_ENABLED

default y
select BT_SMP
help
"Enable BLE security for the UART service client"
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add dot an every help line end

Suggested change
"Enable BLE security for the UART service client"
Enable BLE security for the UART service client

@@ -384,12 +384,16 @@ static void connected(struct bt_conn *conn, uint8_t conn_err)
LOG_WRN("MTU exchange failed (err %d)", err);
}

#ifdef CONFIG_BT_NUS_SECURITY_ENABLED
Copy link
Contributor

Choose a reason for hiding this comment

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

You could use here IS_ENABLED macro instead of conditional compilation

Suggested change
#ifdef CONFIG_BT_NUS_SECURITY_ENABLED
if(IS_ENABLED(CONFIG_BT_NUS_SECURITY_ENABLED)) {


int main(void)
{
int err;

#ifdef CONFIG_BT_NUS_SECURITY_ENABLED
Copy link
Contributor

Choose a reason for hiding this comment

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

Please try to use IS_ENABLED macro like it is done in the peripheral_uart sample


menu "Nordic UART Service Client sample"

config BT_NUS_UART_BUFFER_SIZE
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe BT_NUS_C_.... since this is about client side

Copy link

github-actions bot commented Dec 5, 2023

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Dec 5, 2023
@github-actions github-actions bot closed this Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. CI-Requested Approves single commit for CI tests on Internal HW external External contribution Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants