dfrankland / bluster

A Rust crate for implementing BLE (Bluetooth Low Energy) peripherals
https://crates.io/crates/bluster
MIT License
111 stars 33 forks source link

Read request MTU neither exposed nor checked #46

Open chrysn opened 2 years ago

chrysn commented 2 years ago

When handling a ReadRequest, neither can the user see the the MTU, nor is it checked whether the value passed in is short enough:

while let Some(event) = rx.next().await {
    match event {
        Event::ReadRequest(read_request) => {
            read_request
                .response
                .send(Response::Success(something().to_vec()))
                .unwrap();
        }
    }
}

On the gatt-api side, the MTU is part of the ReadValue method as an option. I did not find the error behavior documented, but my observation is that responding with more bytes than the MTU indicates just leads to transmission of a truncated response, whereas I think good practice in Rust would be to indicate this through an error.