#include "usb_lowlevel.h"
// === PROTOTYPES ===
+void *USB_int_Request(tUSBHost *Host, int Addr, int EndPt, int Type, int Req, int Val, int Indx, int Len, void *Data);
int USB_int_SendSetupSetAddress(tUSBHost *Host, int Address);
int USB_int_ReadDescriptor(tUSBDevice *Dev, int Endpoint, int Type, int Index, int Length, void *Dest);
char *USB_int_GetDeviceString(tUSBDevice *Dev, int Endpoint, int Index);
req.Index = LittleEndian16( Indx );
req.Length = LittleEndian16( Len );
- hdl = Host->HostDef->SendSETUP(Host->Ptr, Addr, EndPt, 0, NULL, &req, sizeof(req));
+ hdl = Host->HostDef->SendSETUP(Host->Ptr, Addr, EndPt, 0, NULL, NULL, &req, sizeof(req));
// TODO: Data toggle?
// TODO: Multi-packet transfers
{
void *hdl2;
- hdl = Host->HostDef->SendIN(Host->Ptr, Addr, EndPt, 0, NULL, Data, Len);
+ hdl = Host->HostDef->SendIN(Host->Ptr, Addr, EndPt, 0, NULL, NULL, Data, Len);
- hdl2 = Host->HostDef->SendOUT(Host->Ptr, Addr, EndPt, 0, NULL, NULL, 0);
+ hdl2 = Host->HostDef->SendOUT(Host->Ptr, Addr, EndPt, 0, NULL, NULL, NULL, 0);
while( Host->HostDef->IsOpComplete(Host->Ptr, hdl2) == 0 )
Time_Delay(1);
}
void *hdl2;
if( Len > 0 )
- hdl = Host->HostDef->SendOUT(Host->Ptr, Addr, EndPt, 0, NULL, Data, Len);
+ hdl = Host->HostDef->SendOUT(Host->Ptr, Addr, EndPt, 0, NULL, NULL, Data, Len);
else
hdl = NULL;
// Status phase (DataToggle=1)
- hdl2 = Host->HostDef->SendIN(Host->Ptr, Addr, EndPt, 1, NULL, NULL, 0);
+ hdl2 = Host->HostDef->SendIN(Host->Ptr, Addr, EndPt, 1, NULL, NULL, NULL, 0);
while( Host->HostDef->IsOpComplete(Host->Ptr, hdl2) == 0 )
Time_Delay(1);
}
void *final;
req.ReqType = 0x80;
+ switch( Type & 0xF00 )
+ {
+ case 0x000: req.ReqType |= (0 << 5); break; // Standard
+ case 0x100: req.ReqType |= (1 << 5); break; // Class
+ case 0x200: req.ReqType |= (2 << 5); break; // Vendor
+ }
+
req.Request = 6; // GET_DESCRIPTOR
req.Value = LittleEndian16( ((Type & 0xFF) << 8) | (Index & 0xFF) );
req.Index = LittleEndian16( 0 ); // TODO: Language ID
Dev->Host->HostDef->SendSETUP(
Dev->Host->Ptr, Dev->Address, Endpoint,
- 0, NULL,
+ 0, NULL, NULL,
&req, sizeof(req)
);
{
Dev->Host->HostDef->SendIN(
Dev->Host->Ptr, Dev->Address, Endpoint,
- bToggle, NULL,
+ bToggle, NULL, NULL,
Dest, ciMaxPacketSize
);
bToggle = !bToggle;
final = Dev->Host->HostDef->SendIN(
Dev->Host->Ptr, Dev->Address, Endpoint,
- bToggle, INVLPTR,
+ bToggle, INVLPTR, NULL,
Dest, Length
);
struct sDescriptor_String str;
int src_len, new_len;
char *ret;
+
+ if(Index == 0) return strdup("");
USB_int_ReadDescriptor(Dev, Endpoint, 3, Index, sizeof(str), &str);
+ if(str.Length < 2) {
+ Log_Error("USB", "String %p:%i:%i:%i descriptor is undersized (%i)",
+ Dev->Host, Dev->Address, Endpoint, Index, str.Length);
+ return NULL;
+ }
// if(str.Length > sizeof(str)) {
// // IMPOSSIBLE!
// Log_Error("USB", "String is %i bytes, which is over prealloc size (%i)",
// }
src_len = (str.Length - 2) / sizeof(str.Data[0]);
+ LOG("&str = %p, src_len = %i", &str, src_len);
+
new_len = _UTF16to8(str.Data, src_len, NULL);
ret = malloc( new_len + 1 );
_UTF16to8(str.Data, src_len, ret);