diff --git a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp index 8fc7f848d..b4e5e816f 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp @@ -102,7 +102,7 @@ namespace ams::mitm::settings { return file_exists; } - Result ReadExternalBluetoothDatabase(s32 *entries_read, SetSysBluetoothDevicesSettings *db, size_t db_max_size) { + Result ReadExternalBluetoothDatabase(s32 *entries_read, settings::BluetoothDevicesSettings *db, size_t db_max_size) { /* Open external database file. */ fs::FileHandle file; R_TRY(fs::OpenFile(std::addressof(file), ExternalBluetoothDatabasePath, fs::OpenMode_Read)); @@ -118,17 +118,17 @@ namespace ams::mitm::settings { total_entries = db_max_size; /* Pairings are stored from least to most recent. Add offset to skip the older entries that won't fit. */ - db_offset += (total_entries - db_max_size) * sizeof(SetSysBluetoothDevicesSettings); + db_offset += (total_entries - db_max_size) * sizeof(settings::BluetoothDevicesSettings); } /* Read database entries. */ - R_TRY(fs::ReadFile(file, db_offset, db, total_entries * sizeof(SetSysBluetoothDevicesSettings))); + R_TRY(fs::ReadFile(file, db_offset, db, total_entries * sizeof(settings::BluetoothDevicesSettings))); /* Convert to old database format if running on a firmware below 13.0.0. */ if (hos::GetVersion() < hos::Version_13_0_0) { for (size_t i = 0; i < total_entries; ++i) { /* Copy as many chars from currently used name field as we can fit in the original one. */ - util::SNPrintf(db[i].name.name, sizeof(db[i].name), "%s", db[i].name2); + util::SNPrintf(db[i].name, sizeof(db[i].name), "%s", db[i].name2); /* Clear the current name field. */ std::memset(db[i].name2, 0, sizeof(db[i].name2)); @@ -140,14 +140,14 @@ namespace ams::mitm::settings { R_SUCCEED(); } - Result StoreExternalBluetoothDatabase(const SetSysBluetoothDevicesSettings *db, size_t total_entries) { + Result StoreExternalBluetoothDatabase(const settings::BluetoothDevicesSettings *db, size_t total_entries) { /* Open external database file. */ fs::FileHandle file; R_TRY(fs::OpenFile(std::addressof(file), ExternalBluetoothDatabasePath, fs::OpenMode_Write)); ON_SCOPE_EXIT { fs::CloseFile(file); }; /* Set file size to accomodate all database entries */ - R_TRY(fs::SetFileSize(file, sizeof(total_entries) + total_entries * sizeof(SetSysBluetoothDevicesSettings))); + R_TRY(fs::SetFileSize(file, sizeof(total_entries) + total_entries * sizeof(settings::BluetoothDevicesSettings))); /* Write number of database entries. */ R_TRY(fs::WriteFile(file, 0, std::addressof(total_entries), sizeof(total_entries), fs::WriteOption::None)); @@ -156,26 +156,26 @@ namespace ams::mitm::settings { u64 db_offset = sizeof(total_entries); if (hos::GetVersion() < hos::Version_13_0_0) { /* Convert to new database format if running on a firmware below 13.0.0 */ - auto tmp_entry = std::make_unique(); + settings::BluetoothDevicesSettings tmp_entry; for (size_t i = 0; i < total_entries; ++i) { /* Take a copy of the current database entry. */ - std::memcpy(tmp_entry.get(), std::addressof(db[i]), sizeof(SetSysBluetoothDevicesSettings)); + std::memcpy(std::addressof(tmp_entry), std::addressof(db[i]), sizeof(settings::BluetoothDevicesSettings)); /* Copy the name field from the original location to the currently used one. */ - util::SNPrintf(tmp_entry->name2, sizeof(tmp_entry->name2), "%s", db[i].name.name); + util::SNPrintf(tmp_entry.name2, sizeof(tmp_entry.name2), "%s", db[i].name); /* Clear the original name field. */ - std::memset(std::addressof(tmp_entry->name), 0, sizeof(tmp_entry->name)); + std::memset(std::addressof(tmp_entry.name), 0, sizeof(tmp_entry.name)); /* Write the converted database entry. */ - R_TRY(fs::WriteFile(file, db_offset, tmp_entry.get(), sizeof(SetSysBluetoothDevicesSettings), fs::WriteOption::None)); + R_TRY(fs::WriteFile(file, db_offset, &tmp_entry, sizeof(settings::BluetoothDevicesSettings), fs::WriteOption::None)); /* Increment offset to the next database entry. */ - db_offset += sizeof(SetSysBluetoothDevicesSettings); + db_offset += sizeof(settings::BluetoothDevicesSettings); } fs::FlushFile(file); } else { - R_TRY(fs::WriteFile(file, db_offset, db, total_entries * sizeof(SetSysBluetoothDevicesSettings), fs::WriteOption::Flush)); + R_TRY(fs::WriteFile(file, db_offset, db, total_entries * sizeof(settings::BluetoothDevicesSettings), fs::WriteOption::Flush)); } R_SUCCEED(); @@ -196,7 +196,7 @@ namespace ams::mitm::settings { R_RETURN(GetFirmwareVersionImpl(out.GetPointer(), m_client_info)); } - Result SetSysMitmService::SetBluetoothDevicesSettings(const sf::InMapAliasArray &settings) { + Result SetSysMitmService::SetBluetoothDevicesSettings(const sf::InMapAliasArray &settings) { /* Forward to session unless external database setting enabled. */ R_UNLESS(ExternalBluetoothDatabaseEnabled(), sm::mitm::ResultShouldForwardToSession()); @@ -209,18 +209,20 @@ namespace ams::mitm::settings { R_TRY(StoreExternalBluetoothDatabase(settings.GetPointer(), settings.GetSize())); /* Also allow the updated database to be stored to system save as usual. */ - R_TRY(setsysSetBluetoothDevicesSettingsFwd(m_forward_service.get(), settings.GetPointer(), settings.GetSize())); + static_assert(sizeof(settings::BluetoothDevicesSettings) == sizeof(::SetSysBluetoothDevicesSettings)); + R_TRY(setsysSetBluetoothDevicesSettingsFwd(m_forward_service.get(), reinterpret_cast(settings.GetPointer()), settings.GetSize())); R_SUCCEED(); } - Result SetSysMitmService::GetBluetoothDevicesSettings(sf::Out out_count, const sf::OutMapAliasArray &out) { + Result SetSysMitmService::GetBluetoothDevicesSettings(sf::Out out_count, const sf::OutMapAliasArray &out) { /* Forward to session unless external database setting enabled. */ R_UNLESS(ExternalBluetoothDatabaseEnabled(), sm::mitm::ResultShouldForwardToSession()); if (!HasExternalBluetoothDatabase()) { /* Forward to the real command to fetch database stored in system save. */ - R_TRY(setsysGetBluetoothDevicesSettingsFwd(m_forward_service.get(), out_count.GetPointer(), out.GetPointer(), out.GetSize())); + static_assert(sizeof(settings::BluetoothDevicesSettings) == sizeof(::SetSysBluetoothDevicesSettings)); + R_TRY(setsysGetBluetoothDevicesSettingsFwd(m_forward_service.get(), out_count.GetPointer(), reinterpret_cast<::SetSysBluetoothDevicesSettings *>(out.GetPointer()), out.GetSize())); /* Create the external database file. */ R_TRY(fs::CreateFile(ExternalBluetoothDatabasePath, 0)); diff --git a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.hpp b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.hpp index fdbace1bc..f61a0bf28 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.hpp @@ -19,8 +19,8 @@ #define AMS_SETTINGS_SYSTEM_MITM_INTERFACE_INFO(C, H) \ AMS_SF_METHOD_INFO(C, H, 3, Result, GetFirmwareVersion, (sf::Out out), (out)) \ AMS_SF_METHOD_INFO(C, H, 4, Result, GetFirmwareVersion2, (sf::Out out), (out)) \ - AMS_SF_METHOD_INFO(C, H, 11, Result, SetBluetoothDevicesSettings, (const sf::InMapAliasArray &settings), (settings)) \ - AMS_SF_METHOD_INFO(C, H, 12, Result, GetBluetoothDevicesSettings, (sf::Out out_count, const sf::OutMapAliasArray &out), (out_count, out)) \ + AMS_SF_METHOD_INFO(C, H, 11, Result, SetBluetoothDevicesSettings, (const sf::InMapAliasArray &settings), (settings)) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, GetBluetoothDevicesSettings, (sf::Out out_count, const sf::OutMapAliasArray &out), (out_count, out)) \ AMS_SF_METHOD_INFO(C, H, 37, Result, GetSettingsItemValueSize, (sf::Out out_size, const ams::settings::SettingsName &name, const ams::settings::SettingsItemKey &key), (out_size, name, key)) \ AMS_SF_METHOD_INFO(C, H, 38, Result, GetSettingsItemValue, (sf::Out out_size, const sf::OutBuffer &out, const ams::settings::SettingsName &name, const ams::settings::SettingsItemKey &key), (out_size, out, name, key)) \ AMS_SF_METHOD_INFO(C, H, 62, Result, GetDebugModeFlag, (sf::Out out), (out)) @@ -43,8 +43,8 @@ namespace ams::mitm::settings { public: Result GetFirmwareVersion(sf::Out out); Result GetFirmwareVersion2(sf::Out out); - Result SetBluetoothDevicesSettings(const sf::InMapAliasArray &settings); - Result GetBluetoothDevicesSettings(sf::Out out_count, const sf::OutMapAliasArray &out); + Result SetBluetoothDevicesSettings(const sf::InMapAliasArray &settings); + Result GetBluetoothDevicesSettings(sf::Out out_count, const sf::OutMapAliasArray &out); Result GetSettingsItemValueSize(sf::Out out_size, const ams::settings::SettingsName &name, const ams::settings::SettingsItemKey &key); Result GetSettingsItemValue(sf::Out out_size, const sf::OutBuffer &out, const ams::settings::SettingsName &name, const ams::settings::SettingsItemKey &key); Result GetDebugModeFlag(sf::Out out);