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

BLE Scan fails to start when running in parallel with BLE mesh #19361

Closed
stephenmasih opened this issue Sep 25, 2019 · 12 comments
Closed

BLE Scan fails to start when running in parallel with BLE mesh #19361

stephenmasih opened this issue Sep 25, 2019 · 12 comments
Assignees
Labels
area: Bluetooth Mesh area: Bluetooth Feature Request A request for a new feature Waiting for response Waiting for author's response

Comments

@stephenmasih
Copy link

Describe the bug
When I try to start the scan before mesh initialising followed by self-provisioning and configuring. It fails with error code -11.
When I first successfully initialise, provision and configure the mesh. and then call bt_le_scan_start(). It fails with error code -69. But I am able to publish and subscribe to the mesh messages.

To Reproduce
Steps to reproduce the behaviour:

  1. mkdir build; cd build
  2. cmake -GNinja -DBOARD=nrf52840_pca10056 ..
  3. ninja
  4. See error

Expected behaviour
BLE mesh works in broadcaster and scanning topologies. I should be able to scan all nearby beacon packets and parallel stay involved in the mesh.

Screenshots or console output
error_screenshot_2
error screenshot_1

@stephenmasih stephenmasih added the bug The issue is a bug, or the PR is fixing a bug label Sep 25, 2019
@jhedberg jhedberg added Enhancement Changes/Updates/Additions to existing features Feature Request A request for a new feature and removed bug The issue is a bug, or the PR is fixing a bug Enhancement Changes/Updates/Additions to existing features labels Sep 25, 2019
@jhedberg
Copy link
Member

Unfortunately this is currently by design. The Mesh stack essentially "owns" the advertising and scanning functionality and any attempts to make direct calls to bt_le_adv_start() or bt_le_scan_start() will result in errors or messing up the state of the mesh stack. We do have plans to fix this, but that involves having a controller that either supports Advertising Extensions, or Mesh HCI vendor extensions.

@stephenmasih
Copy link
Author

I see, can you tell if there are any possible ways because the mesh follows the observer capabilities. It picks up packets and does the work accordingly. Can I filter out beacon packet of a particular type somewhere in the zephyr code?

@jhedberg
Copy link
Member

jhedberg commented Sep 25, 2019

@stephenmasih currently you'd need to manually edit the bt_mesh_scan_cb() function in subsys/bluetooth/mesh/adv.c to add support for non-mesh advertising packets.

I would like to introduce a more flexible scan API which would allow having multiple callbacks, perhaps even per advertising data type, however I put this work on hold when I realised we'd probably need to properly take into account Advertising Extensions as well. My worry was that since AE requires new APIs we'd end up having three different ways of catching advertisements. Anyway, the simple idea was to just have a linked list of callbacks, using something like this:

--- a/include/bluetooth/bluetooth.h
+++ b/include/bluetooth/bluetooth.h
@@ -454,6 +454,20 @@ int bt_le_scan_start(const struct bt_le_scan_param *param, bt_le_scan_cb_t cb);
  */
 int bt_le_scan_stop(void);
 
+typedef void bt_scan_data_func_t(struct bt_scan_data_cb *cb,
+                                const bt_addr_le_t *addr, s8_t rssi,
+                                u8_t adv_type, struct net_buf_simple *buf);
+
+struct bt_scan_data_cb {
+       sys_snode_t         node;
+       bt_scan_data_func_t func;
+       u8_t                data_type;
+       u8_t                adv_types;
+};
+
+void bt_le_scan_data_cb_add(struct bt_scan_data_cb *cb);
+
+void bt_le_scan_data_cb_del(struct bt_scan_data_cb *cb);

If we can do something like that which also fits nicely together with AE APIs then that would be ideal from my perspective. @joerchan FYI.

@stephenmasih
Copy link
Author

Thank you @jhedberg FYI. Let me try editing the bt_mesh_scan_cb() in adv.c . Can you please tell me if it is possible to work with mesh beacons. As I see,
case BT_DATA_MESH_BEACON:
bt_mesh_beacon_recv(buf);
break;
What kind of beacon packet type does it pick up?

@jhedberg
Copy link
Member

jhedberg commented Sep 25, 2019

What kind of beacon packet type does it pick up?

@stephenmasih see section "3.9 Mesh beacons" in the Mesh Profile Specification. This covers both unprovisioned devices as well as secure network beacons.

@stephenmasih
Copy link
Author

I added a callback function as you mentioned @jhedberg. My callback is getting triggered but my scanning stops after some time the mesh initialisation. I mean even my mesh data packets are dropped. My callback is also neither triggered anymore. I seems like it crashed. Can you explain to me the probable reason?

@jhedberg
Copy link
Member

jhedberg commented Oct 2, 2019

@stephenmasih I wouldn't dare to claim a probable reason, but some common reasons can be stack overflows and controller asserts. I'd recommend enabling various logging/debugging Kconfig options to see if you can get some error outputted to the console.

@jhedberg
Copy link
Member

jhedberg commented Oct 2, 2019

@stephenmasih if you have gdb access it would also help to use that to investigate in what state the system is

@stephenmasih
Copy link
Author

Thank you @jhedberg. okay, let me dig deeper into debug mode. I will keep updated.

@carlescufi carlescufi added the Waiting for response Waiting for author's response label Oct 10, 2019
@joerchan
Copy link
Contributor

joerchan commented Jan 7, 2020

If we can do something like that which also fits nicely together with AE APIs then that would be ideal from my perspective. joerchan FYI.

@jhedberg I think this is covered by @trond-snekvik currently open PR.

@stephenmasih Any updates on this? We have a similar bug-report for the advertiser, maybe it is the same type of issue for the scanner? It could be affecting the scanner disable call.
#21498

@carlescufi
Copy link
Member

@jhedberg @trond-snekvik can this be closed?

@jhedberg
Copy link
Member

@jhedberg @trond-snekvik can this be closed?

I'd say so. @stephenmasih can reopen it if/when he's done with further digging and concluded that there's still something to fix in the stack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Bluetooth Mesh area: Bluetooth Feature Request A request for a new feature Waiting for response Waiting for author's response
Projects
None yet
Development

No branches or pull requests

6 participants