X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FModules%2FUSB%2FCore%2Fusb_lowlevel.c;h=27bad3e12f9f750c651ab48c98a2fac5d7ac1e9b;hb=36b950d17b828c7cd2e5e9dbe5fb4cbded89889c;hp=7cea58aa56fff8019440acf25c6a72b6a3635c4d;hpb=5db5602b547aa66aa115a9dbb4360fa3633e620e;p=tpg%2Facess2.git diff --git a/KernelLand/Modules/USB/Core/usb_lowlevel.c b/KernelLand/Modules/USB/Core/usb_lowlevel.c index 7cea58aa..27bad3e1 100644 --- a/KernelLand/Modules/USB/Core/usb_lowlevel.c +++ b/KernelLand/Modules/USB/Core/usb_lowlevel.c @@ -14,7 +14,7 @@ #include // === PROTOTYPES === -void *USB_int_Request(tUSBHost *Host, int Addr, int EndPt, int Type, int Req, int Val, int Indx, int Len, void *Data); +void *USB_int_Request(tUSBDevice *Dev, int EndPt, int Type, int Req, int Val, int Indx, int Len, void *Data); void USB_int_WakeThread(void *Thread, void *Data, size_t Length); int USB_int_SendSetupSetAddress(tUSBHost *Host, int Address); int USB_int_ReadDescriptor(tUSBDevice *Dev, int Endpoint, int Type, int Index, int Length, void *Dest); @@ -22,17 +22,28 @@ char *USB_int_GetDeviceString(tUSBDevice *Dev, int Endpoint, int Index); int _UTF16to8(Uint16 *Input, int InputLen, char *Dest); // === CODE === -void *USB_int_Request(tUSBHost *Host, int Addr, int EndPt, int Type, int Req, int Val, int Indx, int Len, void *Data) +void *USB_int_Request(tUSBDevice *Device, int EndPt, int Type, int Req, int Val, int Indx, int Len, void *Data) { + tUSBHost *Host = Device->Host; void *hdl; // TODO: Sanity check (and check that Type is valid) struct sDeviceRequest req; - int dest = Addr * 16 + EndPt; // TODO: Validate - void *dest_hdl = (void*)(dest+1); // TODO: Get registered handle instead tThread *thisthread = Proc_GetCurThread(); + void *dest_hdl; + + ENTER("pDevice xEndPt iType iReq iVal iIndx iLen pData", + Device, EndPt, Type, Req, Val, Indx, Len, Data); - ENTER("pHost xdest iType iReq iVal iIndx iLen pData", - Host, dest, Type, Req, Val, Indx, Len, Data); + if( EndPt < 0 || EndPt >= 16 ) { + LEAVE('n'); + return NULL; + } + + dest_hdl = Device->EndpointHandles[EndPt]; + if( !dest_hdl ) { + LEAVE('n'); + return NULL; + } req.ReqType = Type; req.Request = Req; @@ -73,18 +84,22 @@ void USB_int_WakeThread(void *Thread, void *Data, size_t Length) int USB_int_SendSetupSetAddress(tUSBHost *Host, int Address) { - USB_int_Request(Host, 0, 0, 0x00, 5, Address & 0x7F, 0, 0, NULL); + USB_int_Request(Host->RootHubDev, 0, 0x00, 5, Address & 0x7F, 0, 0, NULL); return 0; } int USB_int_ReadDescriptor(tUSBDevice *Dev, int Endpoint, int Type, int Index, int Length, void *Dest) { struct sDeviceRequest req; - int dest = Dev->Address*16 + Endpoint; - void *dest_hdl = (void*)(dest+1); // TODO: Get correct handle + void *dest_hdl; + + dest_hdl = Dev->EndpointHandles[Endpoint]; + if( !dest_hdl ) { + return -1; + } - ENTER("pDev xdest iType iIndex iLength pDest", - Dev, dest, Type, Index, Length, Dest); + ENTER("pDev xEndpoint iType iIndex iLength pDest", + Dev, Endpoint, Type, Index, Length, Dest); req.ReqType = 0x80; req.ReqType |= ((Type >> 8) & 0x3) << 5; // Bits 5/6