laptou / bluez-rs

Control Bluetooth on Linux.
MIT License
39 stars 9 forks source link

Add support for Default System/Runtime configuration #17

Closed oxc closed 4 years ago

oxc commented 4 years ago

This pull request adds support for the Read/Set Default System/Runtime configuration commands defined in 1.18 (available in Kernel 5.9).

This change does add all missing commands, but does not implement high-level methods for all of them, nor all of the newly introduced events. Please let me know if this is not acceptable.

This change also includes minor fixes:

oxc commented 4 years ago

Demo usage:

let mut bc = BlueZClient::new_with_handler(|controller, event| {
    info!("[{}] Got event {:x?}", controller, event);
}).unwrap();
let controllers = bc.get_controller_list().await.unwrap();
let controller = *controllers.first().unwrap();

let version = bc.get_mgmt_version().await.unwrap();
debug!("Management version: {}.{}", version.version, version.revision);

if version.version >= 1 && version.revision >= 18 {
    let configs = bc.get_default_system_config(controller).await.unwrap();
    for (parameter_type, value) in configs {
        debug!("System config: {:?}={}", parameter_type, u16::from_le_bytes(value.as_slice().try_into().unwrap()));
    }
    bc.set_default_system_config(controller, &[
        (SystemConfigParameterType::LEAutoconnectTimeout, u16::to_le_bytes(20000).to_vec())
    ]).await.unwrap();
} else {
    warn!("MGMT API is too old for default system configuration");
}