wut v1.8.0
Wii U Toolchain
Loading...
Searching...
No Matches
uhs.h
Go to the documentation of this file.
1#pragma once
2#include <wut.h>
3#include <stdbool.h>
4
5#ifdef __cplusplus
6extern "C" {
7#endif
8
9#include "uhs_usbspec.h"
10
14typedef struct UhsHandle UhsHandle;
15typedef struct UhsConfig UhsConfig;
16
17/* Determines which interface parameters to check */
18#define MATCH_ANY 0x000
19#define MATCH_DEV_VID 0x001
20#define MATCH_DEV_PID 0x002
21#define MATCH_DEV_CLASS 0x010
22#define MATCH_DEV_SUBCLASS 0x020
23#define MATCH_DEV_PROTOCOL 0x040
24#define MATCH_IF_CLASS 0x080
25#define MATCH_IF_SUBCLASS 0x100
26#define MATCH_IF_PROTOCOL 0x200
27
34
44
45#define UHS_CONFIG_BUFFER_SIZE 0x137f
46
47struct WUT_PACKED UhsConfig
48{
50 /* buffer aligned by 0x40 with a size of UHS_CONFIG_BUFFER_SIZE */
51 void* buffer;
52 uint32_t buffer_size;
53};
54WUT_CHECK_OFFSET(UhsConfig, 0x00, controller_num);
55WUT_CHECK_OFFSET(UhsConfig, 0x04, buffer);
56WUT_CHECK_OFFSET(UhsConfig, 0x08, buffer_size);
57WUT_CHECK_SIZE(UhsConfig, 0x0C);
58
59struct WUT_PACKED UhsHandle
60{
63 WUT_UNKNOWN_BYTES(4); /* always 0xFFFFFFFF after init */
64 uint32_t handle;
66 WUT_UNKNOWN_BYTES(4);
67};
68WUT_CHECK_OFFSET(UhsHandle, 0x00, state);
69WUT_CHECK_OFFSET(UhsHandle, 0x04, ipc_buffer);
70WUT_CHECK_OFFSET(UhsHandle, 0x0C, handle);
71WUT_CHECK_OFFSET(UhsHandle, 0x10, config);
72WUT_CHECK_SIZE(UhsHandle, 0x18);
73
74/* Endpoint transfer directions */
75#define ENDPOINT_TRANSFER_OUT 1
76#define ENDPOINT_TRANSFER_IN 2
77
78/* Special timeout values */
79#define TIMEOUT_NONE -1
80
81/* Interface filter */
82struct WUT_PACKED UhsInterfaceFilter
83{
84 uint16_t match_params; /* Bitmask of above flags */
85 uint16_t vid; /* Vendor ID */
86 uint16_t pid; /* Product ID */
87 WUT_UNKNOWN_BYTES(4);
88 uint8_t dev_class; /* Device class */
89 uint8_t dev_subclass; /* Device subclass */
90 uint8_t dev_protocol; /* Device protocol */
91 uint8_t if_class; /* Interface class */
92 uint8_t if_subclass; /* Interface subclass */
93 uint8_t if_protocol; /* Interface protocol */
94};
95WUT_CHECK_OFFSET(UhsInterfaceFilter, 0x00, match_params);
96WUT_CHECK_OFFSET(UhsInterfaceFilter, 0x02, vid);
97WUT_CHECK_OFFSET(UhsInterfaceFilter, 0x04, pid);
98WUT_CHECK_OFFSET(UhsInterfaceFilter, 0x0A, dev_class);
99WUT_CHECK_OFFSET(UhsInterfaceFilter, 0x0B, dev_subclass);
100WUT_CHECK_OFFSET(UhsInterfaceFilter, 0x0C, dev_protocol);
101WUT_CHECK_OFFSET(UhsInterfaceFilter, 0x0D, if_class);
102WUT_CHECK_OFFSET(UhsInterfaceFilter, 0x0E, if_subclass);
103WUT_CHECK_OFFSET(UhsInterfaceFilter, 0x0F, if_protocol);
104WUT_CHECK_SIZE(UhsInterfaceFilter, 0x10);
105
106
107/* Interface profile */
108struct WUT_PACKED UhsEndpointDescriptor
109{
110 uint8_t bLength;
115 uint8_t bInterval;
116 WUT_UNKNOWN_BYTES(0x2);
117};
118WUT_CHECK_OFFSET(UhsEndpointDescriptor, 0x00, bLength);
119WUT_CHECK_OFFSET(UhsEndpointDescriptor, 0x01, bDescriptorType);
120WUT_CHECK_OFFSET(UhsEndpointDescriptor, 0x02, bEndpointAddress);
121WUT_CHECK_OFFSET(UhsEndpointDescriptor, 0x03, bmAttributes);
122WUT_CHECK_OFFSET(UhsEndpointDescriptor, 0x04, wMaxPacketSize);
123WUT_CHECK_OFFSET(UhsEndpointDescriptor, 0x06, bInterval);
124WUT_CHECK_SIZE(UhsEndpointDescriptor, 0x09);
125
126/* Interface profile */
137WUT_CHECK_OFFSET(UhsInterfaceProfile, 0x00, if_handle);
138WUT_CHECK_OFFSET(UhsInterfaceProfile, 0x28, dev_desc);
139WUT_CHECK_OFFSET(UhsInterfaceProfile, 0x3A, cfg_desc);
140WUT_CHECK_OFFSET(UhsInterfaceProfile, 0x43, if_desc);
141WUT_CHECK_OFFSET(UhsInterfaceProfile, 0x4c, in_endpoints);
142WUT_CHECK_OFFSET(UhsInterfaceProfile, 0xdc, out_endpoints);
143WUT_CHECK_SIZE(UhsInterfaceProfile, 0x16C);
144
153
161
162/* Open a specific controller under /dev/uhs */
165 UhsConfig* config);
166
169
170typedef void(*UHSDrvRegCallback)(void * context, UhsInterfaceProfile * profile);
171
172/* Register a USB class driver */
175 UhsInterfaceFilter *filter,
176 void *context,
177 UHSDrvRegCallback callback);
178
181 uint32_t drv_handle);
182
185 uint32_t if_handle,
186 void* data,
187 uint32_t size);
188
191 uint32_t if_handle,
192 uint8_t string_index,
193 BOOL as_unicode,
194 void* data,
195 uint32_t size);
196
197/* Determine which USB device interfaces are plugged in and available */
200 UhsInterfaceFilter *filter,
201 UhsInterfaceProfile *profiles,
202 int32_t max_profiles);
203
204
205typedef void(*UhsAcquireInterfaceCallback)(void * context, int32_t arg1, int32_t arg2);
206
207/* Acquire a USB device interface for use */
210 uint32_t if_handle,
211 void * context,
213
214/* Release a currently-held USB device interface */
217 uint32_t if_handle,
218 bool no_reacquire);
219
220/* Administer a USB device */
223 uint32_t if_handle,
224 UHSAdminDevType type,
225 int32_t arg3);
226
229 uint32_t if_handle,
230 UHSAdminEpType type,
231 uint32_t endpointMask,
232 uint32_t max_pending_requests,
233 uint32_t max_request_size);
234
237 uint32_t if_handle,
238 uint32_t endpoint,
239 int32_t direction);
240
241/* Submit a control request to endpoint 0 */
244 uint32_t if_handle,
245 void *buffer,
246 uint8_t bRequest,
247 uint8_t bmRequestType,
248 uint16_t wValue,
249 uint16_t wIndex,
250 uint16_t wLength,
251 int32_t timeout);
252
253/* Submit a bulk request to an endpoint */
256 uint32_t if_handle,
257 uint8_t endpoint,
258 int32_t direction,
259 void *buffer,
260 int32_t length,
261 int32_t timeout);
262
263/* Submit an interrupt request to an endpoint */
266 uint32_t if_handle,
267 uint8_t endpoint,
268 int32_t direction,
269 void *buffer,
270 int32_t length,
271 int32_t timeout);
272
273static inline uint32_t UHSEndpointDirIsIn(UhsEndpointDescriptor * endpoint_descriptor){
274 return ((endpoint_descriptor->bEndpointAddress & 0x80) == 0x80);
275}
276
277static inline uint32_t UHSEndpointGetNum(UhsEndpointDescriptor * endpoint_descriptor){
278 return (endpoint_descriptor->bEndpointAddress & 0x0F);
279}
280
281static inline uint32_t UHSEndpointGetMask(UhsEndpointDescriptor * endpoint_descriptor){
282 uint32_t endpoint_mask;
283
284 if (UHSEndpointDirIsIn(endpoint_descriptor)) {
285 endpoint_mask = (1 << (UHSEndpointGetNum(endpoint_descriptor) + 16));
286 } else {
287 endpoint_mask = (1 << UHSEndpointGetNum(endpoint_descriptor));
288 }
289 return endpoint_mask;
290}
291
292#ifdef __cplusplus
293}
294#endif
295
UHSStatus UhsSubmitInterruptRequest(UhsHandle *handle, uint32_t if_handle, uint8_t endpoint, int32_t direction, void *buffer, int32_t length, int32_t timeout)
UHSStatus UhsSubmitControlRequest(UhsHandle *handle, uint32_t if_handle, void *buffer, uint8_t bRequest, uint8_t bmRequestType, uint16_t wValue, uint16_t wIndex, uint16_t wLength, int32_t timeout)
UHSStatus UhsSubmitBulkRequest(UhsHandle *handle, uint32_t if_handle, uint8_t endpoint, int32_t direction, void *buffer, int32_t length, int32_t timeout)
UHSStatus UhsAcquireInterface(UhsHandle *handle, uint32_t if_handle, void *context, UhsAcquireInterfaceCallback callback)
uint8_t bLength
Definition uhs.h:110
UHSStatus UhsQueryInterfaces(UhsHandle *handle, UhsInterfaceFilter *filter, UhsInterfaceProfile *profiles, int32_t max_profiles)
uint16_t match_params
Definition uhs.h:84
UHSStatus UhsReleaseInterface(UhsHandle *handle, uint32_t if_handle, bool no_reacquire)
static uint32_t UHSEndpointDirIsIn(UhsEndpointDescriptor *endpoint_descriptor)
Definition uhs.h:273
void * buffer
Definition uhs.h:51
static uint32_t UHSEndpointGetMask(UhsEndpointDescriptor *endpoint_descriptor)
Definition uhs.h:281
UHSStatus UhsClearEndpointHalt(UhsHandle *handle, uint32_t if_handle, uint32_t endpoint, int32_t direction)
uint8_t dev_class
Definition uhs.h:88
UHSStatus UhsClassDrvReg(UhsHandle *handle, UhsInterfaceFilter *filter, void *context, UHSDrvRegCallback callback)
UHSStatus UhsAdministerEndpoint(UhsHandle *handle, uint32_t if_handle, UHSAdminEpType type, uint32_t endpointMask, uint32_t max_pending_requests, uint32_t max_request_size)
uint8_t bEndpointAddress
Definition uhs.h:112
uint32_t controller_num
Definition uhs.h:49
void * ipc_buffer
Definition uhs.h:62
UhsConfig * config
Definition uhs.h:65
UhsConfigDescriptor cfg_desc
Definition uhs.h:132
uint8_t bDescriptorType
Definition uhs.h:111
UHSAdminDevType
Definition uhs.h:146
@ UHS_ADMIN_DEV_DESTROY
Definition uhs.h:151
@ UHS_ADMIN_DEV_SUSPEND
Definition uhs.h:149
@ UHS_ADMIN_DEV_FREEZE
Definition uhs.h:148
@ UHS_ADMIN_DEV_RESUME
Definition uhs.h:150
@ UHS_ADMIN_DEV_RESET
Definition uhs.h:147
uint8_t dev_protocol
Definition uhs.h:90
UHSStatus UhsAdministerDevice(UhsHandle *handle, uint32_t if_handle, UHSAdminDevType type, int32_t arg3)
void(* UHSDrvRegCallback)(void *context, UhsInterfaceProfile *profile)
Definition uhs.h:170
UhsDeviceDescriptor dev_desc
Definition uhs.h:131
uint8_t if_protocol
Definition uhs.h:93
UHSStatus UhsClientOpen(UhsHandle *handle, UhsConfig *config)
UHSHandleState state
Definition uhs.h:61
uint16_t pid
Definition uhs.h:86
uint8_t dev_subclass
Definition uhs.h:89
UHSStatus UhsClassDrvUnReg(UhsHandle *handle, uint32_t drv_handle)
uint32_t handle
Definition uhs.h:64
uint16_t vid
Definition uhs.h:85
uint32_t if_handle
Definition uhs.h:129
uint32_t buffer_size
Definition uhs.h:52
static uint32_t UHSEndpointGetNum(UhsEndpointDescriptor *endpoint_descriptor)
Definition uhs.h:277
uint16_t wMaxPacketSize
Definition uhs.h:114
UHSStatus UhsClientClose(UhsHandle *handle)
uint8_t if_class
Definition uhs.h:91
UHSStatus UhsGetFullConfigDescriptor(UhsHandle *handle, uint32_t if_handle, void *data, uint32_t size)
UHSAdminEpType
Definition uhs.h:155
@ UHS_ADMIN_EP_DISABLE
Definition uhs.h:157
@ UHS_ADMIN_EP_CANCEL_RESET
Definition uhs.h:159
@ UHS_ADMIN_EP_ENABLE
Definition uhs.h:156
@ UHS_ADMIN_EP_CANCEL
Definition uhs.h:158
UHSStatus UhsGetDescriptorString(UhsHandle *handle, uint32_t if_handle, uint8_t string_index, BOOL as_unicode, void *data, uint32_t size)
uint8_t if_subclass
Definition uhs.h:92
uint8_t bmAttributes
Definition uhs.h:113
UhsInterfaceDescriptor if_desc
Definition uhs.h:133
UHSHandleState
Definition uhs.h:36
@ UHS_HANDLE_STATE_ERROR
Definition uhs.h:42
@ UHS_HANDLE_STATE_OPENING
Definition uhs.h:38
@ UHS_HANDLE_STATE_INIT
Definition uhs.h:37
@ UHS_HANDLE_STATE_OPENED
Definition uhs.h:39
@ UHS_HANDLE_STATE_CLOSED
Definition uhs.h:41
@ UHS_HANDLE_STATE_CLOSING
Definition uhs.h:40
UHSStatus
Definition uhs.h:29
@ UHS_STATUS_HANDLE_INVALID_ARGS
Definition uhs.h:31
@ UHS_STATUS_OK
Definition uhs.h:30
@ UHS_STATUS_HANDLE_INVALID_STATE
Definition uhs.h:32
void(* UhsAcquireInterfaceCallback)(void *context, int32_t arg1, int32_t arg2)
Definition uhs.h:205
uint8_t bInterval
Definition uhs.h:115
int32_t BOOL
Definition wut_types.h:7