mirror of
https://github.com/switchbrew/libnx.git
synced 2025-08-07 08:39:24 +02:00
Moved usb code specific to usbds into seperate .c/.h.
This commit is contained in:
parent
528b17c9b5
commit
725ac9f00a
@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* @file usb.h
|
* @file usb.h
|
||||||
* @brief USB (usb:*) service IPC wrapper.
|
* @brief Common USB (usb:*) service IPC header.
|
||||||
* @author SciresM, yellows8
|
* @author SciresM, yellows8
|
||||||
* @copyright libnx Authors
|
* @copyright libnx Authors
|
||||||
*/
|
*/
|
||||||
@ -9,12 +9,8 @@
|
|||||||
#include "../services/sm.h"
|
#include "../services/sm.h"
|
||||||
#include "../kernel/event.h"
|
#include "../kernel/event.h"
|
||||||
|
|
||||||
/// usb:ds Switch-as-device<>host USB comms, see also here: https://switchbrew.org/wiki/USB_services
|
|
||||||
|
|
||||||
/// Names starting with "libusb" were changed to "usb" to avoid collision with actual libusb if it's ever used.
|
/// Names starting with "libusb" were changed to "usb" to avoid collision with actual libusb if it's ever used.
|
||||||
|
|
||||||
#define USBDS_DEFAULT_InterfaceNumber 0x4 ///Value for usb_interface_descriptor bInterfaceNumber for automatically allocating the actual bInterfaceNumber.
|
|
||||||
|
|
||||||
/// Imported from libusb with changed names.
|
/// Imported from libusb with changed names.
|
||||||
/* Descriptor sizes per descriptor type */
|
/* Descriptor sizes per descriptor type */
|
||||||
#define USB_DT_INTERFACE_SIZE 9
|
#define USB_DT_INTERFACE_SIZE 9
|
||||||
@ -91,53 +87,6 @@ struct usb_string_descriptor {
|
|||||||
uint16_t wData[0x40];
|
uint16_t wData[0x40];
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
u16 idVendor; ///< VID
|
|
||||||
u16 idProduct; ///< PID
|
|
||||||
u16 bcdDevice;
|
|
||||||
char Manufacturer[0x20];
|
|
||||||
char Product[0x20];
|
|
||||||
char SerialNumber[0x20];
|
|
||||||
} UsbDsDeviceInfo;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
u32 id; ///< urbId from post-buffer cmds
|
|
||||||
u32 requestedSize;
|
|
||||||
u32 transferredSize;
|
|
||||||
u32 urb_status;
|
|
||||||
} UsbDsReportEntry;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
UsbDsReportEntry report[8];
|
|
||||||
u32 report_count;
|
|
||||||
} UsbDsReportData;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
bool initialized;
|
|
||||||
u32 interface_index;
|
|
||||||
Service h;
|
|
||||||
|
|
||||||
Event SetupEvent;
|
|
||||||
Event CtrlInCompletionEvent;
|
|
||||||
Event CtrlOutCompletionEvent;
|
|
||||||
} UsbDsInterface;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
bool initialized;
|
|
||||||
Service h;
|
|
||||||
Event CompletionEvent;
|
|
||||||
} UsbDsEndpoint;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
UsbComplexId_Default = 0x2
|
|
||||||
} UsbComplexId;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
UsbDeviceSpeed_Full = 0x2, ///< USB 1.1 Full Speed
|
|
||||||
UsbDeviceSpeed_High = 0x3, ///< USB 2.0 High Speed
|
|
||||||
UsbDeviceSpeed_Super = 0x4, ///< USB 3.0 Super Speed
|
|
||||||
} UsbDeviceSpeed;
|
|
||||||
|
|
||||||
/// Imported from libusb, with changed names.
|
/// Imported from libusb, with changed names.
|
||||||
enum usb_class_code {
|
enum usb_class_code {
|
||||||
USB_CLASS_PER_INTERFACE = 0,
|
USB_CLASS_PER_INTERFACE = 0,
|
||||||
@ -208,61 +157,3 @@ enum usb_iso_usage_type {
|
|||||||
USB_ISO_USAGE_TYPE_IMPLICIT = 2,
|
USB_ISO_USAGE_TYPE_IMPLICIT = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Opens a session with usb:ds.
|
|
||||||
Result usbDsInitialize(void);
|
|
||||||
/// Closes the usb:ds session. Any interfaces/endpoints which are left open are automatically closed, since otherwise usb-sysmodule won't fully reset usb:ds to defaults.
|
|
||||||
void usbDsExit(void);
|
|
||||||
|
|
||||||
/// Helpers
|
|
||||||
Result usbDsWaitReady(u64 timeout);
|
|
||||||
Result usbDsParseReportData(UsbDsReportData *reportdata, u32 urbId, u32 *requestedSize, u32 *transferredSize);
|
|
||||||
|
|
||||||
/// IDsService
|
|
||||||
Event* usbDsGetStateChangeEvent(void);
|
|
||||||
Result usbDsGetState(u32* out);
|
|
||||||
|
|
||||||
/// Removed in 5.0.0
|
|
||||||
Result usbDsGetDsInterface(UsbDsInterface** out, struct usb_interface_descriptor* descriptor, const char* interface_name);
|
|
||||||
Result usbDsSetVidPidBcd(const UsbDsDeviceInfo* deviceinfo);
|
|
||||||
|
|
||||||
/// Added in 5.0.0
|
|
||||||
Result usbDsRegisterInterface(UsbDsInterface** out);
|
|
||||||
Result usbDsRegisterInterfaceEx(UsbDsInterface** out, u32 intf_num);
|
|
||||||
Result usbDsClearDeviceData(void);
|
|
||||||
Result usbDsAddUsbStringDescriptor(u8* out_index, const char* string);
|
|
||||||
Result usbDsAddUsbLanguageStringDescriptor(u8* out_index, const u16* lang_ids, u16 num_langs);
|
|
||||||
Result usbDsDeleteUsbStringDescriptor(u8 index);
|
|
||||||
Result usbDsSetUsbDeviceDescriptor(UsbDeviceSpeed speed, struct usb_device_descriptor* descriptor);
|
|
||||||
Result usbDsSetBinaryObjectStore(void* bos, size_t bos_size);
|
|
||||||
Result usbDsEnable(void);
|
|
||||||
Result usbDsDisable(void);
|
|
||||||
|
|
||||||
/// IDsInterface
|
|
||||||
void usbDsInterface_Close(UsbDsInterface* interface);
|
|
||||||
|
|
||||||
Result usbDsInterface_GetSetupPacket(UsbDsInterface* interface, void* buffer, size_t size);
|
|
||||||
Result usbDsInterface_EnableInterface(UsbDsInterface* interface);
|
|
||||||
Result usbDsInterface_DisableInterface(UsbDsInterface* interface);
|
|
||||||
Result usbDsInterface_CtrlInPostBufferAsync(UsbDsInterface* interface, void* buffer, size_t size, u32* urbId);
|
|
||||||
Result usbDsInterface_CtrlOutPostBufferAsync(UsbDsInterface* interface, void* buffer, size_t size, u32* urbId);
|
|
||||||
Result usbDsInterface_GetCtrlInReportData(UsbDsInterface* interface, UsbDsReportData* out);
|
|
||||||
Result usbDsInterface_GetCtrlOutReportData(UsbDsInterface* interface, UsbDsReportData* out);
|
|
||||||
Result usbDsInterface_StallCtrl(UsbDsInterface* interface);
|
|
||||||
|
|
||||||
/// Removed in 5.0.0
|
|
||||||
Result usbDsInterface_GetDsEndpoint(UsbDsInterface* interface, UsbDsEndpoint** endpoint, struct usb_endpoint_descriptor* descriptor);
|
|
||||||
|
|
||||||
/// Added in 5.0.0
|
|
||||||
Result usbDsInterface_RegisterEndpoint(UsbDsInterface* interface, UsbDsEndpoint** endpoint, u8 endpoint_address);
|
|
||||||
Result usbDsInterface_AppendConfigurationData(UsbDsInterface* interface, UsbDeviceSpeed speed, void* buffer, size_t size);
|
|
||||||
|
|
||||||
|
|
||||||
/// IDsEndpoint
|
|
||||||
void usbDsEndpoint_Close(UsbDsEndpoint* endpoint);
|
|
||||||
|
|
||||||
Result usbDsEndpoint_Cancel(UsbDsEndpoint* endpoint);
|
|
||||||
Result usbDsEndpoint_PostBufferAsync(UsbDsEndpoint* endpoint, void* buffer, size_t size, u32* urbId);
|
|
||||||
Result usbDsEndpoint_GetReportData(UsbDsEndpoint* endpoint, UsbDsReportData* out);
|
|
||||||
Result usbDsEndpoint_StallCtrl(UsbDsEndpoint* endpoint);
|
|
||||||
Result usbDsEndpoint_SetZlt(UsbDsEndpoint* endpoint, bool zlt); // Sets Zero Length Termination for endpoint
|
|
||||||
|
|
||||||
|
120
nx/include/switch/services/usbds.h
Normal file
120
nx/include/switch/services/usbds.h
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
/**
|
||||||
|
* @file usbds.h
|
||||||
|
* @brief USB (usb:ds) service IPC wrapper.
|
||||||
|
* @brief Switch-as-device<>host USB comms, see also here: https://switchbrew.org/wiki/USB_services
|
||||||
|
* @author SciresM, yellows8
|
||||||
|
* @copyright libnx Authors
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include "../types.h"
|
||||||
|
#include "../services/sm.h"
|
||||||
|
#include "../services/usb.h"
|
||||||
|
#include "../kernel/event.h"
|
||||||
|
|
||||||
|
#define USBDS_DEFAULT_InterfaceNumber 0x4 ///Value for usb_interface_descriptor bInterfaceNumber for automatically allocating the actual bInterfaceNumber.
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
u16 idVendor; ///< VID
|
||||||
|
u16 idProduct; ///< PID
|
||||||
|
u16 bcdDevice;
|
||||||
|
char Manufacturer[0x20];
|
||||||
|
char Product[0x20];
|
||||||
|
char SerialNumber[0x20];
|
||||||
|
} UsbDsDeviceInfo;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
u32 id; ///< urbId from post-buffer cmds
|
||||||
|
u32 requestedSize;
|
||||||
|
u32 transferredSize;
|
||||||
|
u32 urb_status;
|
||||||
|
} UsbDsReportEntry;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
UsbDsReportEntry report[8];
|
||||||
|
u32 report_count;
|
||||||
|
} UsbDsReportData;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
bool initialized;
|
||||||
|
u32 interface_index;
|
||||||
|
Service h;
|
||||||
|
|
||||||
|
Event SetupEvent;
|
||||||
|
Event CtrlInCompletionEvent;
|
||||||
|
Event CtrlOutCompletionEvent;
|
||||||
|
} UsbDsInterface;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
bool initialized;
|
||||||
|
Service h;
|
||||||
|
Event CompletionEvent;
|
||||||
|
} UsbDsEndpoint;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
UsbComplexId_Default = 0x2
|
||||||
|
} UsbComplexId;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
UsbDeviceSpeed_Full = 0x2, ///< USB 1.1 Full Speed
|
||||||
|
UsbDeviceSpeed_High = 0x3, ///< USB 2.0 High Speed
|
||||||
|
UsbDeviceSpeed_Super = 0x4, ///< USB 3.0 Super Speed
|
||||||
|
} UsbDeviceSpeed;
|
||||||
|
|
||||||
|
/// Opens a session with usb:ds.
|
||||||
|
Result usbDsInitialize(void);
|
||||||
|
/// Closes the usb:ds session. Any interfaces/endpoints which are left open are automatically closed, since otherwise usb-sysmodule won't fully reset usb:ds to defaults.
|
||||||
|
void usbDsExit(void);
|
||||||
|
|
||||||
|
/// Helpers
|
||||||
|
Result usbDsWaitReady(u64 timeout);
|
||||||
|
Result usbDsParseReportData(UsbDsReportData *reportdata, u32 urbId, u32 *requestedSize, u32 *transferredSize);
|
||||||
|
|
||||||
|
/// IDsService
|
||||||
|
Event* usbDsGetStateChangeEvent(void);
|
||||||
|
Result usbDsGetState(u32* out);
|
||||||
|
|
||||||
|
/// Removed in 5.0.0
|
||||||
|
Result usbDsGetDsInterface(UsbDsInterface** out, struct usb_interface_descriptor* descriptor, const char* interface_name);
|
||||||
|
Result usbDsSetVidPidBcd(const UsbDsDeviceInfo* deviceinfo);
|
||||||
|
|
||||||
|
/// Added in 5.0.0
|
||||||
|
Result usbDsRegisterInterface(UsbDsInterface** out);
|
||||||
|
Result usbDsRegisterInterfaceEx(UsbDsInterface** out, u32 intf_num);
|
||||||
|
Result usbDsClearDeviceData(void);
|
||||||
|
Result usbDsAddUsbStringDescriptor(u8* out_index, const char* string);
|
||||||
|
Result usbDsAddUsbLanguageStringDescriptor(u8* out_index, const u16* lang_ids, u16 num_langs);
|
||||||
|
Result usbDsDeleteUsbStringDescriptor(u8 index);
|
||||||
|
Result usbDsSetUsbDeviceDescriptor(UsbDeviceSpeed speed, struct usb_device_descriptor* descriptor);
|
||||||
|
Result usbDsSetBinaryObjectStore(void* bos, size_t bos_size);
|
||||||
|
Result usbDsEnable(void);
|
||||||
|
Result usbDsDisable(void);
|
||||||
|
|
||||||
|
/// IDsInterface
|
||||||
|
void usbDsInterface_Close(UsbDsInterface* interface);
|
||||||
|
|
||||||
|
Result usbDsInterface_GetSetupPacket(UsbDsInterface* interface, void* buffer, size_t size);
|
||||||
|
Result usbDsInterface_EnableInterface(UsbDsInterface* interface);
|
||||||
|
Result usbDsInterface_DisableInterface(UsbDsInterface* interface);
|
||||||
|
Result usbDsInterface_CtrlInPostBufferAsync(UsbDsInterface* interface, void* buffer, size_t size, u32* urbId);
|
||||||
|
Result usbDsInterface_CtrlOutPostBufferAsync(UsbDsInterface* interface, void* buffer, size_t size, u32* urbId);
|
||||||
|
Result usbDsInterface_GetCtrlInReportData(UsbDsInterface* interface, UsbDsReportData* out);
|
||||||
|
Result usbDsInterface_GetCtrlOutReportData(UsbDsInterface* interface, UsbDsReportData* out);
|
||||||
|
Result usbDsInterface_StallCtrl(UsbDsInterface* interface);
|
||||||
|
|
||||||
|
/// Removed in 5.0.0
|
||||||
|
Result usbDsInterface_GetDsEndpoint(UsbDsInterface* interface, UsbDsEndpoint** endpoint, struct usb_endpoint_descriptor* descriptor);
|
||||||
|
|
||||||
|
/// Added in 5.0.0
|
||||||
|
Result usbDsInterface_RegisterEndpoint(UsbDsInterface* interface, UsbDsEndpoint** endpoint, u8 endpoint_address);
|
||||||
|
Result usbDsInterface_AppendConfigurationData(UsbDsInterface* interface, UsbDeviceSpeed speed, void* buffer, size_t size);
|
||||||
|
|
||||||
|
|
||||||
|
/// IDsEndpoint
|
||||||
|
void usbDsEndpoint_Close(UsbDsEndpoint* endpoint);
|
||||||
|
|
||||||
|
Result usbDsEndpoint_Cancel(UsbDsEndpoint* endpoint);
|
||||||
|
Result usbDsEndpoint_PostBufferAsync(UsbDsEndpoint* endpoint, void* buffer, size_t size, u32* urbId);
|
||||||
|
Result usbDsEndpoint_GetReportData(UsbDsEndpoint* endpoint, UsbDsReportData* out);
|
||||||
|
Result usbDsEndpoint_StallCtrl(UsbDsEndpoint* endpoint);
|
||||||
|
Result usbDsEndpoint_SetZlt(UsbDsEndpoint* endpoint, bool zlt); // Sets Zero Length Termination for endpoint
|
||||||
|
|
@ -6,6 +6,7 @@
|
|||||||
#include "kernel/rwlock.h"
|
#include "kernel/rwlock.h"
|
||||||
#include "services/fatal.h"
|
#include "services/fatal.h"
|
||||||
#include "services/usb.h"
|
#include "services/usb.h"
|
||||||
|
#include "services/usbds.h"
|
||||||
#include "runtime/devices/usb_comms.h"
|
#include "runtime/devices/usb_comms.h"
|
||||||
|
|
||||||
#define TOTAL_INTERFACES 4
|
#define TOTAL_INTERFACES 4
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "kernel/ipc.h"
|
#include "kernel/ipc.h"
|
||||||
#include "kernel/detect.h"
|
#include "kernel/detect.h"
|
||||||
#include "services/usb.h"
|
#include "services/usb.h"
|
||||||
|
#include "services/usbds.h"
|
||||||
#include "services/sm.h"
|
#include "services/sm.h"
|
||||||
#include "runtime/util/utf.h"
|
#include "runtime/util/utf.h"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user