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

pkg/nimble: add IP-over-BLE support via netif/GNRC #11578

Merged
merged 20 commits into from Aug 28, 2019

Conversation

haukepetersen
Copy link
Contributor

Contribution description

This PR provides support for IP-over-BLE by providing a GNRC-netif wrapper for Nimble. The provided behavior is should be conform to RFC7668 and the Bluetooth IPSP profile, but some details do still need to be verified.

The PR provides an application for 'fully manual' control of BLE behavior. Other means for BLE connection management (e.g. towards ipv6-mesh-over-ble) will follow in upcoming PRs.

Current State:

  • code (architecture, structure, implementation) is functional and ready to be looked at
  • a lot of documentation (high-level and doxygen) is missing (hence the WIP label)
  • some debug helpers are left in the code, will remove them once everything runs stable

I PR this code now, as it would be wonderful if someone could look over the code to see if there are some critical things I overlooked. I've been staring at this stuff for too long now and a bad tunnel vision :-)

Testing procedure

The provided nimble_gnrc application provides a mighty ble shell command, that can be used for advertising, scanning, and connecting to other nodes. Once at least two nodes are connected, all the IP magic (udp, icmp, ifconfig, rpl) is available...

At least in theory, this code should also work for connecting a RIOT BLE node to Linux. But I did not try this, yet.

Issues/PRs references

rebased on #11296

Known issues:

  • using the unpatched Nimble version a node can only have a single connection. If a second connection is opened, Nimble fails to allocate a second connection context from its context buffer (see nimble/host/src/ble_hs_conn.c -> ble_hs_conn_alloc()). I can't tell why, but it seems the memblock list for ble_hs_conn_pool is corrupted somehow. But when renaming that var to _ble_hs_conn_pool everything works again. So really now idea yet, what is causing this...
  • I did not fully verify, that GNRC behaves fully to spec of RFC7668 (e.g. neighbor discovery options...)

@haukepetersen haukepetersen added Area: network Area: Networking State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet Type: new feature The issue requests / The PR implemements a new feature for RIOT Area: BLE Area: Bluetooth Low Energy support labels May 24, 2019
@miri64 miri64 self-requested a review May 24, 2019 16:09
Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

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

First (superficial look) at the GNRC glue-code looks good to me.

@SemjonWilke SemjonWilke self-requested a review May 27, 2019 09:24
@SemjonWilke
Copy link
Member

SemjonWilke commented May 27, 2019

I tested this PR with a little tweaking as you explained to me in person. The workaround targets a bug in nimble that led to broken states, when trying to connect to multiple boards simultaniously.
Workaround:

  1. Clone and checkout https://github.com/haukepetersen/mynewt-nimble/tree/tmp_ble_hs_conn_fix
  2. change the pkg source in .../RIOT/pkg/nimble/Makefile by adding PKG_SOURCE_LOCAL=<location of the mynewt-branch> below PKG_LICENSE.

When doing so multihop routing with rpl works like a charm. I tested this with 2 nrf52dk as leafs and a nrf52840dk as root. Also sending pings in parallel over 2 hops works well as well as sending a udp package to a server.

Without this workaround I can reproduce the bug that broke the statemachine and hence disabled the first connection as well. However udp and ping communication work without the workaround between exactly 2 nodes (nrf52840dk <-> nrf52dk) as expected.

Whats your opinion @haukepetersen, do you want this PR in without fixing the bug in nimble first or is this PR on hold until the bug is purged?


int app_ble_cmd(int argc, char **argv)
{
if ((argc == 1) || _ishelp(argv[1])) {
Copy link
Member

Choose a reason for hiding this comment

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

A bit crowded and hard to read. Might be a good application for getopt().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true, but I would take this as optimization that might be done in the future. This is IMO not the most relevant code path anyway.

Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

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

Now some more in-depth review. As stated at first-glance, for the most part the glue code is ok, but the error codes are not mapped properly for the upper layer.

pkg/nimble/netif/nimble_netif.c Outdated Show resolved Hide resolved
pkg/nimble/netif/nimble_netif.c Outdated Show resolved Hide resolved
pkg/nimble/netif/nimble_netif.c Outdated Show resolved Hide resolved
pkg/nimble/netif/nimble_netif.c Show resolved Hide resolved
pkg/nimble/netif/nimble_netif.c Show resolved Hide resolved
pkg/nimble/netif/nimble_netif.c Show resolved Hide resolved
pkg/nimble/netif/nimble_netif.c Outdated Show resolved Hide resolved
@haukepetersen
Copy link
Contributor Author

addressed comments and rebased

@haukepetersen
Copy link
Contributor Author

This PR is now ready for actual review and testing, so I removed the WIP tag.

I is however still rebased on #11640

@haukepetersen haukepetersen added State: waiting for other PR State: The PR requires another PR to be merged first and removed State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet labels Jun 6, 2019
@haukepetersen
Copy link
Contributor Author

rebased

@haukepetersen haukepetersen removed the State: waiting for other PR State: The PR requires another PR to be merged first label Jun 6, 2019
Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

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

My review of the example application. I think with introducing shell commands instead and fixing the gnrc_ipv6_default/gnrc_sixlowpan_default dependencies it is not necessary to duplicate the gnrc_networking application. Sorry I did not spot this earlier.

@@ -0,0 +1 @@
TODO
Copy link
Member

Choose a reason for hiding this comment

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

The README still is not provided here ;-).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ups

# Specify the mandatory networking modules for IPv6 and UDP
USEMODULE += auto_init_gnrc_netif
USEMODULE += gnrc_ipv6_router_default
USEMODULE += gnrc_sixlowpan_router_default
Copy link
Member

Choose a reason for hiding this comment

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

This is redundant. Rather put this as a dependency of nimble + gnrc_ipv6_router_default like the rest does it.


# Specify the mandatory networking modules for IPv6 and UDP
USEMODULE += auto_init_gnrc_netif
USEMODULE += gnrc_ipv6_router_default
Copy link
Member

Choose a reason for hiding this comment

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

If there is no mesh support yet, why router?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not true, we do have (some sort of) mesh support build in

Copy link
Member

Choose a reason for hiding this comment

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

All the more argument to not have this a dedicated example but to fold this into gnrc_networking.


int app_ble_cmd(int argc, char **argv);

int app_udp_cmd(int argc, char **argv);
Copy link
Member

Choose a reason for hiding this comment

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

Here and above: Doc missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, will fix.

return memcmp(argv, "help", 4) == 0;
}

