mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-09 22:56:35 +00:00
haze: abstract firmware version and serial number fetch
This commit is contained in:
parent
9f83b3c838
commit
8e2eca2004
6 changed files with 83 additions and 21 deletions
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include <haze/async_usb_server.hpp>
|
#include <haze/async_usb_server.hpp>
|
||||||
#include <haze/common.hpp>
|
#include <haze/common.hpp>
|
||||||
|
#include <haze/device_properties.hpp>
|
||||||
#include <haze/event_reactor.hpp>
|
#include <haze/event_reactor.hpp>
|
||||||
#include <haze/file_system_proxy.hpp>
|
#include <haze/file_system_proxy.hpp>
|
||||||
#include <haze/ptp.hpp>
|
#include <haze/ptp.hpp>
|
||||||
|
|
26
troposphere/haze/include/haze/device_properties.hpp
Normal file
26
troposphere/haze/include/haze/device_properties.hpp
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) Atmosphère-NX
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms and conditions of the GNU General Public License,
|
||||||
|
* version 2, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace haze {
|
||||||
|
|
||||||
|
Result LoadDeviceProperties();
|
||||||
|
|
||||||
|
const char *GetSerialNumber();
|
||||||
|
|
||||||
|
const char *GetFirmwareVersion();
|
||||||
|
|
||||||
|
}
|
50
troposphere/haze/source/device_properties.cpp
Normal file
50
troposphere/haze/source/device_properties.cpp
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) Atmosphère-NX
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms and conditions of the GNU General Public License,
|
||||||
|
* version 2, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include <haze.hpp>
|
||||||
|
|
||||||
|
namespace haze {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
constinit SetSysSerialNumber g_serial_number = {};
|
||||||
|
constinit SetSysFirmwareVersion g_firmware_version = {};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Result LoadDeviceProperties() {
|
||||||
|
/* Initialize set:sys. */
|
||||||
|
R_TRY(setsysInitialize());
|
||||||
|
|
||||||
|
/* Ensure we maintain a clean state on exit. */
|
||||||
|
ON_SCOPE_EXIT { setsysExit(); };
|
||||||
|
|
||||||
|
/* Get the serial number and firmware version. */
|
||||||
|
R_TRY(setsysGetSerialNumber(std::addressof(g_serial_number)));
|
||||||
|
R_TRY(setsysGetFirmwareVersion(std::addressof(g_firmware_version)));
|
||||||
|
|
||||||
|
/* We succeeded. */
|
||||||
|
R_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *GetSerialNumber() {
|
||||||
|
return g_serial_number.number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *GetFirmwareVersion() {
|
||||||
|
return g_firmware_version.display_version;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -17,6 +17,9 @@
|
||||||
#include <haze/console_main_loop.hpp>
|
#include <haze/console_main_loop.hpp>
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
/* Load device firmware version and serial number. */
|
||||||
|
HAZE_R_ABORT_UNLESS(haze::LoadDeviceProperties());
|
||||||
|
|
||||||
/* Run the application. */
|
/* Run the application. */
|
||||||
haze::ConsoleMainLoop::RunApplication();
|
haze::ConsoleMainLoop::RunApplication();
|
||||||
|
|
||||||
|
|
|
@ -304,16 +304,6 @@ 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));
|
||||||
|
@ -328,8 +318,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(version.display_version));
|
R_TRY(db.AddString(GetFirmwareVersion()));
|
||||||
R_TRY(db.AddString(serial.number));
|
R_TRY(db.AddString(GetSerialNumber()));
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -165,19 +165,11 @@ 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. */
|
|
||||||
SetSysSerialNumber serial;
|
|
||||||
R_TRY(setsysGetSerialNumber(std::addressof(serial)));
|
|
||||||
|
|
||||||
/* Report strings. */
|
/* Report strings. */
|
||||||
u8 iManufacturer, iProduct, iSerialNumber;
|
u8 iManufacturer, iProduct, iSerialNumber;
|
||||||
R_TRY(usbDsAddUsbStringDescriptor(std::addressof(iManufacturer), "Nintendo"));
|
R_TRY(usbDsAddUsbStringDescriptor(std::addressof(iManufacturer), "Nintendo"));
|
||||||
R_TRY(usbDsAddUsbStringDescriptor(std::addressof(iProduct), "Nintendo Switch"));
|
R_TRY(usbDsAddUsbStringDescriptor(std::addressof(iProduct), "Nintendo Switch"));
|
||||||
R_TRY(usbDsAddUsbStringDescriptor(std::addressof(iSerialNumber), serial.number));
|
R_TRY(usbDsAddUsbStringDescriptor(std::addressof(iSerialNumber), GetSerialNumber()));
|
||||||
|
|
||||||
/* Send device descriptors */
|
/* Send device descriptors */
|
||||||
struct usb_device_descriptor device_descriptor = {
|
struct usb_device_descriptor device_descriptor = {
|
||||||
|
|
Loading…
Reference in a new issue