Loading system/gd/rust/linux/mgmt/src/migrate.rs +82 −45 Original line number Diff line number Diff line Loading @@ -360,16 +360,16 @@ fn convert_from_bluez_device( continue; } let mut map: HashMap<&str, DeviceKey> = if is_hid_file { let mut map: HashMap<&str, Vec<DeviceKey>> = if is_hid_file { match sec.as_str() { REPORT_MAP_SECTION_NAME => [( "report_map", DeviceKey::new("HidDescriptor", KeyAction::Apply(Converter::Base64ToHex)), vec![DeviceKey::new("HidDescriptor", KeyAction::Apply(Converter::Base64ToHex))], )] .into(), GENERAL_SECTION_NAME => [ ("bcdhid", DeviceKey::new("HidVersion", KeyAction::WrapOk)), ("bcountrycode", DeviceKey::new("HidCountryCode", KeyAction::WrapOk)), ("bcdhid", vec![DeviceKey::new("HidVersion", KeyAction::WrapOk)]), ("bcountrycode", vec![DeviceKey::new("HidCountryCode", KeyAction::WrapOk)]), ] .into(), _ => [].into(), Loading @@ -378,42 +378,73 @@ fn convert_from_bluez_device( // info file match sec.as_str() { GENERAL_SECTION_NAME => [ ("Name", DeviceKey::new("Name", KeyAction::WrapOk)), ("Class", DeviceKey::new("DevClass", KeyAction::Apply(Converter::HexToDec))), ("Name", vec![DeviceKey::new("Name", KeyAction::WrapOk)]), ( "Class", vec![DeviceKey::new("DevClass", KeyAction::Apply(Converter::HexToDec))], ), ( "Appearance", vec![DeviceKey::new("Appearance", KeyAction::Apply(Converter::HexToDec))], ), ( "SupportedTechnologies", DeviceKey::new("DevType", KeyAction::Apply(Converter::TypeB2F)), vec![DeviceKey::new("DevType", KeyAction::Apply(Converter::TypeB2F))], ), ( "Services", DeviceKey::new( vec![DeviceKey::new( "Service", KeyAction::Apply(Converter::ReplaceSemiColonWithSpace), ), )], ), ( "AddressType", DeviceKey::new("AddrType", KeyAction::Apply(Converter::AddrTypeB2F)), vec![DeviceKey::new("AddrType", KeyAction::Apply(Converter::AddrTypeB2F))], ), ] .into(), LINKKEY_SECTION_NAME => [ ( "Key", DeviceKey::new( vec![DeviceKey::new( "LinkKey", KeyAction::Apply(Converter::ReverseEndianLowercase), )], ), ), ("Type", DeviceKey::new("LinkKeyType", KeyAction::WrapOk)), ("PINLength", DeviceKey::new("PinLength", KeyAction::WrapOk)), ("Type", vec![DeviceKey::new("LinkKeyType", KeyAction::WrapOk)]), ("PINLength", vec![DeviceKey::new("PinLength", KeyAction::WrapOk)]), ] .into(), DEVICEID_SECTION_NAME => [ ("Source", DeviceKey::new("SdpDiVendorIdSource", KeyAction::WrapOk)), ("Vendor", DeviceKey::new("SdpDiManufacturer", KeyAction::WrapOk)), ("Product", DeviceKey::new("SdpDiModel", KeyAction::WrapOk)), ("Version", DeviceKey::new("SdpDiHardwareVersion", KeyAction::WrapOk)), ( "Source", vec![ DeviceKey::new("SdpDiVendorIdSource", KeyAction::WrapOk), DeviceKey::new("VendorIdSource", KeyAction::WrapOk), ], ), ( "Vendor", vec![ DeviceKey::new("SdpDiManufacturer", KeyAction::WrapOk), DeviceKey::new("VendorId", KeyAction::WrapOk), ], ), ( "Product", vec![ DeviceKey::new("SdpDiModel", KeyAction::WrapOk), DeviceKey::new("ProductId", KeyAction::WrapOk), ], ), ( "Version", vec![ DeviceKey::new("SdpDiHardwareVersion", KeyAction::WrapOk), DeviceKey::new("ProductVersion", KeyAction::WrapOk), ], ), ] .into(), _ => [].into(), Loading @@ -423,8 +454,9 @@ fn convert_from_bluez_device( // Do the conversion for all keys found in BlueZ for (k, v) in props { match map.get_mut(k.as_str()) { Some(key) => { let new_val = match key.apply_action(v.unwrap_or_default()) { Some(keys) => { for key in keys { let new_val = match key.apply_action(v.clone().unwrap_or_default()) { Ok(val) => val, Err(err) => { error!( Loading @@ -438,6 +470,7 @@ fn convert_from_bluez_device( }; floss_conf.set(addr_lower.as_str(), key.key.clone(), Some(new_val)); } } None => { debug!("No key match: {}", k); } Loading Loading @@ -601,6 +634,13 @@ fn convert_floss_conf(filename: &str) { KeyAction::ApplyToSection(Converter::DecToHex, GENERAL_SECTION_NAME), ), ), ( "Appearance", DeviceKey::new( "Appearance", KeyAction::ApplyToSection(Converter::DecToHex, GENERAL_SECTION_NAME), ), ), ( "DevType", DeviceKey::new( Loading Loading @@ -636,19 +676,10 @@ fn convert_floss_conf(filename: &str) { ("LinkKeyType", DeviceKey::new("Type", KeyAction::ToSection(LINKKEY_SECTION_NAME))), ("PinLength", DeviceKey::new("PINLength", KeyAction::ToSection(LINKKEY_SECTION_NAME))), // DeviceID ( "SdpDiVendorIdSource", DeviceKey::new("Source", KeyAction::ToSection(DEVICEID_SECTION_NAME)), ), ( "SdpDiManufacturer", DeviceKey::new("Vendor", KeyAction::ToSection(DEVICEID_SECTION_NAME)), ), ("SdpDiModel", DeviceKey::new("Product", KeyAction::ToSection(DEVICEID_SECTION_NAME))), ( "SdpDiHardwareVersion", DeviceKey::new("Version", KeyAction::ToSection(DEVICEID_SECTION_NAME)), ), ("VendorIdSource", DeviceKey::new("Source", KeyAction::ToSection(DEVICEID_SECTION_NAME))), ("VendorId", DeviceKey::new("Vendor", KeyAction::ToSection(DEVICEID_SECTION_NAME))), ("ProductId", DeviceKey::new("Product", KeyAction::ToSection(DEVICEID_SECTION_NAME))), ("ProductVersion", DeviceKey::new("Version", KeyAction::ToSection(DEVICEID_SECTION_NAME))), ( "LE_KEY_PID", DeviceKey::new( Loading Loading @@ -1015,6 +1046,7 @@ mod tests { assert_eq!(conf.get(test_addr, "Name"), Some(String::from("Test Device"))); assert_eq!(conf.get(test_addr, "DevClass"), Some(String::from("2360344"))); assert_eq!(conf.get(test_addr, "Appearance"), Some(String::from("962"))); assert_eq!(conf.get(test_addr, "DevType"), Some(String::from("1"))); assert_eq!( conf.get(test_addr, "Service"), Loading @@ -1036,6 +1068,11 @@ mod tests { assert_eq!(conf.get(test_addr, "SdpDiModel"), Some(String::from("22222"))); assert_eq!(conf.get(test_addr, "SdpDiHardwareVersion"), Some(String::from("3"))); assert_eq!(conf.get(test_addr, "VendorIdSource"), Some(String::from("1"))); assert_eq!(conf.get(test_addr, "VendorId"), Some(String::from("100"))); assert_eq!(conf.get(test_addr, "ProductId"), Some(String::from("22222"))); assert_eq!(conf.get(test_addr, "ProductVersion"), Some(String::from("3"))); assert_eq!( conf.get(test_addr, "LE_KEY_PID"), Some(String::from("ffeeddccbbaa9988776655443322110001001122334455")) Loading system/gd/rust/linux/mgmt/test/migrate/fake_bluez_info.toml +1 −0 Original line number Diff line number Diff line [General] Name=Test Device Class=0x240418 Appearance=0x03c2 SupportedTechnologies=BR/EDR; Services=0000110b-0000-1000-8000-00805f9b34fb;0000110c-0000-1000-8000-00805f9b34fb; AddressType=static Loading Loading
system/gd/rust/linux/mgmt/src/migrate.rs +82 −45 Original line number Diff line number Diff line Loading @@ -360,16 +360,16 @@ fn convert_from_bluez_device( continue; } let mut map: HashMap<&str, DeviceKey> = if is_hid_file { let mut map: HashMap<&str, Vec<DeviceKey>> = if is_hid_file { match sec.as_str() { REPORT_MAP_SECTION_NAME => [( "report_map", DeviceKey::new("HidDescriptor", KeyAction::Apply(Converter::Base64ToHex)), vec![DeviceKey::new("HidDescriptor", KeyAction::Apply(Converter::Base64ToHex))], )] .into(), GENERAL_SECTION_NAME => [ ("bcdhid", DeviceKey::new("HidVersion", KeyAction::WrapOk)), ("bcountrycode", DeviceKey::new("HidCountryCode", KeyAction::WrapOk)), ("bcdhid", vec![DeviceKey::new("HidVersion", KeyAction::WrapOk)]), ("bcountrycode", vec![DeviceKey::new("HidCountryCode", KeyAction::WrapOk)]), ] .into(), _ => [].into(), Loading @@ -378,42 +378,73 @@ fn convert_from_bluez_device( // info file match sec.as_str() { GENERAL_SECTION_NAME => [ ("Name", DeviceKey::new("Name", KeyAction::WrapOk)), ("Class", DeviceKey::new("DevClass", KeyAction::Apply(Converter::HexToDec))), ("Name", vec![DeviceKey::new("Name", KeyAction::WrapOk)]), ( "Class", vec![DeviceKey::new("DevClass", KeyAction::Apply(Converter::HexToDec))], ), ( "Appearance", vec![DeviceKey::new("Appearance", KeyAction::Apply(Converter::HexToDec))], ), ( "SupportedTechnologies", DeviceKey::new("DevType", KeyAction::Apply(Converter::TypeB2F)), vec![DeviceKey::new("DevType", KeyAction::Apply(Converter::TypeB2F))], ), ( "Services", DeviceKey::new( vec![DeviceKey::new( "Service", KeyAction::Apply(Converter::ReplaceSemiColonWithSpace), ), )], ), ( "AddressType", DeviceKey::new("AddrType", KeyAction::Apply(Converter::AddrTypeB2F)), vec![DeviceKey::new("AddrType", KeyAction::Apply(Converter::AddrTypeB2F))], ), ] .into(), LINKKEY_SECTION_NAME => [ ( "Key", DeviceKey::new( vec![DeviceKey::new( "LinkKey", KeyAction::Apply(Converter::ReverseEndianLowercase), )], ), ), ("Type", DeviceKey::new("LinkKeyType", KeyAction::WrapOk)), ("PINLength", DeviceKey::new("PinLength", KeyAction::WrapOk)), ("Type", vec![DeviceKey::new("LinkKeyType", KeyAction::WrapOk)]), ("PINLength", vec![DeviceKey::new("PinLength", KeyAction::WrapOk)]), ] .into(), DEVICEID_SECTION_NAME => [ ("Source", DeviceKey::new("SdpDiVendorIdSource", KeyAction::WrapOk)), ("Vendor", DeviceKey::new("SdpDiManufacturer", KeyAction::WrapOk)), ("Product", DeviceKey::new("SdpDiModel", KeyAction::WrapOk)), ("Version", DeviceKey::new("SdpDiHardwareVersion", KeyAction::WrapOk)), ( "Source", vec![ DeviceKey::new("SdpDiVendorIdSource", KeyAction::WrapOk), DeviceKey::new("VendorIdSource", KeyAction::WrapOk), ], ), ( "Vendor", vec![ DeviceKey::new("SdpDiManufacturer", KeyAction::WrapOk), DeviceKey::new("VendorId", KeyAction::WrapOk), ], ), ( "Product", vec![ DeviceKey::new("SdpDiModel", KeyAction::WrapOk), DeviceKey::new("ProductId", KeyAction::WrapOk), ], ), ( "Version", vec![ DeviceKey::new("SdpDiHardwareVersion", KeyAction::WrapOk), DeviceKey::new("ProductVersion", KeyAction::WrapOk), ], ), ] .into(), _ => [].into(), Loading @@ -423,8 +454,9 @@ fn convert_from_bluez_device( // Do the conversion for all keys found in BlueZ for (k, v) in props { match map.get_mut(k.as_str()) { Some(key) => { let new_val = match key.apply_action(v.unwrap_or_default()) { Some(keys) => { for key in keys { let new_val = match key.apply_action(v.clone().unwrap_or_default()) { Ok(val) => val, Err(err) => { error!( Loading @@ -438,6 +470,7 @@ fn convert_from_bluez_device( }; floss_conf.set(addr_lower.as_str(), key.key.clone(), Some(new_val)); } } None => { debug!("No key match: {}", k); } Loading Loading @@ -601,6 +634,13 @@ fn convert_floss_conf(filename: &str) { KeyAction::ApplyToSection(Converter::DecToHex, GENERAL_SECTION_NAME), ), ), ( "Appearance", DeviceKey::new( "Appearance", KeyAction::ApplyToSection(Converter::DecToHex, GENERAL_SECTION_NAME), ), ), ( "DevType", DeviceKey::new( Loading Loading @@ -636,19 +676,10 @@ fn convert_floss_conf(filename: &str) { ("LinkKeyType", DeviceKey::new("Type", KeyAction::ToSection(LINKKEY_SECTION_NAME))), ("PinLength", DeviceKey::new("PINLength", KeyAction::ToSection(LINKKEY_SECTION_NAME))), // DeviceID ( "SdpDiVendorIdSource", DeviceKey::new("Source", KeyAction::ToSection(DEVICEID_SECTION_NAME)), ), ( "SdpDiManufacturer", DeviceKey::new("Vendor", KeyAction::ToSection(DEVICEID_SECTION_NAME)), ), ("SdpDiModel", DeviceKey::new("Product", KeyAction::ToSection(DEVICEID_SECTION_NAME))), ( "SdpDiHardwareVersion", DeviceKey::new("Version", KeyAction::ToSection(DEVICEID_SECTION_NAME)), ), ("VendorIdSource", DeviceKey::new("Source", KeyAction::ToSection(DEVICEID_SECTION_NAME))), ("VendorId", DeviceKey::new("Vendor", KeyAction::ToSection(DEVICEID_SECTION_NAME))), ("ProductId", DeviceKey::new("Product", KeyAction::ToSection(DEVICEID_SECTION_NAME))), ("ProductVersion", DeviceKey::new("Version", KeyAction::ToSection(DEVICEID_SECTION_NAME))), ( "LE_KEY_PID", DeviceKey::new( Loading Loading @@ -1015,6 +1046,7 @@ mod tests { assert_eq!(conf.get(test_addr, "Name"), Some(String::from("Test Device"))); assert_eq!(conf.get(test_addr, "DevClass"), Some(String::from("2360344"))); assert_eq!(conf.get(test_addr, "Appearance"), Some(String::from("962"))); assert_eq!(conf.get(test_addr, "DevType"), Some(String::from("1"))); assert_eq!( conf.get(test_addr, "Service"), Loading @@ -1036,6 +1068,11 @@ mod tests { assert_eq!(conf.get(test_addr, "SdpDiModel"), Some(String::from("22222"))); assert_eq!(conf.get(test_addr, "SdpDiHardwareVersion"), Some(String::from("3"))); assert_eq!(conf.get(test_addr, "VendorIdSource"), Some(String::from("1"))); assert_eq!(conf.get(test_addr, "VendorId"), Some(String::from("100"))); assert_eq!(conf.get(test_addr, "ProductId"), Some(String::from("22222"))); assert_eq!(conf.get(test_addr, "ProductVersion"), Some(String::from("3"))); assert_eq!( conf.get(test_addr, "LE_KEY_PID"), Some(String::from("ffeeddccbbaa9988776655443322110001001122334455")) Loading
system/gd/rust/linux/mgmt/test/migrate/fake_bluez_info.toml +1 −0 Original line number Diff line number Diff line [General] Name=Test Device Class=0x240418 Appearance=0x03c2 SupportedTechnologies=BR/EDR; Services=0000110b-0000-1000-8000-00805f9b34fb;0000110c-0000-1000-8000-00805f9b34fb; AddressType=static Loading