1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-09-19 21:43:44 +01:00
nxdumptool/include/core/usb.h
Pablo Curiel fb58d20fe3 I'm a terrible person and an even worse developer.
And I don't need anyone to tell me so, thank you very much.

* PoC: remove gc_dumper and nsp_dumper PoC; create nxdt_rw_poc with all gc_dumper and nsp_dumper capabilities + standalone ticket dumping + raw NCA dumping; use ftruncate() to set output file sizes whenever possible. PoC code is a mess, as always. Expect the features from the rest of the PoCs to be implemented into nxdt_rw_poc soon.

* workflow: temporarily disable borealis build generation; comment out manual installation of up-to-date packages from Leseratte's mirrors because the latest devkitA64 Docker image has them all.

* borealis: update to fix building issues with latest devkitA64.

* bfttf: error out on invalid NCA signatures.

* config: save configuration to the current working directory; parse and validate new "gamecard/write_raw_hfs_partition" flag.

* defines: remove CONFIG_PATH macro; rename CONFIG_FILE_NAME.

* gamecard: rename fs_ctx -> hfs_ctx everywhere; use HFS function calls to retrieve partition names.

* hfs: move GameCardHashFileSystemPartitionType enum from gamecard.h and rename it to HashFileSystemPartitionType; add hfsIsValidContext(); add hfsGetPartitionNameString().

* nca/npdm: update comments to reflect latest HOS version.

* nxdt_bfsar: always generate absolute SD card paths with the device name; error out on an invalid NCA signature.

* nxdt_includes: include dirent.h; refactor Version struct to make it a union of all known *Version structs.

* nxdt_log: don't write session separator if the logfile is empty.

* nxdt_utils: log appletIsGamePlayRecordingSupported() errors; add utilsDeleteDirectoryRecursively().

* rsa: provide clearer function descriptions in header file.

* services: handle usb:ds initialization.

* tik: update tikConvertPersonalizedTicketToCommonTicket() to allow NULL input pointers as raw certificate chain arguments (much needed for standalone ticket dumping).

* title: add titleGetApplicationIdByMetaKey().

* usb: refactor interface (de)initialization code; slightly improve ABI usage (console-side only); redefine ABI version field in StartSession command blocks; upgrade ABI to v1.1.

* FatFs: rename DIR -> FDIR to avoid conflicts with definitions from stdlib's dirent.h.

* gamecard_tab: display package ID from the inserted gamecard; fix displayed version numbers from bundled system updates below 3.0.0.

* todo: add notes about creating devoptab devices for HFS/PFS/RomFS file tree dumping.
2023-05-24 21:05:34 +02:00

88 lines
4.3 KiB
C

/*
* usb.h
*
* Heavily based in usb_comms from libnx.
*
* Copyright (c) 2018-2020, Switchbrew and libnx contributors.
* Copyright (c) 2020-2023, DarkMatterCore <pabloacurielz@gmail.com>.
*
* This file is part of nxdumptool (https://github.com/DarkMatterCore/nxdumptool).
*
* nxdumptool is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nxdumptool is distributed in the hope that 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifndef __USB_H__
#define __USB_H__
#ifdef __cplusplus
extern "C" {
#endif
#define USB_TRANSFER_BUFFER_SIZE 0x800000 /* 8 MiB. */
/// Used to indicate the USB speed selected by the host device.
typedef enum {
UsbHostSpeed_None = 0,
UsbHostSpeed_FullSpeed = 1, ///< USB 1.x.
UsbHostSpeed_HighSpeed = 2, ///< USB 2.0.
UsbHostSpeed_SuperSpeed = 3 ///< USB 3.0.
} UsbHostSpeed;
/// Initializes the USB interface, input and output endpoints and allocates an internal transfer buffer.
bool usbInitialize(void);
/// Closes the USB interface, input and output endpoints and frees the transfer buffer.
void usbExit(void);
/// Returns a pointer to a dynamically allocated, page aligned memory buffer that's suitable for USB transfers.
void *usbAllocatePageAlignedBuffer(size_t size);
/// Used to check if the console has been connected to a USB host device and if a valid USB session has been established.
/// Returns a value from the UsbHostSpeed enum.
u8 usbIsReady(void);
/// Sends file properties to the host device before starting a file data transfer. If needed, it must be called before usbSendFileData().
/// 'file_size' may be zero if an empty file shall be created, in which case no file data transfer will be necessary.
/// Calling this function before finishing an ongoing file data transfer will result in an error.
/// Under NSP transfer mode, this function must be called right before transferring data from each NSP file entry to the host device, which should in turn write it all to the same output file.
bool usbSendFileProperties(u64 file_size, const char *filename);
/// Sends NSP properties to the host device and enables NSP transfer mode. If needed, it must be called before usbSendFileData().
/// Both 'nsp_size' and 'nsp_header_size' must be greater than zero. 'nsp_size' must also be greater than 'nsp_header_size'.
/// Calling this function after NSP transfer mode has already been enabled will result in an error.
/// The host device should immediately write 'nsp_header_size' padding at the start of the output file and start listening for further usbSendFileProperties() calls, or a usbSendNspHeader() call.
bool usbSendNspProperties(u64 nsp_size, const char *filename, u32 nsp_header_size);
/// Performs a file data transfer. Must be continuously called after usbSendFileProperties() / usbSendNspProperties() until all file data has been transferred.
/// Data chunk size must not exceed USB_TRANSFER_BUFFER_SIZE.
/// If the last file data chunk is aligned to the endpoint max packet size, the host device should expect a Zero Length Termination (ZLT) packet.
/// Calling this function if there's no remaining data to transfer will result in an error.
bool usbSendFileData(void *data, u64 data_size);
/// Used to gracefully cancel an ongoing file transfer. The current USB session is kept alive.
void usbCancelFileTransfer(void);
/// Sends NSP header data to the host device, making it rewind the NSP file pointer to write this data, essentially finishing the NSP transfer process.
/// Must be called after the data from all NSP file entries has been transferred using both usbSendNspProperties() and usbSendFileData() calls.
/// If the NSP header size is aligned to the endpoint max packet size, the host device should expect a Zero Length Termination (ZLT) packet.
bool usbSendNspHeader(void *nsp_header, u32 nsp_header_size);
#ifdef __cplusplus
}
#endif
#endif /* __USB_H__ */