jonas-schievink / rubble

(going to be a) BLE stack for embedded Rust
BSD Zero Clause License
396 stars 56 forks source link

Add function to `LinkLayer` for entering standby #140

Open daboross opened 4 years ago

daboross commented 4 years ago

I'm mainly wanting to arbitrarily stop advertising - I'm not at all sure how much this makes sense in practice, but it seems like a useful control to have for completeness? It's a single function LinkLayer::enter_standby which returns a Cmd and does as the name suggests.

This doesn't gracefully end connections - it's doing the same thing as starting advertising when one has an existing connection, but just not advertising instead.

jonas-schievink commented 4 years ago

Hmm, yeah, we want something like this eventually, but getting it correct is a bit more involved. For example, the low-priority part of the stack needs to know that the connection is being teared down to drain the packet queue before the operation can complete (otherwise establishing a new connection will start processing and transmitting packets from the old connection, which is pretty bad).

That said, going from "advertising" to "not advertising" should be trivial. Maybe we should have a stop_advertising function instead that will panic when a connection is established, if that helps with your use case?

daboross commented 4 years ago

That makes a lot of sense! I assumed some teardown would be needed, but didn't realize that this could even result in sending packets to the wrong connection.

I think a stop_advertising function could be useful, though it would allow accessing the same kind of bad situation if one calls start_advertising immediately followed by stop_advertising. I don't have a super compelling use case for this in any case, it would just be adding a feature so that it could be exposed to tock apps.

I think we definitely want some kind of connection termination at some point, though. Would it be alright if I opened up a new issue just to track that?

jonas-schievink commented 4 years ago

Sure!