From: John Hodge Date: Sat, 19 May 2012 16:02:24 +0000 (+0800) Subject: Modules/USB MSC - Can now read on qemu (dunno how reliable) X-Git-Tag: rel0.15~611^2~88 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=27e4c3e417e0205fd35cb39919933eecaa9477ba;p=tpg%2Facess2.git Modules/USB MSC - Can now read on qemu (dunno how reliable) --- diff --git a/KernelLand/Modules/USB/MSC/main.c b/KernelLand/Modules/USB/MSC/main.c index 6d64b7bb..c3509f6d 100644 --- a/KernelLand/Modules/USB/MSC/main.c +++ b/KernelLand/Modules/USB/MSC/main.c @@ -5,7 +5,7 @@ * main.c * - Driver Core */ -#define DEBUG 1 +#define DEBUG 0 #define VERSION VER2(0,1) #include #include @@ -57,7 +57,9 @@ void MSC_DeviceConnected(tUSBInterface *Dev, void *Descriptors, size_t Descripto USB_SetDeviceDataPtr(Dev, info); info->BlockCount = MSC_SCSI_GetSize(Dev, &info->BlockSize); - + + LOG("Device has 0x%llx blocks of 0x%x bytes", + info->BlockCount, info->BlockSize); LVM_AddVolume(&gMSC_SCSI_VolType, "0", Dev, info->BlockSize, info->BlockCount); } @@ -79,10 +81,10 @@ int MSC_int_CreateCBW(tMSC_CBW *Cbw, int bInput, size_t CmdLen, const void *CmdD } Cbw->dCBWSignature = LittleEndian32(0x43425355); - Cbw->dCBWTag = giMSC_NextTag ++; + Cbw->dCBWTag = giMSC_NextTag ++; Cbw->dCBWDataTransferLength = LittleEndian32(DataLen); Cbw->bmCBWFlags = (bInput ? 0x80 : 0x00); - Cbw->bCBWLUN = 0; // TODO: Logical Unit Number (param from proto) + Cbw->bCBWLUN = 0; // TODO: Logical Unit Number (param from proto) Cbw->bCBWLength = CmdLen; memcpy(Cbw->CBWCB, CmdData, CmdLen); @@ -121,21 +123,24 @@ void MSC_RecvData(tUSBInterface *Dev, size_t CmdLen, const void *CmdData, size_t const int endpoint_out = 2; const int endpoint_in = 1; const int max_packet_size = 64; - + if( MSC_int_CreateCBW(&cbw, 1, CmdLen, CmdData, DataLen) ) return ; // Send CBW + LOG("Send CBW"); USB_SendData(Dev, endpoint_out, sizeof(cbw), &cbw); // Read Data for( size_t ofs = 0; ofs < DataLen; ofs += max_packet_size ) { + LOG("Read bytes 0x%x+0x%x", ofs, MIN(max_packet_size, DataLen - ofs)); // TODO: use async version and wait for the transaction to complete USB_RecvData(Dev, endpoint_in, MIN(max_packet_size, DataLen - ofs), Data + ofs); } // Read CSW + LOG("Read CSW"); USB_RecvData(Dev, endpoint_in, sizeof(csw), &csw); // TODO: Validate CSW } diff --git a/KernelLand/Modules/USB/MSC/msc_proto.h b/KernelLand/Modules/USB/MSC/msc_proto.h index 913822fd..8cbd8524 100644 --- a/KernelLand/Modules/USB/MSC/msc_proto.h +++ b/KernelLand/Modules/USB/MSC/msc_proto.h @@ -20,7 +20,7 @@ struct sMSC_CBW Uint8 bCBWLUN; Uint8 bCBWLength; Uint8 CBWCB[16]; -}; +} PACKED; struct sMSC_CSW { @@ -28,6 +28,6 @@ struct sMSC_CSW Uint32 dCSWTag; Uint32 dCSWDataResidue; Uint8 dCSWStatus; -}; +} PACKED; #endif