vitasdk
Documentation of the vitasdk
usbd.h
Go to the documentation of this file.
1
7#ifndef _PSP2KERN_USBD_H_
8#define _PSP2KERN_USBD_H_
9
10#include <vitasdk/build_utils.h>
11#include <psp2common/types.h>
12#include <psp2common/usbd.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#define SCE_USBD_PROBE_SUCCEEDED (0)
19#define SCE_USBD_PROBE_FAILED (-1)
20#define SCE_USBD_ATTACH_SUCCEEDED (0)
21#define SCE_USBD_ATTACH_FAILED (-1)
22#define SCE_USBD_DETACH_SUCCEEDED (0)
23#define SCE_USBD_DETACH_FAILED (-1)
24
25#define SCE_USBD_MAX_LS_CONTROL_PACKET_SIZE 8
26#define SCE_USBD_MAX_FS_CONTROL_PACKET_SIZE 64
27#define SCE_USBD_MAX_ISOCHRONOUS_PACKET_SIZE 1023
28#define SCE_USBD_MAX_LS_INTERRUPT_PACKET_SIZE 8
29#define SCE_USBD_MAX_FS_INTERRUPT_PACKET_SIZE 64
30#define SCE_USBD_MAX_BULK_PACKET_SIZE 64
31
32#define SCE_USBD_FEATURE_ENDPOINT_HALT 0x00
33#define SCE_USBD_FEATURE_DEVICE_REMOTE_WAKEUP 0x01
34
35
36typedef struct SceUsbdDriver {
37 const char *name;
38 int (*probe)(int device_id);
39 int (*attach)(int device_id);
40 int (*detach)(int device_id);
43
44typedef struct SceUsbdCompositeDriver {
45 const char *name;
46 int (*probe)(int device_id, SceUsbdEndpointDescriptor* desc); // endpoint descriptor should be interface one
47 int (*attach)(int device_id);
48 int (*detach)(int device_id);
51
52typedef struct SceUsbdDeviceRequest {
54 uint8_t bRequest;
55 uint16_t wValue;
56 uint16_t wIndex;
57 uint16_t wLength;
60
76
90
91typedef struct ksceUsbdIsochPswLen {
92 uint16_t len:12;
93 uint16_t PSW:4;
96
104
114
124
134
144
145
157
168
178
179typedef void (*ksceUsbdDoneCallback)(int32_t result, int32_t count, void* arg);
180typedef void (*ksceUsbdIsochDoneCallback)(int32_t result, ksceUsbdIsochTransfer *req, void *arg);
181
195 const SceUsbdDeviceRequest *req,
196 unsigned char *buffer,
198 void *user_data);
199
213 unsigned char *buffer,
216 void *user_data);
217
230 ksceUsbdIsochTransfer* transfer,
232 void *user_data);
233
248 unsigned char *buffer,
249 unsigned int length,
251 void *user_data);
252
266int ksceUsbdBulkTransfer2(int pipe_id,
267 unsigned char *buffer,
268 unsigned int length,
270 void *user_data);
271
272
282int ksceUsbdGetDeviceLocation(SceUID device_id, uint8_t *location);
283
284int ksceUsbdSuspend(int port);
285int ksceUsbdSuspendPhase2(int port, int flag);
286int ksceUsbdResume(int port);
287
288int ksceUsbdHostStop(int port);
289int ksceUsbdHostStart(int port);
290
300int ksceUsbdGetDeviceSpeed(int device_id, uint8_t *speed);
301#define SCE_USBD_DEVICE_SPEED_LS (0)
302#define SCE_USBD_DEVICE_SPEED_FS (1)
303#define SCE_USBD_DEVICE_SPEED_HS (2)
304
305
306#define ksceUsbdSetConfiguration(pid, config, cb, arg) ({ \
307 SceUsbdDeviceRequest _dr; \
308 _dr.bmRequestType = 0x00; \
309 _dr.bRequest = SCE_USBD_REQUEST_SET_CONFIGURATION; \
310 _dr.wValue = (config); \
311 _dr.wIndex = 0; \
312 _dr.wLength = 0; \
313 ksceUsbdControlTransfer((pid), (&_dr), NULL, (cb), (arg)); })
314
315
316#define ksceUsbdClearDeviceFeature(pid, fs, cb, arg) ({ \
317 SceUsbdDeviceRequest _dr; \
318 _dr.bmRequestType = 0x00; \
319 _dr.bRequest = SCE_USBD_REQUEST_CLEAR_FEATURE; \
320 _dr.wValue = (fs); \
321 _dr.wIndex = 0; \
322 _dr.wLength = 0; \
323 ksceUsbdControlTransfer((pid), (&_dr), NULL, (cb), (arg)); })
324
325#define ksceUsbdClearInterfaceFeature(pid, fs, interface, cb, arg) ({ \
326 SceUsbdDeviceRequest _dr; \
327 _dr.bmRequestType = 0x01; \
328 _dr.bRequest = SCE_USBD_REQUEST_CLEAR_FEATURE; \
329 _dr.wValue = (fs); \
330 _dr.wIndex = (interface); \
331 _dr.wLength = 0; \
332 ksceUsbdControlTransfer((pid), (&_dr), NULL, (cb), (arg)); })
333
334#define ksceUsbdClearEndpointFeature(pid, fs, endpoint, cb, arg) ({ \
335 SceUsbdDeviceRequest _dr; \
336 _dr.bmRequestType = 0x02; \
337 _dr.bRequest = SCE_USBD_REQUEST_CLEAR_FEATURE; \
338 _dr.wValue = (fs); \
339 _dr.wIndex = (endpoint); \
340 _dr.wLength = 0; \
341 ksceUsbdControlTransfer((pid), (&_dr), NULL, (cb), (arg)); })
342
343#define ksceUsbdGetConfiguration(pid, ptr, cb, arg) ({ \
344 SceUsbdDeviceRequest _dr; \
345 _dr.bmRequestType = 0x80; \
346 _dr.bRequest = SCE_USBD_REQUEST_GET_CONFIGURATION; \
347 _dr.wValue = 0; \
348 _dr.wIndex = 0; \
349 _dr.wLength = 1; \
350 ksceUsbdControlTransfer((pid), (&_dr), (ptr), (cb), (arg)); })
351
352#define ksceUsbdGetDescriptor(pid, type, index, lang_id, ptr, len, cb, arg) ({ \
353 SceUsbdDeviceRequest _dr; \
354 _dr.bmRequestType = 0x80; \
355 _dr.bRequest = SCE_USBD_REQUEST_GET_DESCRIPTOR; \
356 _dr.wValue = ((type) << 8) | (index); \
357 _dr.wIndex = (lang_id); \
358 _dr.wLength = (len); \
359 ksceUsbdControlTransfer((pid), (&_dr), (ptr), (cb), (arg)); })
360
361#define ksceUsbdGetInterface(pid, interface, ptr, cb, arg) ({ \
362 SceUsbdDeviceRequest _dr; \
363 _dr.bmRequestType = 0x81; \
364 _dr.bRequest = SCE_USBD_REQUEST_GET_INTERFACE; \
365 _dr.wValue = 0; \
366 _dr.wIndex = (interface); \
367 _dr.wLength = 1; \
368 ksceUsbdControlTransfer((pid), (&_dr), (ptr), (cb), (arg)); })
369
370#define ksceUsbdGetDeviceStatus(pid, ptr, cb, arg) ({ \
371 SceUsbdDeviceRequest _dr; \
372 _dr.bmRequestType = 0x80; \
373 _dr.bRequest = SCE_USBD_REQUEST_GET_STATUS; \
374 _dr.wValue = 0; \
375 _dr.wIndex = 0; \
376 _dr.wLength = 2; \
377 ksceUsbdControlTransfer((pid), (&_dr), (ptr), (cb), (arg)); })
378
379#define ksceUsbdGetInterfaceStatus(pid, interface, ptr, cb, arg) ({ \
380 SceUsbdDeviceRequest _dr; \
381 _dr.bmRequestType = 0x81; \
382 _dr.bRequest = SCE_USBD_REQUEST_GET_STATUS; \
383 _dr.wValue = 0; \
384 _dr.wIndex = (interface); \
385 _dr.wLength = 2; \
386 ksceUsbdControlTransfer((pid), (&_dr), (ptr), (cb), (arg)); })
387
388#define ksceUsbdGetEndpointStatus(pid, endpoint, ptr, cb, arg) ({ \
389 SceUsbdDeviceRequest _dr; \
390 _dr.bmRequestType = 0x82; \
391 _dr.bRequest = SCE_USBD_REQUEST_GET_STATUS; \
392 _dr.wValue = 0; \
393 _dr.wIndex = (endpoint); \
394 _dr.wLength = 2; \
395 ksceUsbdControlTransfer((pid), (&_dr), (ptr), (cb), (arg)); })
396
397#define ksceUsbdSetAddress(pid, address, cb, arg) ({ \
398 SceUsbdDeviceRequest _dr; \
399 _dr.bmRequestType = 0x00; \
400 _dr.bRequest = SCE_USBD_REQUEST_SET_ADDRESS; \
401 _dr.wValue = (address); \
402 _dr.wIndex = 0; \
403 _dr.wLength = 0; \
404 ksceUsbdControlTransfer((pid), (&_dr), NULL, (cb), (arg)); })
405
406#define ksceUsbdSetConfiguration(pid, config, cb, arg) ({ \
407 SceUsbdDeviceRequest _dr; \
408 _dr.bmRequestType = 0x00; \
409 _dr.bRequest = SCE_USBD_REQUEST_SET_CONFIGURATION; \
410 _dr.wValue = (config); \
411 _dr.wIndex = 0; \
412 _dr.wLength = 0; \
413 ksceUsbdControlTransfer((pid), (&_dr), NULL, (cb), (arg)); })
414
415#define ksceUsbdSetDeviceDescriptor(pid, type, index, lang_id, ptr, len, \
416 cb, arg) ({ \
417 SceUsbdDeviceRequest _dr; \
418 _dr.bmRequestType = 0x00; \
419 _dr.bRequest = SCE_USBD_REQUEST_SET_DESCRIPTOR; \
420 _dr.wValue = ((type) << 8) | (index); \
421 _dr.wIndex = (lang_id); \
422 _dr.wLength = (len); \
423 ksceUsbdControlTransfer((pid), (&_dr), (ptr), (cb), (arg)); })
424
425#define ksceUsbdSetInterfaceDescriptor(pid, type, index, lang_id, ptr, len, \
426 cb, arg) ({ \
427 SceUsbdDeviceRequest _dr; \
428 _dr.bmRequestType = 0x01; \
429 _dr.bRequest = SCE_USBD_REQUEST_SET_DESCRIPTOR; \
430 _dr.wValue = ((type) << 8) | (index); \
431 _dr.wIndex = (lang_id); \
432 _dr.wLength = (len); \
433 ksceUsbdControlTransfer((pid), (&_dr), (ptr), (cb), (arg)); })
434
435#define ksceUsbdSetEndpointDescriptor(pid, type, index, lang_id, ptr, len, \
436 cb, arg) ({ \
437 SceUsbdDeviceRequest _dr; \
438 _dr.bmRequestType = 0x02; \
439 _dr.bRequest = SCE_USBD_REQUEST_SET_DESCRIPTOR; \
440 _dr.wValue = ((type) << 8) | (index); \
441 _dr.wIndex = (lang_id); \
442 _dr.wLength = (len); \
443 ksceUsbdControlTransfer((pid), (&_dr), (ptr), (cb), (arg)); })
444
445#define ksceUsbdSetDeviceFeature(pid, fs, cb, arg) ({ \
446 SceUsbdDeviceRequest _dr; \
447 _dr.bmRequestType = 0x00; \
448 _dr.bRequest = SCE_USBD_REQUEST_SET_FEATURE; \
449 _dr.wValue = (fs); \
450 _dr.wIndex = 0; \
451 _dr.wLength = 0; \
452 ksceUsbdControlTransfer((pid), (&_dr), NULL, (cb), (arg)); })
453
454#define ksceUsbdSetInterfaceFeature(pid, fs, interface, cb, arg) ({ \
455 SceUsbdDeviceRequest _dr; \
456 _dr.bmRequestType = 0x01; \
457 _dr.bRequest = SCE_USBD_REQUEST_SET_FEATURE; \
458 _dr.wValue = (fs); \
459 _dr.wIndex = (interface); \
460 _dr.wLength = 0; \
461 ksceUsbdControlTransfer((pid), (&_dr), NULL, (cb), (arg)); })
462
463#define ksceUsbdSetEndpointFeature(pid, fs, endpoint, cb, arg) ({ \
464 SceUsbdDeviceRequest _dr; \
465 _dr.bmRequestType = 0x02; \
466 _dr.bRequest = SCE_USBD_REQUEST_SET_FEATURE; \
467 _dr.wValue = (fs); \
468 _dr.wIndex = (endpoint); \
469 _dr.wLength = 0; \
470 ksceUsbdControlTransfer((pid), (&_dr), NULL, (cb), (arg)); })
471
472#define ksceUsbdSetInterface(pid, interface, alt_setting, cb, arg) ({ \
473 SceUsbdDeviceRequest _dr; \
474 _dr.bmRequestType = 0x01; \
475 _dr.bRequest = SCE_USBD_REQUEST_SET_INTERFACE; \
476 _dr.wValue = (alt_setting); \
477 _dr.wIndex = (interface); \
478 _dr.wLength = 0; \
479 ksceUsbdControlTransfer((pid), (&_dr), NULL, (cb), (arg)); })
480
481#define ksceUsbdSynchFrame(pid, endpoint, pfn, cb, arg) ({ \
482 SceUsbdDeviceRequest _dr; \
483 _dr.bmRequestType = 0x82; \
484 _dr.bRequest = SCE_USBD_REQUEST_SYNCH_FRAME; \
485 _dr.wValue = 0; \
486 _dr.wIndex = (endpoint); \
487 _dr.wLength = 2; \
488 ksceUsbdControlTransfer((pid), (&_dr), pfn, (cb), (arg)); })
489
490// OHCI/EHCI completion codes
491#define OHCI_CC_NO_ERROR 0x0
492#define OHCI_CC_CRC 0x1
493#define OHCI_CC_BIT_STUFFING 0x2
494#define OHCI_CC_DATA_TOGGLE_MISMATCH 0x3
495#define OHCI_CC_STALL 0x4
496#define OHCI_CC_DEVICE_NOT_RESPONDING 0x5
497#define OHCI_CC_PID_CHECK_FAILURE 0x6
498#define OHCI_CC_UNEXPECTED_PID 0x7
499#define OHCI_CC_DATA_OVERRUN 0x8
500#define OHCI_CC_DATA_UNDERRUN 0x9
501#define OHCI_CC_BUFFER_OVERRUN 0xc
502#define OHCI_CC_BUFFER_UNDERRUN 0xd
503#define OHCI_CC_NOT_ACCESSED1 0xe
504#define OHCI_CC_NOT_ACCESSED2 0xf
505#define EHCI_CC_MISSED_MICRO_FRAME 0x10
506#define EHCI_CC_XACT 0x20
507#define EHCI_CC_BABBLE 0x30
508#define EHCI_CC_DATABUF 0x40
509#define EHCI_CC_HALTED 0x50
510
511// Isochronous transfer(PSW) completion codes
512#define USBD_CC_NOERR 0x0
513#define USBD_CC_MISSED_MICRO_FRAME 0x1
514#define USBD_CC_XACTERR 0x2
515#define USBD_CC_BABBLE 0x4
516#define USBD_CC_DATABUF 0x8
517
518int ksceUsbd_05073925(SceUID device_id, int* unk1, int* unk2);
519int ksceUsbd_7938DAC7(SceUID pipe_id); // clear halt?
520
521#ifdef __cplusplus
522}
523#endif
524
525#endif /* _PSP2KERN_USBD_H_ */
#define VITASDK_BUILD_ASSERT_EQ(__size__, __name__)
Definition build_utils.h:13
uint8_t type
0 = read?, 1 = write?, 2 = feature?, 3 = ?
Definition bt.h:2
void * buffer
Definition bt.h:6
uint32_t length
Definition bt.h:7
unsigned int SceSize
Definition types.h:56
int SceUID
UIDs are used to describe many different kernel objects.
Definition types.h:90
uint8_t bRequest
Definition usbd.h:54
SceUsbdDescriptorType
Definition usbd.h:46
int ksceUsbdBulkTransfer2(int pipe_id, unsigned char *buffer, unsigned int length, ksceUsbdDoneCallback cb, void *user_data)
Transfer data to/from endpoint.
int(* probe)(int device_id)
Definition usbd.h:38
int ksceUsbdControlTransfer(SceUID pipe_id, const SceUsbdDeviceRequest *req, unsigned char *buffer, ksceUsbdDoneCallback cb, void *user_data)
Transfer data to/from endpoint.
int ksceUsbdSuspendPhase2(int port, int flag)
const char * name
Definition usbd.h:45
int(* attach)(int device_id)
Definition usbd.h:47
int ksceUsbdHostStart(int port)
void(* ksceUsbdDoneCallback)(int32_t result, int32_t count, void *arg)
Definition usbd.h:179
uint16_t wValue
Definition usbd.h:55
int32_t relative_start_frame
Definition usbd.h:99
int ksceUsbdRegisterCompositeLdd(const SceUsbdCompositeDriver *driver)
Register USB driver for composite devices.
void(* ksceUsbdIsochDoneCallback)(int32_t result, ksceUsbdIsochTransfer *req, void *arg)
Definition usbd.h:180
const char * name
Definition usbd.h:37
uint16_t wIndex
Definition usbd.h:56
int(* attach)(int device_id)
Definition usbd.h:39
int ksceUsbdIsochronousTransfer(SceUID pipe_id, ksceUsbdIsochTransfer *transfer, ksceUsbdIsochDoneCallback cb, void *user_data)
Transfer isochronous data to/from endpoint.
int(* detach)(int device_id)
Definition usbd.h:48
int ksceUsbdResume(int port)
uint16_t PSW
Definition usbd.h:93
void * ksceUsbdScanStaticDescriptor(SceUID device_id, void *start, SceUsbdDescriptorType type)
Return usb descriptor.
int ksceUsbdClosePipe(SceUID pipe_id)
Close communication pipe to endpoint.
SceUID ksceUsbdOpenPipe(int device_id, SceUsbdEndpointDescriptor *endpoint)
Open communication pipe to endpoint.
uint16_t wLength
Definition usbd.h:57
int ksceUsbdBulkTransfer(SceUID pipe_id, unsigned char *buffer, unsigned int length, ksceUsbdDoneCallback cb, void *user_data)
Transfer data to/from endpoint.
int ksceUsbdInterruptTransfer(SceUID pipe_id, unsigned char *buffer, SceSize length, ksceUsbdDoneCallback cb, void *user_data)
Transfer data to/from interrupt endpoint.
int(* detach)(int device_id)
Definition usbd.h:40
int ksceUsbdGetDeviceSpeed(int device_id, uint8_t *speed)
Get device speed.
int ksceUsbdHostStop(int port)
uint8_t bmRequestType
Definition usbd.h:53
int ksceUsbdUnregisterCompositeLdd(const SceUsbdCompositeDriver *driver)
De-register USB driver for composite devices.
uint16_t len
Definition usbd.h:92
int(* probe)(int device_id, SceUsbdEndpointDescriptor *desc)
Definition usbd.h:46
int ksceUsbdRegisterDriver(const SceUsbdDriver *driver)
Register USB driver.
int ksceUsbd_05073925(SceUID device_id, int *unk1, int *unk2)
int ksceUsbdSuspend(int port)
unsigned short unk1
Definition usbd.h:1
void * buffer_base
Definition usbd.h:98
int ksceUsbdGetDeviceLocation(SceUID device_id, uint8_t *location)
Get device location.
int ksceUsbd_7938DAC7(SceUID pipe_id)
int32_t num_packets
Definition usbd.h:100
SceUsbdReqtype
Definition usbd.h:61
ksceUsbdIsochPswLen packets[8]
Definition usbd.h:101
SceUsbdRequest
Definition usbd.h:77
int ksceUsbdUnregisterDriver(const SceUsbdDriver *driver)
De-register USB driver.
@ SCE_USBD_REQTYPE_DIR_TO_HOST
Definition usbd.h:64
@ SCE_USBD_REQTYPE_TYPE_CLASS
Definition usbd.h:67
@ SCE_USBD_REQTYPE_RECIP_BITS
Definition usbd.h:70
@ SCE_USBD_REQTYPE_TYPE_STANDARD
Definition usbd.h:66
@ SCE_USBD_REQTYPE_TYPE_RESERVED
Definition usbd.h:69
@ SCE_USBD_REQTYPE_RECIP_INTERFACE
Definition usbd.h:72
@ SCE_USBD_REQTYPE_TYPE_BITS
Definition usbd.h:65
@ SCE_USBD_REQTYPE_RECIP_DEVICE
Definition usbd.h:71
@ SCE_USBD_REQTYPE_RECIP_ENDPOINT
Definition usbd.h:73
@ SCE_USBD_REQTYPE_TYPE_VENDOR
Definition usbd.h:68
@ SCE_USBD_REQTYPE_DIR_TO_DEVICE
Definition usbd.h:63
@ SCE_USBD_REQTYPE_RECIP_OTHER
Definition usbd.h:74
@ SCE_USBD_REQTYPE_DIR_BITS
Definition usbd.h:62
@ SCE_USBD_REQUEST_SET_FEATURE
Definition usbd.h:80
@ SCE_USBD_REQUEST_GET_STATUS
Definition usbd.h:78
@ SCE_USBD_REQUEST_SYNCH_FRAME
Definition usbd.h:88
@ SCE_USBD_REQUEST_SET_DESCRIPTOR
Definition usbd.h:83
@ SCE_USBD_REQUEST_SET_ADDRESS
Definition usbd.h:81
@ SCE_USBD_REQUEST_GET_DESCRIPTOR
Definition usbd.h:82
@ SCE_USBD_REQUEST_GET_CONFIGURATION
Definition usbd.h:84
@ SCE_USBD_REQUEST_GET_INTERFACE
Definition usbd.h:86
@ SCE_USBD_REQUEST_SET_INTERFACE
Definition usbd.h:87
@ SCE_USBD_REQUEST_CLEAR_FEATURE
Definition usbd.h:79
@ SCE_USBD_REQUEST_SET_CONFIGURATION
Definition usbd.h:85
Definition usbd.h:44
Definition usbd.h:52
Definition usbd.h:36
Definition usbd.h:127
Definition usbd.h:91
Definition usbd.h:97