UsbKbd.cpp revision 867d5db4d336a197f5166d37f8ff8a38c63d1c2b
af062818b47340eef15700d2f0211576ba3506eevboxsync * UsbKbd - USB Human Interface Device Emulation, Keyboard.
af062818b47340eef15700d2f0211576ba3506eevboxsync * Copyright (C) 2007-2010 Oracle Corporation
af062818b47340eef15700d2f0211576ba3506eevboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
af062818b47340eef15700d2f0211576ba3506eevboxsync * available from http://www.virtualbox.org. This file is free software;
af062818b47340eef15700d2f0211576ba3506eevboxsync * you can redistribute it and/or modify it under the terms of the GNU
af062818b47340eef15700d2f0211576ba3506eevboxsync * General Public License (GPL) as published by the Free Software
af062818b47340eef15700d2f0211576ba3506eevboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
af062818b47340eef15700d2f0211576ba3506eevboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
af062818b47340eef15700d2f0211576ba3506eevboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
af062818b47340eef15700d2f0211576ba3506eevboxsync/*******************************************************************************
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync* Header Files *
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync*******************************************************************************/
af062818b47340eef15700d2f0211576ba3506eevboxsync/*******************************************************************************
af062818b47340eef15700d2f0211576ba3506eevboxsync* Defined Constants And Macros *
af062818b47340eef15700d2f0211576ba3506eevboxsync*******************************************************************************/
af062818b47340eef15700d2f0211576ba3506eevboxsync/** @name USB HID string IDs
af062818b47340eef15700d2f0211576ba3506eevboxsync/** @name USB HID specific descriptor types
af062818b47340eef15700d2f0211576ba3506eevboxsync/** @name USB HID vendor and product IDs
af062818b47340eef15700d2f0211576ba3506eevboxsync/** @name USB HID class specific requests
af062818b47340eef15700d2f0211576ba3506eevboxsync/*******************************************************************************
af062818b47340eef15700d2f0211576ba3506eevboxsync* Structures and Typedefs *
af062818b47340eef15700d2f0211576ba3506eevboxsync*******************************************************************************/
af062818b47340eef15700d2f0211576ba3506eevboxsync * The USB HID request state.
typedef struct USBHIDEP
bool fHalted;
} USBHIDEP;
typedef struct USBHIDURBQUEUE
typedef struct USBHIDK_REPORT
} scan_state_t;
typedef struct USBHID
bool fHaveDoneQueueWaiter;
bool fNoUrbSinceLastPress;
bool fHasPendingChanges;
} Lun0;
} USBHID;
NULL,
switch (state) {
case SS_IDLE:
case SS_EXT:
case SS_EXT1:
*pUsage = 0;
return state;
if (pUrb)
if (!pNext)
return pUrb;
while (pCur)
if (!pCur)
Log(("usbHidCompleteStall/#%u: pUrb=%p:%s: %s\n", pThis->pUsbIns->iInstance, pUrb, pUrb->pszDesc, pszWhy));
if (pEp)
return VINF_SUCCESS;
Log(("usbHidCompleteOk/#%u: pUrb=%p:%s cbData=%#zx\n", pThis->pUsbIns->iInstance, pUrb, pUrb->pszDesc, cbData));
return VINF_SUCCESS;
if (pUrb)
return VINF_SUCCESS;
#ifdef DEBUG
unsigned offBuf = 0;
if (uCode != 0)
if (pUrb)
#ifdef DEBUG
#ifdef DEBUG
// LogRel(("Sent report: %x : %x %x, size %d\n", pReport->ShiftState, pReport->aKeys[0], pReport->aKeys[1], cbCopy));
return VINF_EOF;
return NULL;
int fKeyDown;
bool fHaveEvent = true;
if (fKeyDown)
fHaveEvent = false;
if (fHaveEvent)
if (fHaveEvent)
return VINF_SUCCESS;
if (pUrb)
return pUrb;
return VINF_SUCCESS;
AssertFailed();
case USBHIDREQSTATE_STATUS:
AssertFailed();
case USBHIDREQSTATE_READY:
return VINF_SUCCESS;
case VUSB_REQ_GET_DESCRIPTOR:
case VUSB_DT_STRING:
case DT_IF_HID_REPORT:
Log(("usbHid: GET_DESCRIPTOR DT_IF_HID_REPORT wValue=%#x wIndex=%#x cbCopy=%#x\n", pSetup->wValue, pSetup->wIndex, cbCopy));
case VUSB_REQ_GET_STATUS:
case VUSB_REQ_CLEAR_FEATURE:
Log(("usbHid: Implement standard request: bmRequestType=%#x bRequest=%#x wValue=%#x wIndex=%#x wLength=%#x\n",
case HID_REQ_SET_IDLE:
case HID_REQ_GET_IDLE:
Log(("usbHid: GET_IDLE wValue=%#x wIndex=%#x, returning %#x\n", pSetup->wValue, pSetup->wIndex, pThis->bIdle));
Log(("usbHid: Unimplemented class request: bmRequestType=%#x bRequest=%#x wValue=%#x wIndex=%#x wLength=%#x\n",
Log(("usbHid: Unknown control msg: bmRequestType=%#x bRequest=%#x wValue=%#x wIndex=%#x wLength=%#x\n",
return VINF_SUCCESS;
LogFlow(("usbHidQueue/#%u: pUrb=%p:%s EndPt=%#x\n", pUsbIns->iInstance, pUrb, pUrb->pszDesc, pUrb->EndPt));
int rc;
AssertFailed();
return rc;
return VINF_SUCCESS;
static DECLCALLBACK(int) usbHidUsbSetInterface(PPDMUSBINS pUsbIns, uint8_t bInterfaceNumber, uint8_t bAlternateSetting)
LogFlow(("usbHidUsbSetInterface/#%u: bInterfaceNumber=%u bAlternateSetting=%u\n", pUsbIns->iInstance, bInterfaceNumber, bAlternateSetting));
return VINF_SUCCESS;
LogFlow(("usbHidUsbSetConfiguration/#%u: bConfigurationValue=%u\n", pUsbIns->iInstance, bConfigurationValue));
return VINF_SUCCESS;
return &g_UsbHidDescCache;
return rc;
static DECLCALLBACK(int) usbHidConstruct(PPDMUSBINS pUsbIns, int iInstance, PCFGMNODE pCfg, PCFGMNODE pCfgGlobal)
return rc;
rc = pUsbIns->pHlpR3->pfnDriverAttach(pUsbIns, 0 /*iLun*/, &pThis->Lun0.IBase, &pThis->Lun0.pDrvBase, "Keyboard Port");
return PDMUsbHlpVMSetError(pUsbIns, VERR_PDM_MISSING_INTERFACE, RT_SRC_POS, N_("HID failed to query keyboard interface"));
return VINF_SUCCESS;
sizeof(USBHID),
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,