void app_ble_init(void)
Copy link
Member

Choose a reason for hiding this comment

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

Couln't this and the callback go to netif->ops->init()? It does not look very dependent on the application for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but it is.

The scanlist´ has nothing to do with nimble/netif`, and the callback is only valid for this application...

@@ -0,0 +1,364 @@

Copy link
Member

Choose a reason for hiding this comment

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

This file could also go to shell_commands, couldn't it? I believe then (and with the dependency fixes proposed in the Makefile) we could get away with not duplicating gnrc_networking ;-).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not really. The thing is, that these shell commands are quite application specific. I have some other code almost ready to be PRed, that does some sort of automated connection management (nimble_autoconn (connect to anything that fits some filter criteria) and nimble_rble (RPL-over-BLE)). Both use their own specific event callback implementations and would clash badly with these shell command implemenation here. So the shell command is not as generic as it seems...

Copy link
Member

Choose a reason for hiding this comment

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

maybe sc_nimble_manual_scan then? You say yourself, that these commands has nothing to do with nimble or gnrc_netif themselves, but rather are for managing connections. So a potential for duplication is there while they do not contributing to examplify GNRC+Nimble (i.e. have not much to do with this example).

@haukepetersen
Copy link
Contributor Author

@miri64 I spend some more thoughts on the shell-command issue: I think I have a rough idea what I could do so take it out of the application, and hence allow for using the gnrc_netoworking example after all. I need a little time to evaluate this idea though. So for now: I'd like to keep this example as is, and would prefer to rework it in a follow up. Would that work for you?

@miri64
Copy link
Member

miri64 commented Jun 11, 2019

So for now: I'd like to keep this example as is, and would prefer to rework it in a follow up. Would that work for you?

Let's do it like this: I still need some time to review the whole PR anyways, so if until then your evaluation comes to a close we decide then. Overall, I'd really like to avoid setting yet another precedence of code duplication within the code base if it is avoidable.

@haukepetersen
Copy link
Contributor Author

pushed some updates:

  • made NimBLE the default link layer for GNRC on nrf52 based boards (instead of the Nordic Softdevice)
  • removed the nimble_gnrc example (in favor of using it as default for gnrc_networking)
  • moved the nimble_netif (ble) shell command to the sys/shell module

@haukepetersen
Copy link
Contributor Author

And just a heads up: I would like to get this code in as is (after its approved and possible fixed, that is). I will then restructure parts of it again to cater for the upcoming CCNLIte integration and some automatic connection manager modules...

pkg/nimble/Makefile.dep Outdated Show resolved Hide resolved
pkg/nimble/Makefile.dep Outdated Show resolved Hide resolved
@haukepetersen
Copy link
Contributor Author

squashed. Now lets see... :-)

@miri64 miri64 added CI: run tests If set, CI server will run tests on hardware for the labeled PR CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Aug 28, 2019
@miri64
Copy link
Member

miri64 commented Aug 28, 2019

Running tests on boards, to make sure we don't break the nightlies with all our rat tail fixes.

@miri64
Copy link
Member

miri64 commented Aug 28, 2019

Let's go. Thanks test caching for the quick run 😁

@miri64 miri64 merged commit d6ac49c into RIOT-OS:master Aug 28, 2019
@haukepetersen
Copy link
Contributor Author

Wonderful, thanks a lot for the review effort!

@kaspar030
Copy link
Contributor

Awesome! 👍 👍

@emmanuelsearch
Copy link
Member

ditto ;)) thumbs up from over here too!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: BLE Area: Bluetooth Low Energy support Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants