• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! Shim to provide more structured access to sysprops from Rust.
2 
3 use crate::bindings::root as bindings;
4 use crate::utils::LTCheckedPtr;
5 
6 /// List of properties accessible to Rust. Add new ones here as they become
7 /// necessary.
8 pub enum PropertyI32 {
9     // bluetooth.core.le
10     LeInquiryScanInterval,
11     LeInquiryScanWindow,
12 
13     // bluetooth.device_id
14     ProductId,
15     ProductVersion,
16     VendorId,
17     VendorIdSource,
18 }
19 
20 impl Into<(Vec<u8>, i32)> for PropertyI32 {
21     /// Convert the property into the property key name and a default value.
into(self) -> (Vec<u8>, i32)22     fn into(self) -> (Vec<u8>, i32) {
23         let (key, default_value) = match self {
24             // Inquiry scan interval  = N * 0.625 ms; value of 432 = 270ms
25             PropertyI32::LeInquiryScanInterval => ("bluetooth.core.le.inquiry_scan_interval", 430),
26 
27             //Inquiry scan window  = N * 0.625 ms; value of 216 = 135ms
28             PropertyI32::LeInquiryScanWindow => ("bluetooth.core.le.inquiry_scan_window", 216),
29 
30             PropertyI32::ProductId => ("bluetooth.device_id.product_id", 0),
31             PropertyI32::ProductVersion => ("bluetooth.device_id.product_version", 0),
32 
33             // Vendor ID defaults to Google (0xE0)
34             PropertyI32::VendorId => ("bluetooth.device_id.vendor_id", 0xE0),
35 
36             // Vendor ID source defaults to Bluetooth Sig (0x1)
37             PropertyI32::VendorIdSource => ("bluetooth.device_id.vendor_id_source", 0x1),
38         };
39 
40         (key.bytes().chain("\0".bytes()).collect::<Vec<u8>>(), default_value)
41     }
42 }
43 
44 /// Get the i32 value for a system property.
get_i32(prop: PropertyI32) -> i3245 pub fn get_i32(prop: PropertyI32) -> i32 {
46     let (key, default_value) = prop.into();
47     let key_cptr = LTCheckedPtr::from(&key);
48 
49     unsafe {
50         bindings::osi_property_get_int32(
51             key_cptr.cast_into::<std::os::raw::c_char>(),
52             default_value,
53         )
54     }
55 }
56