-
Notifications
You must be signed in to change notification settings - Fork 91
/
usbd.h
383 lines (340 loc) · 9.17 KB
/
usbd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/**
* \usergroup{SceUsbd}
* \usage{psp2/usbd.h,SceUsbd_stub}
*/
#ifndef _PSP2_USBD_H_
#define _PSP2_USBD_H_
#include <vitasdk/build_utils.h>
#include <psp2/types.h>
#include <psp2common/usbd.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct SceUsbdDeviceInfo {
unsigned int port;
unsigned int device_num;
unsigned int unk3; // handled? 0, 1, 2
} SceUsbdDeviceInfo;
VITASDK_BUILD_ASSERT_EQ(0xC, SceUsbdDeviceInfo);
typedef struct SceUsbdTransferData {
unsigned int pipe; // 0x00
const void *data; // 0x04
unsigned int data_size; // 0x08
void *transferred; // // 0x0C // ptr to 8 bytes?
unsigned int timeout; // 0x10 // size of above ptr? only 8 allowed?
} SceUsbdTransferData;
VITASDK_BUILD_ASSERT_EQ(0x14, SceUsbdTransferData);
typedef struct SceUsbdReceiveEvent {
unsigned int unk0; // 0
unsigned int unk1; // next ptr?
unsigned int unk2; // != 8, set to 1, 2, 4? // transfer flags? type?
unsigned int unk3;
unsigned int unk4;
unsigned int unk5;
unsigned int transfer_id;
} SceUsbdReceiveEvent;
VITASDK_BUILD_ASSERT_EQ(0x1C, SceUsbdReceiveEvent);
#define USB_DESCRIPTOR_DEVICE 0x01 // bDescriptorType for a Device Descriptor.
#define USB_DESCRIPTOR_CONFIGURATION 0x02 // bDescriptorType for a Configuration Descriptor.
#define USB_DESCRIPTOR_STRING 0x03 // bDescriptorType for a String Descriptor.
#define USB_DESCRIPTOR_INTERFACE 0x04 // bDescriptorType for an Interface Descriptor.
#define USB_DESCRIPTOR_ENDPOINT 0x05 // bDescriptorType for an Endpoint Descriptor.
#define USB_DESCRIPTOR_DEVICE_QUALIFIER 0x06 // bDescriptorType for a Device Qualifier.
#define USB_DESCRIPTOR_OTHER_SPEED 0x07 // bDescriptorType for a Other Speed Configuration.
#define USB_DESCRIPTOR_INTERFACE_POWER 0x08 // bDescriptorType for Interface Power.
#define USB_DESCRIPTOR_OTG 0x09 // bDescriptorType for an OTG Descriptor.
/**
* Init usb subsystem
*
* @return 0 on success, < 0 on error
*
* @param[out] uid Pointer to uid
*
*/
int sceUsbdInit(SceUID *uid);
/**
* Stop usb subsystem
*
* @return 0 on success, < 0 on error
*
* @param uid uid
*
*/
int sceUsbdEnd(SceUID uid);
/**
* Get usb devices list
*
* @return 0 on success, < 0 on error
*
* @param[in] uid uid
* @param[in] num max number of devices to return (8 max)
* @param[out] info pointer to receive device info
*
*/
int sceUsbdGetDeviceList(SceUID uid, SceSize num, SceUsbdDeviceInfo *info); // 8 devices max
/**
* Get usb device descriptors data size
*
* @return size on success, < 0 on error
*
* @param uid uid
* @param device_id device id
*
*/
int sceUsbdGetDescriptorSize(SceUID uid, unsigned int device_id);
/**
* Get usb device descriptors (all)
*
* @return 0 on success, < 0 on error
*
* @param[in] uid uid
* @param[in] device_id device id
* @param[out] descriptor buffer for descriptor data
* @param[in] size buffer size
*
*/
int sceUsbdGetDescriptor(SceUID uid, SceUID device_id, unsigned char *descriptor, SceSize size);
/**
* Get usb device speed
*
* @return 0 on success, < 0 on error
*
* @param[in] uid uid
* @param[in] device_id device id
* @param[out] speed device speed
*
*/
int sceUsbdGetDeviceSpeed(SceUID uid, SceUID device_id, unsigned int *speed);
#define SCE_USBD_DEVICE_SPEED_LS (0)
#define SCE_USBD_DEVICE_SPEED_FS (1)
#define SCE_USBD_DEVICE_SPEED_HS (2)
/**
* Register callback to usb event
*
* @return 0 on success, < 0 on error
*
* @param[in] cbid callback uid
* @param[in] flag if 1 - trigger events immediately
*
* @note there may be only one callback registered through whole system.
* And it's currently taken up by shell.
*
*/
int sceUsbdRegisterCallback(SceUID cbid, int flag);
/**
* Remove callback to usb event
*
* @return 0 on success, < 0 on error
*
* @param[in] cbid callback uid
*
* @note this checks process id
*
*/
int sceUsbdUnregisterCallback(SceUID cbid);
/**
* Reset usb device
*
* @return 0 on success, < 0 on error
*
* @param[in] uid uid
* @param[in] device_id device id
*
*/
int sceUsbdResetDevice(SceUID uid, SceUID device_id);
/**
* Attach specified driver to device
*
* @return 0 on success, < 0 on error
*
* @param[in] uid uid
* @param[in] driver_id driver id (result of Register(Composite)Ldd)
* @param[in] bus usb port number
* @param[in] device usb device number
*
* @note device_id = (bus << 16) + device
*/
int sceUsbdAttach(SceUID uid, SceUID driver_id, SceUInt bus, SceUInt device);
/**
* Get device address
*
* @return 0 on success, < 0 on error
*
* @param[in] uid uid
* @param[in] device_id device id
* @param[out] addr buffer for return value
*
* @note it is unknown what that function actually returns in addr, observed only 0
*/
int sceUsbdGetDeviceAddress(SceUID uid, SceUID device_id, SceUsbdDeviceAddress *addr);
typedef struct SceUsbdTransferStatus {
uint32_t unk0; // < 0x40 - transfer id (result of sceUsbdTransferData)
uint32_t unk1; // unused
uint32_t unk2; // ret 4. ptr? // status?
uint32_t unk3; // ret 4. ptr? // transferred?
} SceUsbdTransferStatus;
VITASDK_BUILD_ASSERT_EQ(0x10, SceUsbdTransferStatus);
typedef struct SceUsbdIsochTransferStatus {
uint32_t unk0; // < 0x40 - size? pipe? transfer id?
uint32_t unk1; // unused
uintptr_t* unk2; // ret up to 0x28 buff. 10 * 4 bytes. or 8*5 bytes
uint32_t unk3; // ret 4. ptr?
} SceUsbdIsochTransferStatus;
VITASDK_BUILD_ASSERT_EQ(0x10, SceUsbdIsochTransferStatus);
/**
* Get transfer status
*
* @return 0 on success, < 0 on error
*
* @param[in] transfer_id transfer uid
* @param[out] status buffer for return value
*
* @note it is unknown what that function actually returns in addr, observed only 0
*/
int sceUsbdGetTransferStatus(SceUID transfer_id, SceUsbdTransferStatus* status);
/**
* Get isochronous transfer status
*
* @return 0 on success, < 0 on error
*
* @param[in] transfer_id transfer uid
* @param[out] status buffer for return value
*
* @note it is unknown what that function actually returns in addr, observed only 0
*/
int sceUsbdGetIsochTransferStatus(SceUID transfer_id, SceUsbdIsochTransferStatus* status);
typedef struct SceUsbdDevicePipe {
unsigned int device_id;
unsigned int unk1;
unsigned int unk2;
unsigned int unk3;
unsigned int unk4;
unsigned int unk5;
} SceUsbdDevicePipe;
VITASDK_BUILD_ASSERT_EQ(0x18, SceUsbdDevicePipe);
/**
* Open endpoint communication pipe
*
* @return pipe_id on success, < 0 on error
*
* @param[in] uid uid
* @param[in] pipe endpoint to open
*
*/
SceUID sceUsbdOpenPipe(SceUID uid, SceUsbdDevicePipe* pipe);
/**
* Open endpoint communication pipe for default config endpoint
*
* @return pipe_id on success, < 0 on error
*
* @param[in] uid uid
* @param[in] device_id device id
*
*/
SceUID sceUsbdOpenDefaultPipe(SceUID uid, SceUID device_id);
/**
* Close endpoint communication pipe
*
* @return 0 on success, < 0 on error
*
* @param[in] uid uid
* @param[in] pipe_id pipe uid
*
*/
int sceUsbdClosePipe(SceUID uid, SceUID pipe_id);
/**
* Transfer data to/from endpoint
*
* @return transfer_id on success, < 0 on error
*
* @param[in] uid uid
* @param[in] data data to transfer
*
*/
SceUID sceUsbdTransferData(SceUID uid, SceUsbdTransferData *data);
typedef struct SceUsbdIsochTransfer {
unsigned int unk0; // array of num_packets? ptrs to 4
unsigned int unk1; // num packets?
unsigned int unk2;
unsigned int unk3;
unsigned int unk4;
unsigned int unk5;
unsigned int unk6;
unsigned int unk7;
unsigned int unk8;
unsigned int unk9;
} SceUsbdIsochTransfer;
VITASDK_BUILD_ASSERT_EQ(0x28, SceUsbdIsochTransfer);
/**
* Transfer data to/from endpoint isochronously
*
* @return transfer_id on success, < 0 on error
*
* @param[in] uid uid
* @param[in] pipe_id pipe uid
* @param[in] transfer data to transfer
*
*/
int sceUsbdIsochTransferData(SceUID uid, SceUID pipe_id, SceUsbdIsochTransfer* transfer);
/**
* Receive usb event
*
* @return transfer_id on success, < 0 on error
*
* @param[in] uid uid
* @param[out] event
*
*/
int sceUsbdReceiveEvent(SceUID uid, SceUsbdReceiveEvent *event);
/**
* Register logical device driver
*
* @return driver_id on success, < 0 on error
*
* @param[in] uid uid
* @param[in] name driver name, 255 max
*
*/
SceUID sceUsbdRegisterLdd(SceUID uid, char* name);
/**
* Register logical device driver for composite devices
*
* @return driver_id on success, < 0 on error
*
* @param[in] uid uid
* @param[in] name driver name, 255 max
*
*/
SceUID sceUsbdRegisterCompositeLdd(SceUID uid, char* name);
/**
* De-register logical device driver
*
* @return 0 on success, < 0 on error
*
* @param[in] uid uid
* @param[in] name driver name, 255 max
*
*/
int sceUsbdUnregisterLdd(SceUID uid, char* name);
typedef struct SceUsbdAttachCompositeParam {
uint32_t driver_id;
uint32_t bus;
uint32_t device;
uint32_t unk3; // num devices?
uint32_t unk4;
} SceUsbdAttachCompositeParam;
VITASDK_BUILD_ASSERT_EQ(0x14, SceUsbdAttachCompositeParam);
/**
* Attach composite driver to device
*
* @return 0 on success, < 0 on error
*
* @param[in] uid uid
* @param[in] param parameters
*
*/
int sceUsbdAttachCompositeLdd(SceUID uid, SceUsbdAttachCompositeParam* param);
#ifdef __cplusplus
}
#endif
#endif /* _PSP2_USBD_H_ */