mirror of
https://github.com/joel16/uofw.git
synced 2024-11-23 03:29:43 +00:00
usbacc: Move usb driver structs and funcs to usbbus.h and clean-up some usbacc functions
This commit is contained in:
parent
b8bc07f5e6
commit
f0153746cd
170
include/usbbus.h
Normal file
170
include/usbbus.h
Normal file
@ -0,0 +1,170 @@
|
||||
/* Copyright (C) The uOFW team
|
||||
See the file COPYING for copying permission.
|
||||
*/
|
||||
|
||||
/** @defgroup Chkreg Chkreg Module
|
||||
* Region check and ConsoleId service.
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef USBBUS_H
|
||||
#define USBBUS_H
|
||||
|
||||
#include "common_header.h"
|
||||
|
||||
/**
|
||||
* USB driver endpoint
|
||||
*/
|
||||
struct UsbEndpoint {
|
||||
/** Endpoint number (must be filled in sequentially) */
|
||||
int endpnum;
|
||||
/** Filled in by the bus driver */
|
||||
int unk2;
|
||||
/** Filled in by the bus driver */
|
||||
int unk3;
|
||||
};
|
||||
|
||||
/**
|
||||
* USB Interface descriptor
|
||||
*/
|
||||
struct InterfaceDescriptor {
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned char bInterfaceNumber;
|
||||
unsigned char bAlternateSetting;
|
||||
unsigned char bNumEndpoints;
|
||||
unsigned char bInterfaceClass;
|
||||
unsigned char bInterfaceSubClass;
|
||||
unsigned char bInterfaceProtocol;
|
||||
unsigned char iInterface;
|
||||
} __attribute__((packed));
|
||||
|
||||
/**
|
||||
* USB driver interfaces structure
|
||||
*/
|
||||
struct UsbInterfaces {
|
||||
/** Pointers to the individual interface descriptors */
|
||||
struct InterfaceDescriptor *infp[2];
|
||||
/** Number of interface descriptors */
|
||||
unsigned int num;
|
||||
};
|
||||
|
||||
/**
|
||||
* USB string descriptor
|
||||
*/
|
||||
struct StringDescriptor {
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
short bString[32];
|
||||
} __attribute__((packed));
|
||||
|
||||
/**
|
||||
* USB EP0 Device Request
|
||||
*/
|
||||
struct DeviceRequest {
|
||||
unsigned char bmRequestType;
|
||||
unsigned char bRequest;
|
||||
unsigned short wValue;
|
||||
unsigned short wIndex;
|
||||
unsigned short wLength;
|
||||
} __attribute__((packed));
|
||||
|
||||
/**
|
||||
* USB driver structure used by ::sceUsbbdRegister and ::sceUsbbdUnregister
|
||||
*/
|
||||
struct UsbDriver {
|
||||
/** Name of the USB driver */
|
||||
const char *name;
|
||||
/** Number of endpoints in this driver (including default control) */
|
||||
int endpoints;
|
||||
/** List of endpoint structures (used when calling other functions) */
|
||||
struct UsbEndpoint *endp;
|
||||
/** Interface list */
|
||||
struct UsbInterface *intp;
|
||||
/** Pointer to hi-speed device descriptor */
|
||||
void *devp_hi;
|
||||
/** Pointer to hi-speed device configuration */
|
||||
void *confp_hi;
|
||||
/** Pointer to full-speed device descriptor */
|
||||
void *devp;
|
||||
/** Pointer to full-speed device configuration */
|
||||
void *confp;
|
||||
/** Default String descriptor */
|
||||
struct StringDescriptor *str;
|
||||
/** Received a control request arg0 is endpoint, arg1 is possibly data arg2 is data buffer */
|
||||
int (*recvctl)(int arg1, int arg2, struct DeviceRequest *req);
|
||||
/** Unknown */
|
||||
int (*func28)(int arg1, int arg2, int arg3);
|
||||
/** Configuration set (attach) function */
|
||||
int (*attach)(int speed, void *arg2, void *arg3);
|
||||
/** Configuration unset (detach) function */
|
||||
int (*detach)(int arg1, int arg2, int arg3);
|
||||
/** Unknown set to 0 */
|
||||
int unk34;
|
||||
/** Function called when the driver is started */
|
||||
int (*start_func)(int size, void *args);
|
||||
/** Function called when the driver is stopped */
|
||||
int (*stop_func)(int size, void *args);
|
||||
/** Link to next USB driver in the chain, set to NULL */
|
||||
struct UsbDriver *link;
|
||||
};
|
||||
|
||||
/**
|
||||
* USB device request, used by ::sceUsbbdReqSend and ::sceUsbbdReqRecv.
|
||||
*/
|
||||
struct UsbdDeviceReq {
|
||||
/** Pointer to the endpoint to queue request on */
|
||||
struct UsbEndpoint *endp;
|
||||
/** Pointer to the data buffer to use in the request */
|
||||
void *data;
|
||||
/** Size of the data buffer (send == size of data, recv == size of max receive) */
|
||||
int size;
|
||||
/** Unknown */
|
||||
int unkc;
|
||||
/** Pointer to the function to call on completion */
|
||||
void *func;
|
||||
/** Resultant size (send == size of data sent, recv == size of data received) */
|
||||
int recvsize;
|
||||
/** Return code of the request, 0 == success, -3 == cancelled */
|
||||
int retcode;
|
||||
/** Unknown */
|
||||
int unk1c;
|
||||
/** A user specified pointer for the device request */
|
||||
void *arg;
|
||||
/** Link pointer to next request used by the driver, set it to NULL */
|
||||
void *link;
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a USB driver.
|
||||
*
|
||||
* @param drv - Pointer to a filled out USB driver
|
||||
*
|
||||
* @return 0 on success, < 0 on error.
|
||||
*/
|
||||
int sceUsbbdRegister(struct UsbDriver *drv);
|
||||
|
||||
|
||||
/**
|
||||
* Unregister a USB driver
|
||||
*
|
||||
* @param drv - Pointer to a filled out USB driver
|
||||
*
|
||||
* @return 0 on success, < 0 on error
|
||||
*/
|
||||
int sceUsbbdUnregister(struct UsbDriver *drv);
|
||||
|
||||
/**
|
||||
* Queue a send request (IN from host pov)
|
||||
*
|
||||
* @param req - Pointer to a filled out UsbdDeviceReq structure.
|
||||
*
|
||||
* @return 0 on success, < 0 on error
|
||||
*/
|
||||
int sceUsbbdReqSend(struct UsbdDeviceReq *req);
|
||||
|
||||
int sceUsbBus_driver_8A3EB5D2(void);
|
||||
|
||||
#endif // USBBUS_H
|
||||
|
||||
/** @} */
|
@ -1,6 +1,7 @@
|
||||
#include <common_imp.h>
|
||||
#include <interruptman.h>
|
||||
#include <sysmem_utils_kernel.h>
|
||||
#include <usbbus.h>
|
||||
|
||||
SCE_MODULE_INFO("sceUSB_Acc_Driver", SCE_MODULE_KERNEL | SCE_MODULE_ATTR_EXCLUSIVE_LOAD | SCE_MODULE_ATTR_EXCLUSIVE_START, 1, 3);
|
||||
SCE_SDK_VERSION(SDK_VERSION);
|
||||
@ -10,146 +11,26 @@ SCE_SDK_VERSION(SDK_VERSION);
|
||||
#define SCE_ERROR_USB_DRIVER_NOT_FOUND 0x80243005
|
||||
#define SCE_ERROR_USB_BUS_DRIVER_NOT_STARTED 0x80243007
|
||||
|
||||
/** USB driver endpoint */
|
||||
struct UsbEndpoint
|
||||
{
|
||||
/** Endpoint number (must be filled in sequentially) */
|
||||
int endpnum;
|
||||
/** Filled in by the bus driver */
|
||||
int unk2;
|
||||
/** Filled in by the bus driver */
|
||||
int unk3;
|
||||
};
|
||||
|
||||
/** USB Interface descriptor */
|
||||
struct InterfaceDescriptor
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned char bInterfaceNumber;
|
||||
unsigned char bAlternateSetting;
|
||||
unsigned char bNumEndpoints;
|
||||
unsigned char bInterfaceClass;
|
||||
unsigned char bInterfaceSubClass;
|
||||
unsigned char bInterfaceProtocol;
|
||||
unsigned char iInterface;
|
||||
} __attribute__((packed));
|
||||
|
||||
/** USB driver interfaces structure */
|
||||
struct UsbInterfaces
|
||||
{
|
||||
/** Pointers to the individual interface descriptors */
|
||||
struct InterfaceDescriptor *infp[2];
|
||||
/** Number of interface descriptors */
|
||||
unsigned int num;
|
||||
};
|
||||
|
||||
/** USB string descriptor */
|
||||
struct StringDescriptor
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
short bString[32];
|
||||
} __attribute__((packed));
|
||||
|
||||
/** USB EP0 Device Request */
|
||||
struct DeviceRequest
|
||||
{
|
||||
unsigned char bmRequestType;
|
||||
unsigned char bRequest;
|
||||
unsigned short wValue;
|
||||
unsigned short wIndex;
|
||||
unsigned short wLength;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct UsbDriver
|
||||
{
|
||||
/** Name of the USB driver */
|
||||
const char *name;
|
||||
/** Number of endpoints in this driver (including default control) */
|
||||
int endpoints;
|
||||
/** List of endpoint structures (used when calling other functions) */
|
||||
struct UsbEndpoint *endp;
|
||||
/** Interface list */
|
||||
struct UsbInterface *intp;
|
||||
/** Pointer to hi-speed device descriptor */
|
||||
void *devp_hi;
|
||||
/** Pointer to hi-speed device configuration */
|
||||
void *confp_hi;
|
||||
/** Pointer to full-speed device descriptor */
|
||||
void *devp;
|
||||
/** Pointer to full-speed device configuration */
|
||||
void *confp;
|
||||
/** Default String descriptor */
|
||||
struct StringDescriptor *str;
|
||||
/** Received a control request arg0 is endpoint, arg1 is possibly data arg2 is data buffer */
|
||||
int (*recvctl)(int arg1, int arg2, struct DeviceRequest *req);
|
||||
/** Unknown */
|
||||
int (*func28)(int arg1, int arg2, int arg3);
|
||||
/** Configuration set (attach) function */
|
||||
int (*attach)(int speed, void *arg2, void *arg3);
|
||||
/** Configuration unset (detach) function */
|
||||
int (*detach)(int arg1, int arg2, int arg3);
|
||||
/** Unknown set to 0 */
|
||||
int unk34;
|
||||
/** Function called when the driver is started */
|
||||
int (*start_func)(int size, void *args);
|
||||
/** Function called when the driver is stopped */
|
||||
int (*stop_func)(int size, void *args);
|
||||
/** Link to next USB driver in the chain, set to NULL */
|
||||
struct UsbDriver *link;
|
||||
};
|
||||
|
||||
/** USB device request, used by ::sceUsbbdReqSend and ::sceUsbbdReqRecv. */
|
||||
struct UsbdDeviceReq
|
||||
{
|
||||
/** Pointer to the endpoint to queue request on */
|
||||
struct UsbEndpoint *endp;
|
||||
/** Pointer to the data buffer to use in the request */
|
||||
void *data;
|
||||
/** Size of the data buffer (send == size of data, recv == size of max receive) */
|
||||
int size;
|
||||
/** Unknown */
|
||||
int unkc;
|
||||
/** Pointer to the function to call on completion */
|
||||
void *func;
|
||||
/** Resultant size (send == size of data sent, recv == size of data received) */
|
||||
int recvsize;
|
||||
/** Return code of the request, 0 == success, -3 == cancelled */
|
||||
int retcode;
|
||||
/** Unknown */
|
||||
int unk1c;
|
||||
/** A user specified pointer for the device request */
|
||||
void *arg;
|
||||
/** Link pointer to next request used by the driver, set it to NULL */
|
||||
void *link;
|
||||
};
|
||||
|
||||
int sceUsbbdRegister(struct UsbDriver *drv); // sceUsbBus_driver_B1644BE7
|
||||
int sceUsbbdUnregister(struct UsbDriver *drv); // sceUsbBus_driver_C1E2A540
|
||||
int sceUsbbdReqSend(struct UsbdDeviceReq *req); // sceUsbBus_driver_23E51D8F
|
||||
int sceUsbBus_driver_8A3EB5D2(void);
|
||||
|
||||
// Globals
|
||||
struct UsbDriver g_drv; // 0x00000CC4
|
||||
u8 g_unk0; // 0x00000D53
|
||||
u16 g_unk1; // 0x00000D50
|
||||
u16 g_type; // 0x00000D50
|
||||
u8 g_unk2; // 0x00000D52
|
||||
u8 g_unk3; // 0x00000D53
|
||||
struct UsbdDeviceReq g_req; // 0x00000CAC
|
||||
struct UsbEndpoint g_endp; // 0x00000CAC
|
||||
|
||||
// Subroutine sceUsbAccGetAuthStat - Address 0x00000000 - Aliases: sceUsbAcc_79A1C743, sceUsbAcc_driver_79A1C743 -- Done
|
||||
// Exported in sceUsbAcc_internal, sceUsbAcc and sceUsbAcc_driver
|
||||
s32 sceUsbAccGetAuthStat(void)
|
||||
{
|
||||
int intr = sceKernelCpuSuspendIntr();
|
||||
s32 ret = SCE_ERROR_USB_BUS_DRIVER_NOT_STARTED;
|
||||
s32 ret = 0;
|
||||
|
||||
if (g_unk0) {
|
||||
ret = 0;
|
||||
if (sceUsbBus_driver_8A3EB5D2() == 0)
|
||||
ret = 0x80243701;
|
||||
}
|
||||
else
|
||||
ret = SCE_ERROR_USB_BUS_DRIVER_NOT_STARTED;
|
||||
|
||||
sceKernelCpuResumeIntr(intr);
|
||||
return ret;
|
||||
@ -164,18 +45,19 @@ s32 sceUsbAccGetInfo(void)
|
||||
|
||||
// Subroutine sceUsbAcc_internal_2A100C1F - Address 0x00000154 -- TODO: Verify
|
||||
// Exported in sceUsbAcc_internal
|
||||
s32 sceUsbAcc_internal_2A100C1F(struct UsbdDeviceReq *arg)
|
||||
s32 sceUsbAcc_internal_2A100C1F(struct UsbdDeviceReq *req)
|
||||
{
|
||||
s32 ret = SCE_ERROR_USB_BUS_DRIVER_NOT_STARTED;
|
||||
|
||||
if (g_unk3) {
|
||||
u8 *data = req->data;
|
||||
|
||||
if (g_unk0) {
|
||||
ret = SCE_ERROR_USB_INVALID_ARGUMENT;
|
||||
|
||||
if (*(u8 *)(&arg[1] + 3) < 0x3D) {
|
||||
sceKernelDcacheWritebackRange(&arg[1], sizeof(arg[2]));
|
||||
arg[0] = g_req;
|
||||
arg[2] = *((&arg[1] + 3) + 4);
|
||||
ret = sceUsbbdReqSend(arg);
|
||||
if ((data[3]) < 0x3D) {
|
||||
sceKernelDcacheWritebackRange(data, req->size);
|
||||
req->endp = &g_endp;
|
||||
req->size = data[3] + 4;
|
||||
ret = sceUsbbdReqSend(req);
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,9 +70,9 @@ s32 sceUsbAccRegisterType(u16 type)
|
||||
{
|
||||
s32 error = SCE_ERROR_USB_DRIVER_NOT_FOUND;
|
||||
|
||||
if ((g_unk1 & type) == 0) {
|
||||
if ((g_type & type) == 0) {
|
||||
error = 0;
|
||||
g_unk1 = g_unk1 | type;
|
||||
g_type = g_type | type;
|
||||
}
|
||||
|
||||
return error;
|
||||
@ -202,9 +84,9 @@ s32 sceUsbAccUnregisterType(u16 type)
|
||||
{
|
||||
s32 error = SCE_ERROR_USB_DRIVER_NOT_FOUND;
|
||||
|
||||
if ((g_unk1 & type) != 0) {
|
||||
if ((g_type & type) != 0) {
|
||||
error = 0;
|
||||
g_unk1 = g_unk1 & ~type;
|
||||
g_type = g_type & ~type;
|
||||
}
|
||||
|
||||
return error;
|
||||
@ -215,7 +97,7 @@ s32 module_start(SceSize args __attribute__((unused)), void *argp __attribute__(
|
||||
{
|
||||
s32 ret = 0;
|
||||
if ((ret = sceUsbbdRegister(&g_drv)) >= 0) {
|
||||
g_unk1 = 0;
|
||||
g_type = 0;
|
||||
g_unk2 = 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user