mirror of
https://github.com/joel16/uofw.git
synced 2024-11-30 06:50:47 +00:00
commit
470665e281
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
|
||||
|
||||
/** @} */
|
BIN
lib/libsceUsbBus_driver.a
Normal file
BIN
lib/libsceUsbBus_driver.a
Normal file
Binary file not shown.
11
src/usbacc/Makefile
Normal file
11
src/usbacc/Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
# Copyright (C) 2021 The uOFW team
|
||||
# See the file COPYING for copying permission.
|
||||
|
||||
TARGET = usbacc
|
||||
OBJS = usbacc.o
|
||||
|
||||
#DEBUG = 1
|
||||
|
||||
LIBS = -lsceUsbBus_driver -lInterruptManagerForKernel -lThreadManForKernel -lUtilsForKernel
|
||||
|
||||
include ../../lib/build.mak
|
29
src/usbacc/exports.exp
Normal file
29
src/usbacc/exports.exp
Normal file
@ -0,0 +1,29 @@
|
||||
# Export file automatically generated with prxtool
|
||||
PSP_BEGIN_EXPORTS
|
||||
|
||||
PSP_EXPORT_START(syslib, 0x0000, 0x8000)
|
||||
PSP_EXPORT_FUNC_HASH(module_start)
|
||||
PSP_EXPORT_FUNC_HASH(module_stop)
|
||||
PSP_EXPORT_VAR_HASH(module_info)
|
||||
PSP_EXPORT_VAR_HASH(module_sdk_version)
|
||||
PSP_EXPORT_END
|
||||
|
||||
PSP_EXPORT_START(sceUsbAcc_internal, 0x0011, 0x0001)
|
||||
PSP_EXPORT_FUNC_NID(sceUsbAccGetInfo, 0x0CD7D4AA)
|
||||
PSP_EXPORT_FUNC_NID(sceUsbAccUnregisterType, 0x18B04C82)
|
||||
PSP_EXPORT_FUNC_NID(sceUsbAcc_internal_2A100C1F, 0x2A100C1F)
|
||||
PSP_EXPORT_FUNC_NID(sceUsbAccRegisterType, 0x2E251404)
|
||||
PSP_EXPORT_FUNC_NID(sceUsbAccGetAuthStat, 0x79A1C743)
|
||||
PSP_EXPORT_END
|
||||
|
||||
PSP_EXPORT_START(sceUsbAcc, 0x0011, 0x4001)
|
||||
PSP_EXPORT_FUNC_NID(sceUsbAccGetInfo, 0x0CD7D4AA)
|
||||
PSP_EXPORT_FUNC_NID(sceUsbAccGetAuthStat, 0x79A1C743)
|
||||
PSP_EXPORT_END
|
||||
|
||||
PSP_EXPORT_START(sceUsbAcc_driver, 0x0011, 0x0001)
|
||||
PSP_EXPORT_FUNC_NID(sceUsbAccGetInfo, 0x0CD7D4AA)
|
||||
PSP_EXPORT_FUNC_NID(sceUsbAccGetAuthStat, 0x79A1C743)
|
||||
PSP_EXPORT_END
|
||||
|
||||
PSP_END_EXPORTS
|
144
src/usbacc/usbacc.c
Normal file
144
src/usbacc/usbacc.c
Normal file
@ -0,0 +1,144 @@
|
||||
#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);
|
||||
|
||||
// Error codes are derived from -> https://github.com/xerpi/psp-uvc-usb-video-class/blob/master/include/usb.h
|
||||
#define SCE_ERROR_USB_INVALID_ARGUMENT 0x80243002
|
||||
#define SCE_ERROR_USB_DRIVER_NOT_FOUND 0x80243005
|
||||
#define SCE_ERROR_USB_BUS_DRIVER_NOT_STARTED 0x80243007
|
||||
|
||||
// Globals
|
||||
struct UsbDriver g_drv; // 0x00000CC4
|
||||
u64 g_unk0; // 0x00000D10
|
||||
u8 g_usbBusDriverStarted; // 0x00000D53
|
||||
u16 g_type; // 0x00000D50
|
||||
u8 g_unk2; // 0x00000D52
|
||||
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 = 0;
|
||||
|
||||
if (g_unk0) {
|
||||
if (sceUsbBus_driver_8A3EB5D2() == 0)
|
||||
ret = 0x80243701;
|
||||
}
|
||||
else
|
||||
ret = SCE_ERROR_USB_BUS_DRIVER_NOT_STARTED;
|
||||
|
||||
sceKernelCpuResumeIntr(intr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Subroutine sceUsbAccGetInfo - Address 0x00000068 - Aliases: sceUsbAcc_0CD7D4AA, sceUsbAcc_driver_0CD7D4AA
|
||||
// Exported in sceUsbAcc_internal, sceUsbAcc and sceUsbAcc_driver
|
||||
s32 sceUsbAccGetInfo(u64 *arg)
|
||||
{
|
||||
s32 ret = 0;
|
||||
s32 oldK1 = pspShiftK1();
|
||||
int intr = sceKernelCpuSuspendIntr();
|
||||
|
||||
if (g_usbBusDriverStarted) {
|
||||
if (sceUsbBus_driver_8A3EB5D2() != 0) {
|
||||
if (arg) {
|
||||
if (((((u32)arg + 8) | (u32)arg) & (oldK1))) {
|
||||
*arg = g_unk0;
|
||||
}
|
||||
}
|
||||
else
|
||||
ret = SCE_ERROR_USB_INVALID_ARGUMENT;
|
||||
|
||||
sceKernelCpuResumeIntr(intr);
|
||||
}
|
||||
else {
|
||||
sceKernelCpuResumeIntr(intr);
|
||||
ret = 0x80243701;
|
||||
}
|
||||
}
|
||||
else {
|
||||
sceKernelCpuResumeIntr(intr);
|
||||
ret = SCE_ERROR_USB_BUS_DRIVER_NOT_STARTED;
|
||||
}
|
||||
|
||||
pspSetK1(oldK1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Subroutine sceUsbAcc_internal_2A100C1F - Address 0x00000154 -- TODO: Verify
|
||||
// Exported in sceUsbAcc_internal
|
||||
s32 sceUsbAcc_internal_2A100C1F(struct UsbdDeviceReq *req)
|
||||
{
|
||||
s32 ret = 0;
|
||||
u8 *data = req->data;
|
||||
|
||||
if (g_usbBusDriverStarted) {
|
||||
if ((data[3]) < 0x3D) {
|
||||
sceKernelDcacheWritebackRange(data, req->size);
|
||||
req->endp = &g_endp;
|
||||
req->size = data[3] + 4;
|
||||
ret = sceUsbbdReqSend(req);
|
||||
}
|
||||
else
|
||||
ret = SCE_ERROR_USB_INVALID_ARGUMENT;
|
||||
}
|
||||
else
|
||||
ret = SCE_ERROR_USB_BUS_DRIVER_NOT_STARTED;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Subroutine sceUsbAccRegisterType - Address 0x000004AC -- Done
|
||||
// Exported in sceUsbAcc_internal
|
||||
s32 sceUsbAccRegisterType(u16 type)
|
||||
{
|
||||
s32 ret = 0;
|
||||
|
||||
if ((g_type & type) == 0)
|
||||
g_type = g_type | type;
|
||||
else
|
||||
ret = SCE_ERROR_USB_DRIVER_NOT_FOUND;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Subroutine sceUsbAccUnregisterType - Address 0x000004E0 -- Done
|
||||
// Exported in sceUsbAcc_internal
|
||||
s32 sceUsbAccUnregisterType(u16 type)
|
||||
{
|
||||
s32 ret = 0;
|
||||
|
||||
if ((g_type & type) != 0)
|
||||
g_type = g_type & ~type;
|
||||
else
|
||||
ret = SCE_ERROR_USB_DRIVER_NOT_FOUND;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Subroutine module_start - Address 0x00000518 -- Done
|
||||
s32 module_start(SceSize args __attribute__((unused)), void *argp __attribute__((unused)))
|
||||
{
|
||||
if ((sceUsbbdRegister(&g_drv)) >= 0) {
|
||||
g_type = 0;
|
||||
g_unk2 = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Subroutine module_stop - Address 0x00000558 -- Done
|
||||
s32 module_stop(SceSize args __attribute__((unused)), void *argp __attribute__((unused)))
|
||||
{
|
||||
if (sceUsbbdUnregister(&g_drv) >= 0)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
Loading…
Reference in New Issue
Block a user