Skip to content

Conversation

@vChavezB
Copy link
Contributor

@vChavezB vChavezB commented Jul 22, 2023

Added support to connect to an HCI TCP Server. This allows to do integration tests with other frameworks that support a virtual hci interface.

The use cases I see for this are:

  • Test automatically mobile apps with zephyr applications. E.g. Android Emulator
  • Integration tests that depend on Zephyr Bluetooth Peripheral devices without the real zephyr hardware. e.g., Test the correct
    functionality of a Bluetooth gateway by assigning a virtual hci controller bridge.

Attached is a proof of concept to show case emulating an Android device and connecting to a Zephyr Bluetooth sample (peripheral_hr). I am using the experimental python software from Google called bumble for connecting the Zephyr TCP HCI client and the Android netsim

https://github.com/google/bumble

Upper left screen is the HCI traffice between zephyr bluetooth stack (host) and the android-netsim (Controller). Lower window is the zephyr binary running the peripheral_hr example in the Windows Subsystem for Linux. And on the right is the Android emulator running with Android API 34 and the NRF Connect App to test the GATT notification of the peripheral_hr sample.

pof_tcp_hci_zephyr.mp4

carlescufi
carlescufi previously approved these changes Jul 25, 2023
Copy link
Member

@carlescufi carlescufi left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@aescolar aescolar left a comment

Choose a reason for hiding this comment

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

Thanks @vChavezB
Just a few relatively minor things that caught my eye.

Copy link
Member

@aescolar aescolar left a comment

Choose a reason for hiding this comment

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

Just 2 trivial nits from me, which do not really warrant another pass unless you want to.

aescolar
aescolar previously approved these changes Jul 25, 2023
@vChavezB vChavezB force-pushed the userchan_tcp branch 2 times, most recently from 4d31894 to 8f50abb Compare July 25, 2023 15:04
aescolar
aescolar previously approved these changes Jul 25, 2023
@vChavezB vChavezB requested a review from carlescufi August 1, 2023 15:40
@zephyrbot zephyrbot added the area: native port Host native arch port (native_sim) label Aug 19, 2023
@vChavezB
Copy link
Contributor Author

vChavezB commented Aug 19, 2023

I will start adding the documentation about how to use the virtual controller here

https://github.com/vChavezB/zephyr/blob/641720da22721a7dd6ddba8eeb6a297b6675c6be/doc/connectivity/bluetooth/bluetooth-tools.rst?plain=1#L186

Edit: I have added the first documentation on how to use the virtual controller with an example.

@vChavezB vChavezB force-pushed the userchan_tcp branch 2 times, most recently from fdb082b to eef22a9 Compare August 19, 2023 18:53
@vChavezB vChavezB requested review from Thalley and aescolar August 19, 2023 18:54
Copy link
Member

@aescolar aescolar left a comment

Choose a reason for hiding this comment

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

Thank you very much for the update @vChavezB

@vChavezB
Copy link
Contributor Author

Thanks for the input @aescolar will modify accordingly.

@vChavezB
Copy link
Contributor Author

I have added the changes proposed by @aescolar for the docs and reverted the condition return value for sscanf .

aescolar
aescolar previously approved these changes Aug 21, 2023
Comment on lines 338 to 339
Copy link
Contributor

Choose a reason for hiding this comment

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

Since bt_dev_index is global, I suggest to make arg_hci_idx local, and do this check where arg_hci_idx is assigned. IMO there should be no reason to keep arg_hci_idx as a global value

Copy link
Contributor Author

@vChavezB vChavezB Aug 22, 2023

Choose a reason for hiding this comment

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

I made arg_hci_idx global to leave it for discussion. The question for me is where should user argument values be checked?

Directly when cmd_bt_dev_found is called or btuserchan_check_arg ?

If the bt index would be checked in cmd_bt_dev_found would it not make sense to also check the other arguments (i.e., ip address, port number) in this function ?

It was not clear to me if btuserchan_check_arg was just used to check if the argument --bt-dev was set or if it should also check the argument values.

Copy link
Member

Choose a reason for hiding this comment

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

Directly when cmd_bt_dev_found is called or btuserchan_check_arg ?

It is a bit better to check directly in cmd_bt_dev_found, no need to keep going if there is a bad cmd line argument.

would it not make sense to also check the other arguments (i.e., ip address, port number) in this function ?

Yep

@vChavezB
Copy link
Contributor Author

  • I have moved the argument value checks to cmd_bt_dev_found.
  • Removed redundant statement hci_socket = false; when the argument correspondes to an IP address and port number because hci_socket is static.
  • Capitalization of Bluetooth, TCP and HCI in the docs for the virtual controller sections.

aescolar
aescolar previously approved these changes Aug 22, 2023
Copy link
Member

@aescolar aescolar left a comment

Choose a reason for hiding this comment

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

I'm even happier with the PR now :)

@vChavezB
Copy link
Contributor Author

vChavezB commented Aug 22, 2023

Sorry there was a build error, hopefully it should now work 👍

Forgot a local variable that was used in btuserchan_check_arg when moving the checks to cmd_bt_dev_found

@vChavezB
Copy link
Contributor Author

There seems to be some errors but I am not sure if they are related to the change of the hci user channel source file.

@aescolar
Copy link
Member

There seems to be some errors but I am not sure if they are related to the change of the hci user channel source file.

Not related to this PR, main is broken right now, I queued a fix here: #61733

Added support to connect to an HCI TCP Server. This
allows to do integration tests with other frameworks
that support a virtual hci interface.

Signed-off-by: Victor Chavez <[email protected]>
@vChavezB
Copy link
Contributor Author

ok thanks for the update, I have just updated a condition which was incorrect

https://github.com/vChavezB/zephyr/blob/c7445a10bcac73121dc94e6a97018101c7e288d0/drivers/bluetooth/hci/userchan.c#L299

As I was not considering hci interfaces with index 0 i.e., hci0.

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.

Thanks for the PR and the quick updates :)

@vChavezB
Copy link
Contributor Author

No problem, thanks a lot for the input !

@aescolar aescolar merged commit 33c922a into zephyrproject-rtos:main Aug 22, 2023
@vChavezB vChavezB deleted the userchan_tcp branch August 22, 2023 19:58
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 area: native port Host native arch port (native_sim)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants