VirtualBox

Changeset 43788 in vbox for trunk/src


Ignore:
Timestamp:
Oct 31, 2012 6:30:35 PM (12 years ago)
Author:
vboxsync
Message:

Scraped off some of the bit rot.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/UsbMsd.cpp

    r40282 r43788  
    3939 * @{ */
    4040#define USBMSD_STR_ID_MANUFACTURER  1
    41 #define USBMSD_STR_ID_PRODUCT       2
     41#define USBMSD_STR_ID_PRODUCT_HD    2
    4242/** @} */
    4343
     44/** @name USB MSD vendor and product IDs
     45 * @{ */
     46#define VBOX_USB_VENDOR             0x80EE
     47#define USBMSD_PID_HD               0x0030
     48#define USBMSD_PID_CD               0x0031
     49/** @} */
    4450
    4551/*******************************************************************************
    4652*   Structures and Typedefs                                                    *
    4753*******************************************************************************/
    48 /**
    49  * USB Command block wrapper (MSD/SCSI).
     54
     55/**
     56 * USB MSD Command Block Wrapper or CBW. The command block
     57 * itself (CBWCB) contains protocol-specific data (here SCSI).
    5058 */
    5159#pragma pack(1)
     
    7280
    7381/**
    74  * USB Command Status Wrapper (MSD/SCSI).
     82 * USB MSD Command Status Wrapper or CSW.
    7583 */
    7684#pragma pack(1)
     
    255263static const PDMUSBDESCCACHESTRING g_aUsbMsdStrings_en_US[] =
    256264{
    257     { USBMSD_STR_ID_MANUFACTURER,   "VirtualBox"     },
    258     { USBMSD_STR_ID_PRODUCT,        "VirtualBox MSD" },
     265    { USBMSD_STR_ID_MANUFACTURER,   "VirtualBox"   },
     266    { USBMSD_STR_ID_PRODUCT_HD,     "USB Harddisk" },
    259267};
    260268
     
    272280            /* .bEndpointAddress = */   0x81 /* ep=1, in */,
    273281            /* .bmAttributes = */       2 /* bulk */,
    274             /* .wMaxPacketSize = */     0x200 /* or 64? */,
    275             /* .bInterval = */          0xff,
     282            /* .wMaxPacketSize = */     64,//512 /* or 64? */,  <-- depends on device speed!
     283            /* .bInterval = */          0,
    276284        },
    277285        /* .pvMore = */     NULL,
     
    285293            /* .bEndpointAddress = */   0x02 /* ep=2, out */,
    286294            /* .bmAttributes = */       2 /* bulk */,
    287             /* .wMaxPacketSize = */     0x200 /* or 64? */,
    288             /* .bInterval = */          0xff,
     295            /* .wMaxPacketSize = */     64,//512 /* or 64? */,  <-- depends on device speed!
     296            /* .bInterval = */          0,
    289297        },
    290298        /* .pvMore = */     NULL,
     
    313321};
    314322
    315 static const VUSBINTERFACE g_aUsbMsdInterfaces[2] =
     323static const VUSBINTERFACE g_aUsbMsdInterfaces[] =
    316324{
    317325    { &g_UsbMsdInterfaceDesc, /* .cSettings = */ 1 },
     
    330338        /* .MaxPower = */           50 /* 100mA */
    331339    },
    332     NULL,
    333     &g_aUsbMsdInterfaces[0]
     340    NULL,                           /* pvMore */
     341    &g_aUsbMsdInterfaces[0],
     342    NULL                            /* pvOriginal */
    334343};
    335344
     
    338347    /* .bLength = */                sizeof(g_UsbMsdDeviceDesc),
    339348    /* .bDescriptorType = */        VUSB_DT_DEVICE,
    340     /* .bcdUsb = */                 0x200,
     349    /* .bcdUsb = */                 0x200, /* USB 2.0 */
    341350    /* .bDeviceClass = */           0 /* Class specified in the interface desc. */,
    342351    /* .bDeviceSubClass = */        0 /* Subclass specified in the interface desc. */,
    343     /* .bDeviceProtocol = */        0x50 /* Protocol specified in the interface desc. */,
     352    /* .bDeviceProtocol = */        0 /* Protocol specified in the interface desc. */,
    344353    /* .bMaxPacketSize0 = */        64,
    345     /* .idVendor = */               0x4200,
    346     /* .idProduct = */              0x0042,
    347     /* .bcdDevice = */              0x0100,
     354    /* .idVendor = */               VBOX_USB_VENDOR,
     355    /* .idProduct = */              USBMSD_PID_HD,
     356    /* .bcdDevice = */              0x0100, /* 1.0 */
    348357    /* .iManufacturer = */          USBMSD_STR_ID_MANUFACTURER,
    349     /* .iProduct = */               USBMSD_STR_ID_PRODUCT,
     358    /* .iProduct = */               USBMSD_STR_ID_PRODUCT_HD,
    350359    /* .iSerialNumber = */          0,
    351360    /* .bNumConfigurations = */     1
     361};
     362
     363static const VUSBDEVICEQUALIFIER g_UsbMsdDeviceQualifier =
     364{
     365    /* .bLength = */                sizeof(g_UsbMsdDeviceQualifier),
     366    /* .bDescriptorType = */        VUSB_DT_DEVICE_QUALIFIER,
     367    /* .bcdUsb = */                 0x200, /* USB 2.0 */
     368    /* .bDeviceClass = */           0 /* Class specified in the interface desc. */,
     369    /* .bDeviceSubClass = */        0 /* Subclass specified in the interface desc. */,
     370    /* .bDeviceProtocol = */        0 /* Protocol specified in the interface desc. */,
     371    /* .bMaxPacketSize0 = */        64,
     372    /* .bNumConfigurations = */     1,
     373    /* .bReserved = */              0
    352374};
    353375
     
    636658
    637659    pUrb->enmStatus = VUSBSTATUS_OK;
    638     pUrb->cbData    = cbData;
     660    pUrb->cbData    = (uint32_t)cbData;
    639661
    640662    usbMsdLinkDone(pThis, pUrb);
     
    665687        && pReq->enmState == USBMSDREQSTATE_EXECUTING)
    666688    {
    667         /* Don't try deal with the set config variant nor multiple build-only
     689        /* Don't try to deal with the set config variant nor multiple build-only
    668690           mass storage resets. */
    669691        if (pThis->pResetUrb && (pUrb || fSetConfig))
     
    785807                break;
    786808
    787             /* Process it as the normal way. */
     809            /* Process it the normal way. */
    788810            usbMsdHandleBulkDevToHost(pThis, &pThis->aEps[1], pUrb);
    789811        }
     
    914936    if ((pCbw->bmCBWFlags & USBCBW_DIR_MASK) != USBCBW_DIR_IN)
    915937        return usbMsdScsiIllegalRequest(pThis, pReq, SCSI_ASC_INVALID_MESSAGE, 0, "direction");
    916     if (pCbw->bCBWCBLength != 6)
     938    if (pCbw->bCBWCBLength < 6)
    917939        return usbMsdScsiIllegalRequest(pThis, pReq, SCSI_ASC_INVALID_MESSAGE, 0, "length");
    918940    if ((pCbw->CBWCB[1] >> 5) != pCbw->bCBWLun)
     
    920942    if (pCbw->bCBWLun != 0)
    921943        return usbMsdScsiIllegalRequest(pThis, pReq, SCSI_ASC_INVALID_MESSAGE, 0, "lun0");
    922     if ((pCbw->CBWCB[4] < 6) != pCbw->bCBWLun)
     944    if (pCbw->CBWCB[4] < 6)
    923945        return usbMsdScsiIllegalRequest(pThis, pReq, SCSI_ASC_INV_FIELD_IN_CMD_PACKET, 0, "out length");
    924946
     
    10011023
    10021024/**
    1003  * Handles request sent to the out-bound (to device) bulk pipe.
     1025 * Handle requests sent to the outbound (to device) bulk pipe.
    10041026 */
    10051027static int usbMsdHandleBulkHostToDev(PUSBMSD pThis, PUSBMSDEP pEp, PVUSBURB pUrb)
     
    10351057                return usbMsdCompleteStall(pThis, NULL, pUrb, "BAD CBW");
    10361058            }
    1037             Log(("usbMsd: CBW: dCBWSignature=%#x dCBWTag=%#x dCBWDataTransferLength=%#x bmCBWFlags=%#x bCBWLun=%#x bCBWCBLength=%#x  cbData=%#x fShortNotOk=%RTbool\n",
    1038                  pCbw->dCBWSignature, pCbw->dCBWTag, pCbw->dCBWDataTransferLength, pCbw->bmCBWFlags, pCbw->bCBWLun, pCbw->bCBWCBLength, pUrb->cbData, pUrb->fShortNotOk));
    10391059            if (pCbw->dCBWSignature != USBCBW_SIGNATURE)
    10401060            {
     
    10421062                return usbMsdCompleteStall(pThis, NULL, pUrb, "Bad CBW");
    10431063            }
     1064            Log(("usbMsd: CBW: dCBWTag=%#x dCBWDataTransferLength=%#x bmCBWFlags=%#x bCBWLun=%#x bCBWCBLength=%#x  cbData=%#x fShortNotOk=%RTbool\n",
     1065                 pCbw->dCBWTag, pCbw->dCBWDataTransferLength, pCbw->bmCBWFlags, pCbw->bCBWLun, pCbw->bCBWCBLength, pUrb->cbData, pUrb->fShortNotOk));
    10441066            if (pCbw->bmCBWFlags & ~USBCBW_DIR_MASK)
    10451067            {
     
    11491171                }
    11501172            }
    1151             return usbMsdCompleteOk(pThis, pUrb, 0);
     1173            return usbMsdCompleteOk(pThis, pUrb, cbData);
    11521174        }
    11531175
     
    11691191
    11701192/**
    1171  * Handles request sent to the in-bound (to host) bulk pipe.
     1193 * Handle requests sent to the inbound (to host) bulk pipe.
    11721194 */
    11731195static int usbMsdHandleBulkDevToHost(PUSBMSD pThis, PUSBMSDEP pEp, PVUSBURB pUrb)
     
    12171239        case USBMSDREQSTATE_STATUS:
    12181240        {
    1219             /** @todo !fShortNotOk and CSW request? */
    1220             if (pUrb->cbData != sizeof(USBCSW))
    1221             {
    1222                 Log(("usbMsd: Unexpected status request size: %#x (expected %#x)\n", pUrb->cbData, sizeof(USBCSW)));
     1241            if ((pUrb->cbData < sizeof(USBCSW)) || (pUrb->cbData > sizeof(USBCSW) && pUrb->fShortNotOk))
     1242            {
     1243                Log(("usbMsd: Unexpected status request size: %#x (expected %#x), fShortNotOK=%RTbool\n", pUrb->cbData, sizeof(USBCSW), pUrb->fShortNotOk));
    12231244                return usbMsdCompleteStall(pThis, NULL, pUrb, "Invalid CSW size");
    12241245            }
     
    12331254                                ? USBCSW_STATUS_FAILED
    12341255                                : USBCSW_STATUS_PHASE_ERROR;
     1256            /** @todo the following is not always accurate; VSCSI needs
     1257             *        to implement residual counts properly! */
    12351258            if ((pReq->Cbw.bmCBWFlags & USBCBW_DIR_MASK) == USBCBW_DIR_OUT)
    12361259                pCsw->dCSWDataResidue = pCsw->bCSWStatus == USBCSW_STATUS_OK
     
    12391262            else
    12401263                pCsw->dCSWDataResidue = pCsw->bCSWStatus == USBCSW_STATUS_OK
    1241                                       ? pReq->ScsiReq.cbScatterGather
    1242                                       : 0;
    1243             Log(("usbMsdHandleBulkDevToHost: CSW: dCSWTag=%#x bCSWStatus=%d dCSWDataResidue=%#x\n",
     1264                                      ? 0
     1265                                      : pReq->ScsiReq.cbScatterGather;
     1266            Log(("usbMsd: CSW: dCSWTag=%#x bCSWStatus=%d dCSWDataResidue=%#x\n",
    12441267                 pCsw->dCSWTag, pCsw->bCSWStatus, pCsw->dCSWDataResidue));
    12451268
     
    13341357                switch (pSetup->wValue >> 8)
    13351358                {
     1359                    uint32_t    cbCopy;
     1360
    13361361                    case VUSB_DT_STRING:
    13371362                        Log(("usbMsd: GET_DESCRIPTOR DT_STRING wValue=%#x wIndex=%#x\n", pSetup->wValue, pSetup->wIndex));
    13381363                        break;
     1364                    case VUSB_DT_DEVICE_QUALIFIER:
     1365                        Log(("usbMsd: GET_DESCRIPTOR DT_DEVICE_QUALIFIER wValue=%#x wIndex=%#x\n", pSetup->wValue, pSetup->wIndex));
     1366                        /* Returned data is written after the setup message. */
     1367                        cbCopy = pUrb->cbData - sizeof(*pSetup);
     1368                        cbCopy = RT_MIN(cbCopy, sizeof(g_UsbMsdDeviceQualifier));
     1369                        memcpy(&pUrb->abData[sizeof(*pSetup)], &g_UsbMsdDeviceQualifier, cbCopy);
     1370                        return usbMsdCompleteOk(pThis, pUrb, cbCopy + sizeof(*pSetup));
    13391371                    default:
    13401372                        Log(("usbMsd: GET_DESCRIPTOR, huh? wValue=%#x wIndex=%#x\n", pSetup->wValue, pSetup->wIndex));
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette