Changes

1,692 bytes added ,  05:53, 9 August 2015
Add ioctlv requests for control and bulk requests
Line 10: Line 10:  
===0x11 - UhsQueryInterfaces()===
 
===0x11 - UhsQueryInterfaces()===
 
This function is used to determine which USB device interfaces are plugged in and available. Its input is an [[#Interface Filter|interface filter buffer]] containing a series of parameters to filter the interfaces by, such as class, subclass, vendor ID, and product ID. The output is an array of [[#Interface Profile|interface profiles]], one for each interface being read. IOS_Ioctl() with this function returns the number of attached USB interfaces permitted by the filter.
 
This function is used to determine which USB device interfaces are plugged in and available. Its input is an [[#Interface Filter|interface filter buffer]] containing a series of parameters to filter the interfaces by, such as class, subclass, vendor ID, and product ID. The output is an array of [[#Interface Profile|interface profiles]], one for each interface being read. IOS_Ioctl() with this function returns the number of attached USB interfaces permitted by the filter.
 +
 +
==ioctlv() interface==
 +
===0x0C - UhsSubmitControlRequest()===
 +
This function is used to send a control request to a USB device interface. It takes two buffers through the ioctlv interface: a [[#Request Blocks|control request block]] and the actual data buffer, in that order. If the direction of the request is out to the device, there are 0 inputs and 2 outputs; if the direction is in to the host, there is 1 input and 1 output.
 +
 +
===0x0E - UhsSubmitBulkRequest()===
 +
This function is used to send a bulk request to a USB device interface. It takes two buffers through the ioctlv interface: a [[#Request Blocks|bulk request block]] and the actual data buffer, in that order. If the direction of the request is out to the device, there are 0 inputs and 2 outputs; if the direction is in to the host, there is 1 input and 1 output.
    
==Structures==
 
==Structures==
Line 108: Line 115:     
in_endpoints and out_endpoints are arrays of USB endpoint descriptors, but parsing them isn't exactly straightforward. The USB specification defines endpoint descriptors as 7-bytes, but UHS also supports 9-byte endpoints. Anyone programming with this API will have to iterate through the lists, applying casts as necessary. All USB endpoint descriptors start with a length, so check that first. If it's 0, assume the endpoint is empty and go 9-bytes forward for the next one. If it specifies a size, use that.
 
in_endpoints and out_endpoints are arrays of USB endpoint descriptors, but parsing them isn't exactly straightforward. The USB specification defines endpoint descriptors as 7-bytes, but UHS also supports 9-byte endpoints. Anyone programming with this API will have to iterate through the lists, applying casts as necessary. All USB endpoint descriptors start with a length, so check that first. If it's 0, assume the endpoint is empty and go 9-bytes forward for the next one. If it specifies a size, use that.
 +
 +
===Request Blocks===
 +
The USB spec defines four types of requests: control, bulk, isochronous, and interrupt. UHS provides request buffers to invoke all of them.
 +
<syntaxhighlight lang="C">
 +
/* Endpoint transfer directions */
 +
#define ENDPOINT_TRANSFER_OUT 1
 +
#define ENDPOINT_TRANSFER_IN 2
 +
 +
/* Control request block */
 +
typedef struct
 +
{
 +
    uint32_t if_handle;
 +
    uint8_t endpoint;                    // Usually (always?) 0 for default
 +
    uint32_t timeout;
 +
    uint32_t transfer_type;              // 1=control
 +
    uint8_t bRequest, bmRequestType;
 +
    uint16_t wValue, wIndex, wLength;
 +
} control_req_t;
 +
 +
/* Bulk request block */
 +
typedef struct
 +
{
 +
    uint32_t if_handle;
 +
    uint8_t endpoint;
 +
    uint32_t timeout;
 +
    uint32_t transfer_type;              // 3=bulk
 +
    int direction;                      // 1=out, 2=in as per above
 +
    int length;
 +
} bulk_req_t;
203

edits