haze: get serial number and firmware version from set:sys

This commit is contained in:
Liam 2023-04-17 22:22:28 -04:00
parent 4b3c801e9f
commit a346014dc7
2 changed files with 17 additions and 7 deletions

View file

@ -37,9 +37,7 @@ namespace haze {
constexpr auto MtpVendorExtensionDesc = "microsoft.com: 1.0;"; constexpr auto MtpVendorExtensionDesc = "microsoft.com: 1.0;";
constexpr u16 MtpFunctionalModeDefault = 0; constexpr u16 MtpFunctionalModeDefault = 0;
constexpr auto MtpDeviceManufacturer = "Nintendo"; constexpr auto MtpDeviceManufacturer = "Nintendo";
constexpr auto MtpDeviceModel = "Switch"; constexpr auto MtpDeviceModel = "Nintendo Switch";
constexpr auto MtpDeviceVersion = "1.0.0";
constexpr auto MtpDeviceSerialNumber = "SerialNumber";
enum StorageId : u32 { enum StorageId : u32 {
StorageId_SdmcFs = 0xffffffffu - 1, StorageId_SdmcFs = 0xffffffffu - 1,
@ -306,6 +304,16 @@ namespace haze {
Result PtpResponder::GetDeviceInfo(PtpDataParser &dp) { Result PtpResponder::GetDeviceInfo(PtpDataParser &dp) {
PtpDataBuilder db(g_bulk_write_buffer, std::addressof(m_usb_server)); PtpDataBuilder db(g_bulk_write_buffer, std::addressof(m_usb_server));
/* Initialize set:sys, ensuring we clean up on exit. */
R_TRY(setsysInitialize());
ON_SCOPE_EXIT { setsysExit(); };
/* Get the device version and serial number. */
SetSysFirmwareVersion version;
SetSysSerialNumber serial;
R_TRY(setsysGetFirmwareVersion(std::addressof(version)));
R_TRY(setsysGetSerialNumber(std::addressof(serial)));
/* Write the device info data. */ /* Write the device info data. */
R_TRY(db.WriteVariableLengthData(m_request_header, [&] () { R_TRY(db.WriteVariableLengthData(m_request_header, [&] () {
R_TRY(db.Add(MtpStandardVersion)); R_TRY(db.Add(MtpStandardVersion));
@ -320,8 +328,8 @@ namespace haze {
R_TRY(db.AddArray(SupportedPlaybackFormats, util::size(SupportedPlaybackFormats))); R_TRY(db.AddArray(SupportedPlaybackFormats, util::size(SupportedPlaybackFormats)));
R_TRY(db.AddString(MtpDeviceManufacturer)); R_TRY(db.AddString(MtpDeviceManufacturer));
R_TRY(db.AddString(MtpDeviceModel)); R_TRY(db.AddString(MtpDeviceModel));
R_TRY(db.AddString(MtpDeviceVersion)); R_TRY(db.AddString(version.display_version));
R_TRY(db.AddString(MtpDeviceSerialNumber)); R_TRY(db.AddString(serial.number));
R_SUCCEED(); R_SUCCEED();
})); }));

View file

@ -165,11 +165,13 @@ namespace haze {
static const u16 supported_langs[1] = { 0x0409 }; static const u16 supported_langs[1] = { 0x0409 };
R_TRY(usbDsAddUsbLanguageStringDescriptor(nullptr, supported_langs, util::size(supported_langs))); R_TRY(usbDsAddUsbLanguageStringDescriptor(nullptr, supported_langs, util::size(supported_langs)));
/* Initialize set:sys, ensuring we clean up on exit. */
R_TRY(setsysInitialize());
ON_SCOPE_EXIT { setsysExit(); };
/* Get the device serial number. */ /* Get the device serial number. */
SetSysSerialNumber serial; SetSysSerialNumber serial;
R_TRY(setsysInitialize());
R_TRY(setsysGetSerialNumber(std::addressof(serial))); R_TRY(setsysGetSerialNumber(std::addressof(serial)));
setsysExit();
/* Report strings. */ /* Report strings. */
u8 iManufacturer, iProduct, iSerialNumber; u8 iManufacturer, iProduct, iSerialNumber;