int usbhidGetReport(usbDevice_t *device, int reportNumber, char *buffer, int *len) { BOOLEAN rval = 0; buffer[0] = reportNumber; rval = HidD_GetFeature((HANDLE)device, buffer, *len); return rval == 0 ? USBOPEN_ERR_IO : 0; }
int usbhidGetReport(usbDevice_t* device, int reportNumber, char* buffer, int* len) { buffer[0] = reportNumber; BOOLEAN rval = HidD_GetFeature((HANDLE)device, buffer, *len); if (rval == FALSE) log_str("--- HidD_GetFeature(); GetLastError() == " + GetErrorString(GetLastError()) + "\n"); return rval == 0 ? USBOPEN_ERR_IO : USBOPEN_SUCCESS; }
bool WHTDongle::ReadProtocolVersion(protocol_version_e& dongle_ver, protocol_version_e& tracker_ver) { FeatRep_ProtocolVersion protVer; protVer.report_id = PROT_VER_REPORT_ID; if (HidD_GetFeature(hDevice, &protVer, sizeof(protVer)) != TRUE) return false; dongle_ver = (protocol_version_e) protVer.dongle_ver; tracker_ver = (protocol_version_e) protVer.tracker_ver; return true; }
SG15LightStatus CLCDConnectionLogitech::GetLightStatus() { SG15LightStatus status; status.bMKey[0] = false; status.bMKey[1] = false; status.bMKey[2] = false; status.bMRKey = false; status.eKBDBrightness = KBD_OFF; status.eLCDBrightness = LCD_OFF; if (GetConnectionState() != CONNECTED || m_pConnectedDevice->GetIndex() != LGLCD_DEVICE_BW) //m_lcdDeviceDesc.deviceFamilyId != LGLCD_DEVICE_FAMILY_KEYBOARD_G15) return status; byte *data = new byte[m_HIDCapabilities.FeatureReportByteLength]; data[0] = 0x02; data[1] = 0x02; data[2] = 0x00; data[3] = 0x00; HidD_GetFeature(m_hHIDDeviceHandle, data, m_HIDCapabilities.FeatureReportByteLength); // data[1] = Keys status.eKBDBrightness = (EKBDBrightness)data[1]; // data[2] = LCD switch (data[2]) { case 0x02: status.eLCDBrightness = LCD_ON; break; case 0x01: status.eLCDBrightness = LCD_MEDIUM; break; default: status.eLCDBrightness = LCD_OFF; break; } // MKeys status.bMKey[0] = !(data[3] & G15_M1_LIGHT); status.bMKey[1] = !(data[3] & G15_M2_LIGHT); status.bMKey[2] = !(data[3] & G15_M3_LIGHT); // MRKey status.bMRKey = !(data[3] & G15_MR_LIGHT); delete[] data; return status; }
int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *dev, unsigned char *data, size_t length) { BOOL res; #if 0 res = HidD_GetFeature(dev->device_handle, data, length); if (!res) { register_error(dev, "HidD_GetFeature"); return -1; } return 0; /* HidD_GetFeature() doesn't give us an actual length, unfortunately */ #else DWORD bytes_returned; OVERLAPPED ol; memset(&ol, 0, sizeof(ol)); res = DeviceIoControl(dev->device_handle, IOCTL_HID_GET_FEATURE, data, length, data, length, &bytes_returned, &ol); if (!res) { if (GetLastError() != ERROR_IO_PENDING) { /* DeviceIoControl() failed. Return error. */ register_error(dev, "Send Feature Report DeviceIoControl"); return -1; } } /* Wait here until the write is done. This makes hid_get_feature_report() synchronous. */ res = GetOverlappedResult(dev->device_handle, &ol, &bytes_returned, TRUE/*wait*/); if (!res) { /* The operation failed. */ register_error(dev, "Send Feature Report GetOverLappedResult"); return -1; } /* bytes_returned does not include the first byte which contains the report ID. The data buffer actually contains one more byte than bytes_returned. */ bytes_returned++; return bytes_returned; #endif }
int _ykusb_read(void *dev, int report_type, int report_number, char *buffer, int buffer_size) { HANDLE h = dev; BYTE buf[FEATURE_BUF_SIZE]; if (buffer_size != EXPECT_SIZE) { yk_errno = YK_EUSBERR; return 0; } memset(buf, 0, sizeof(buf)); if (!HidD_GetFeature(h, buf, sizeof (buf))) { yk_errno = YK_EUSBERR; return 0; } memcpy (buffer, buf + 1, buffer_size); return buffer_size; }
int usbGetReport(usbDevice_t *device, int reportType, int reportNumber, char *buffer, int *len) { HANDLE handle = (HANDLE)device; BOOLEAN rval = 0; DWORD bytesRead; switch(reportType){ case USB_HID_REPORT_TYPE_INPUT: buffer[0] = reportNumber; rval = ReadFile(handle, buffer, *len, &bytesRead, NULL); if(rval) *len = bytesRead; break; case USB_HID_REPORT_TYPE_OUTPUT: break; case USB_HID_REPORT_TYPE_FEATURE: buffer[0] = reportNumber; rval = HidD_GetFeature(handle, buffer, *len); break; } return rval == 0 ? USB_ERROR_IO : 0; }
static const blissbox_pad_type_t* input_autoconfigure_get_blissbox_pad_type_win32(int vid, int pid) { /* TODO: Remove the check for !defined(_MSC_VER) after making sure this builds on MSVC */ /* HID API is available since Windows 2000 */ #if defined(_WIN32) && !defined(_XBOX) && !defined(_MSC_VER) && _WIN32_WINNT >= 0x0500 HDEVINFO hDeviceInfo; SP_DEVINFO_DATA DeviceInfoData; SP_DEVICE_INTERFACE_DATA deviceInterfaceData; HANDLE hDeviceHandle = INVALID_HANDLE_VALUE; BOOL bResult = TRUE; BOOL success = FALSE; GUID guidDeviceInterface = {0}; PSP_DEVICE_INTERFACE_DETAIL_DATA pInterfaceDetailData = NULL; ULONG requiredLength = 0; LPTSTR lpDevicePath = NULL; char *devicePath = NULL; DWORD index = 0; DWORD intIndex = 0; size_t nLength = 0; unsigned len = 0; unsigned i = 0; char vidPidString[32] = {0}; char vidString[5] = {0}; char pidString[5] = {0}; char report[USB_PACKET_CTRL_LEN + 1] = {0}; snprintf(vidString, sizeof(vidString), "%04x", vid); snprintf(pidString, sizeof(pidString), "%04x", pid); strlcat(vidPidString, "vid_", sizeof(vidPidString)); strlcat(vidPidString, vidString, sizeof(vidPidString)); strlcat(vidPidString, "&pid_", sizeof(vidPidString)); strlcat(vidPidString, pidString, sizeof(vidPidString)); HidD_GetHidGuid(&guidDeviceInterface); if (!memcmp(&guidDeviceInterface, &GUID_NULL, sizeof(GUID_NULL))) { RARCH_ERR("[Autoconf]: null guid\n"); return NULL; } /* Get information about all the installed devices for the specified * device interface class. */ hDeviceInfo = SetupDiGetClassDevs( &guidDeviceInterface, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); if (hDeviceInfo == INVALID_HANDLE_VALUE) { RARCH_ERR("[Autoconf]: Error in SetupDiGetClassDevs: %d.\n", GetLastError()); goto done; } /* Enumerate all the device interfaces in the device information set. */ DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA); while (!success) { success = SetupDiEnumDeviceInfo(hDeviceInfo, index, &DeviceInfoData); /* Reset for this iteration */ if (lpDevicePath) { LocalFree(lpDevicePath); lpDevicePath = NULL; } if (pInterfaceDetailData) { LocalFree(pInterfaceDetailData); pInterfaceDetailData = NULL; } /* Check if this is the last item */ if (GetLastError() == ERROR_NO_MORE_ITEMS) break; deviceInterfaceData.cbSize = sizeof(SP_INTERFACE_DEVICE_DATA); /* Get information about the device interface. */ for (intIndex = 0; (bResult = SetupDiEnumDeviceInterfaces( hDeviceInfo, &DeviceInfoData, &guidDeviceInterface, intIndex, &deviceInterfaceData)); intIndex++) { /* Check if this is the last item */ if (GetLastError() == ERROR_NO_MORE_ITEMS) break; /* Check for some other error */ if (!bResult) { RARCH_ERR("[Autoconf]: Error in SetupDiEnumDeviceInterfaces: %d.\n", GetLastError()); goto done; } /* Interface data is returned in SP_DEVICE_INTERFACE_DETAIL_DATA * which we need to allocate, so we have to call this function twice. * First to get the size so that we know how much to allocate, and * second to do the actual call with the allocated buffer. */ bResult = SetupDiGetDeviceInterfaceDetail( hDeviceInfo, &deviceInterfaceData, NULL, 0, &requiredLength, NULL); /* Check for some other error */ if (!bResult) { if ((ERROR_INSUFFICIENT_BUFFER == GetLastError()) && (requiredLength > 0)) { /* we got the size, now allocate buffer */ pInterfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc(LPTR, requiredLength); if (!pInterfaceDetailData) { RARCH_ERR("[Autoconf]: Error allocating memory for the device detail buffer.\n"); goto done; } } else { RARCH_ERR("[Autoconf]: Other error: %d.\n", GetLastError()); goto done; } } /* get the interface detailed data */ pInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); /* Now call it with the correct size and allocated buffer */ bResult = SetupDiGetDeviceInterfaceDetail( hDeviceInfo, &deviceInterfaceData, pInterfaceDetailData, requiredLength, NULL, &DeviceInfoData); /* Check for some other error */ if (!bResult) { RARCH_LOG("[Autoconf]: Error in SetupDiGetDeviceInterfaceDetail: %d.\n", GetLastError()); goto done; } /* copy device path */ nLength = _tcslen(pInterfaceDetailData->DevicePath) + 1; lpDevicePath = (TCHAR*)LocalAlloc(LPTR, nLength * sizeof(TCHAR)); StringCchCopy(lpDevicePath, nLength, pInterfaceDetailData->DevicePath); devicePath = (char*)malloc(nLength); for (len = 0; len < nLength; len++) devicePath[len] = lpDevicePath[len]; lpDevicePath[nLength - 1] = 0; if (strstr(devicePath, vidPidString)) goto found; } success = FALSE; index++; } if (!lpDevicePath) { RARCH_ERR("[Autoconf]: No devicepath. Error %d.", GetLastError()); goto done; } found: /* Open the device */ hDeviceHandle = CreateFileA( devicePath, GENERIC_READ, /* | GENERIC_WRITE,*/ FILE_SHARE_READ, /* | FILE_SHARE_WRITE,*/ NULL, OPEN_EXISTING, 0, /*FILE_FLAG_OVERLAPPED,*/ NULL); if (hDeviceHandle == INVALID_HANDLE_VALUE) { /* Windows sometimes erroneously fails to open with a sharing violation: * https://github.com/signal11/hidapi/issues/231 * If this happens, trying again with read + write usually works for some reason. */ /* Open the device */ hDeviceHandle = CreateFileA( devicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, /*FILE_FLAG_OVERLAPPED,*/ NULL); if (hDeviceHandle == INVALID_HANDLE_VALUE) { RARCH_ERR("[Autoconf]: Can't open device for reading and writing: %d.", GetLastError()); runloop_msg_queue_push("Bliss-Box already in use. Please make sure other programs are not using it.", 2, 300, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); goto done; } } done: free(devicePath); LocalFree(lpDevicePath); LocalFree(pInterfaceDetailData); bResult = SetupDiDestroyDeviceInfoList(hDeviceInfo); devicePath = NULL; lpDevicePath = NULL; pInterfaceDetailData = NULL; if (!bResult) RARCH_ERR("[Autoconf]: Could not destroy device info list.\n"); if (!hDeviceHandle || hDeviceHandle == INVALID_HANDLE_VALUE) { /* device is not connected */ return NULL; } report[0] = BLISSBOX_USB_FEATURE_REPORT_ID; HidD_GetFeature(hDeviceHandle, report, sizeof(report)); CloseHandle(hDeviceHandle); for (i = 0; i < sizeof(blissbox_pad_types) / sizeof(blissbox_pad_types[0]); i++) { const blissbox_pad_type_t *pad = &blissbox_pad_types[i]; if (!pad || string_is_empty(pad->name)) continue; if (pad->index == report[0]) return pad; } RARCH_LOG("[Autoconf]: Could not find connected pad in Bliss-Box port#%d.\n", pid - BLISSBOX_PID); #endif return NULL; }
BOOLEAN Hid::GetFeature(HANDLE HidDeviceObject, void *ReportBuffer, ULONG ReportBufferLength) { return HidD_GetFeature(HidDeviceObject, ReportBuffer, ReportBufferLength); }
/*! Send and Receive data over USB * @param device * @param command to send to the device * @param array of data to send * @param length of data to send * @param buffer to hold response * @param lengh of data expected */ int SendData(usbDevice_t *dev, uchar command, uchar * dataToSend, int length, uchar * outBuffer, int outBufferLength) { if (dev==NULL) return -1; // Error, device not opened ReportOut_t reportOut; ReportIn_t reportIn; reportOut.reportSize = length; reportOut.command = command; if (reportOut.reportSize <= 6) { reportOut.reportID = 1; } else if (reportOut.reportSize <= 14) { reportOut.reportID = 2; } else if (reportOut.reportSize <=248) { reportOut.reportID = 3; } else { return -1; // Error, size too great for a single transmission } if (outBufferLength > 250) { return -1; } // Copy the data to the transmit buffer int i; for (i=0; i<reportOut.reportSize; i++) { reportOut.data[i] = dataToSend[i]; } // Send out the data if (!HidD_SetFeature(dev, (void*)&reportOut, sizeof(ReportOut_t))) { return -1; // Error: Couldn't transmit data } // Receive the data if (outBufferLength <= 7) { reportIn.reportID = 1; // Up to 7 bytes of data to receive, plus 1 size byte } else if (outBufferLength <= 15) { reportIn.reportID = 2; } else if (outBufferLength <=249) { reportIn.reportID = 3; } if (!HidD_GetFeature(dev, (void*)&reportIn, sizeof(ReportIn_t))) { return -1; // Error: Couldn't retrieve data } if (outBuffer!=NULL) { for (i=0; i<reportIn.reportSize; i++) { outBuffer[i] = reportIn.data[i]; } } return reportIn.reportSize; // Return the number of bytes received }
void WHTDongle::GetFeatureReportRaw(void* buffer, int report_size) { if (HidD_GetFeature(hDevice, buffer, report_size) != TRUE) ThrowException(L"HidD_GetFeature", ((uint8_t*) buffer)[0]); }
BOOLEAN GetFeature ( PHID_DEVICE HidDevice ) /*++ RoutineDescription: Given a struct _HID_DEVICE, fill in the feature data structures with all features on the device. May issue multiple HidD_GetFeature() calls to deal with multiple report IDs. --*/ { ULONG Index; PHID_DATA pData; BOOLEAN FeatureStatus; BOOLEAN Status; /* // As with writing data, the IsDataSet value in all the structures should be // set to FALSE to indicate that the value has yet to have been set */ pData = HidDevice -> FeatureData; for (Index = 0; Index < HidDevice -> FeatureDataLength; Index++, pData++) { pData -> IsDataSet = FALSE; } /* // Next, each structure in the HID_DATA buffer is filled in with a value // that is retrieved from one or more calls to HidD_GetFeature. The // number of calls is equal to the number of reportIDs on the device */ Status = TRUE; pData = HidDevice -> FeatureData; for (Index = 0; Index < HidDevice -> FeatureDataLength; Index++, pData++) { /* // If a value has yet to have been set for this structure, build a report // buffer with its report ID as the first byte of the buffer and pass // it in the HidD_GetFeature call. Specifying the report ID in the // first specifies which report is actually retrieved from the device. // The rest of the buffer should be zeroed before the call */ if (!pData -> IsDataSet) { memset(HidDevice -> FeatureReportBuffer, 0x00, HidDevice->Caps.FeatureReportByteLength); HidDevice -> FeatureReportBuffer[0] = (UCHAR) pData -> ReportID; FeatureStatus = HidD_GetFeature (HidDevice->HidDevice, HidDevice->FeatureReportBuffer, HidDevice->Caps.FeatureReportByteLength); /* // If the return value is TRUE, scan through the rest of the HID_DATA // structures and fill whatever values we can from this report */ if (FeatureStatus) { FeatureStatus = UnpackReport ( HidDevice->FeatureReportBuffer, HidDevice->Caps.FeatureReportByteLength, HidP_Feature, HidDevice->FeatureData, HidDevice->FeatureDataLength, HidDevice->Ppd); } Status = Status && FeatureStatus; } } return (Status); }
//------------------------------------------------------------------------------ bool DNAUSB::HID_GetFeature( DNADEVICE device, unsigned char* buf, unsigned int len ) { return HidD_GetFeature( device, buf, len ) ? true : false; }