USBHIDDLL_API int __stdcall USBHIDWriteByte(USBHANDLE handle, BYTE* byte, int len) { DWORD numberOfBytesWriten =0; int errorno; if (handle != INVALID_HANDLE_VALUE) { CancelIo(handle); if( GlobalType == T_Feature ) { HidD_SetFeature (handle, byte, len); } else { WriteFile (handle, byte, len, &numberOfBytesWriten, &HIDOverlapped); if (GetLastError() == ERROR_IO_PENDING) { WaitForSingleObject(handle, INFINITE); GetOverlappedResult(handle, &HIDOverlapped, &numberOfBytesWriten, FALSE); errorno = GetLastError(); } } } return numberOfBytesWriten; }
void CLCDConnectionLogitech::SetMKeyLight(bool bM1, bool bM2, bool bM3, bool bMR) { if (GetConnectionState() != CONNECTED || m_pConnectedDevice->GetIndex() != LGLCD_DEVICE_BW) //m_lcdDeviceDesc.deviceFamilyId != LGLCD_DEVICE_FAMILY_KEYBOARD_G15) return; byte *data = new byte[m_HIDCapabilities.FeatureReportByteLength]; data[0] = 0x02; data[1] = 0x04; data[2] = 0x00; if (!bM1) data[2] |= G15_M1_LIGHT; if (!bM2) data[2] |= G15_M2_LIGHT; if (!bM3) data[2] |= G15_M3_LIGHT; if (!bMR) data[2] |= G15_MR_LIGHT; data[3] = 0x00; HidD_SetFeature(m_hHIDDeviceHandle, data, m_HIDCapabilities.FeatureReportByteLength); delete[] data; }
int usbhidSetReport(usbDevice_t *device, char *buffer, int len) { BOOLEAN rval; rval = HidD_SetFeature((HANDLE)device, buffer, len); return rval == 0 ? USBOPEN_ERR_IO : 0; }
int usbhidSetReport(usbDevice_t* device, char* buffer, int len) { BOOLEAN rval = HidD_SetFeature((HANDLE)device, buffer, len); if (rval == FALSE) log_str("--- HidD_SetFeature(); GetLastError() == " + GetErrorString(GetLastError()) + "\n"); return rval == 0 ? USBOPEN_ERR_IO : USBOPEN_SUCCESS; }
int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *dev, const unsigned char *data, size_t length) { BOOL res = HidD_SetFeature(dev->device_handle, (PVOID)data, length); if (!res) { register_error(dev, "HidD_SetFeature"); return -1; } return length; }
void SendReceiveData::restoreFeatures() { device.FeatureReportBuffer[0] = 6; device.FeatureReportBuffer[1] = (CHAR)0xFF; //to shut the compiler up device.FeatureReportBuffer[2] = 0x40; device.FeatureReportBuffer[3] = 0; device.FeatureReportBuffer[4] = 0; HidD_SetFeature (device.HidDevice, device.FeatureReportBuffer, device.Caps.FeatureReportByteLength); }
BOOL SendReceiveData::setFeatures() { device.FeatureReportBuffer[0] = 6; device.FeatureReportBuffer[1] = (CHAR)0xFF; //to shut the compiler up device.FeatureReportBuffer[2] = (CHAR)settings.getSettings(); device.FeatureReportBuffer[3] = 0; device.FeatureReportBuffer[4] = 0; return HidD_SetFeature (device.HidDevice, device.FeatureReportBuffer, device.Caps.FeatureReportByteLength); }
ssize_t hs_hid_send_feature_report(hs_handle *h, const uint8_t *buf, size_t size) { assert(h); assert(h->dev->type == HS_DEVICE_TYPE_HID); assert(buf); if (size < 2) return 0; // Timeout behavior? BOOL success = HidD_SetFeature(h->handle, (char *)buf, (DWORD)size); if (!success) return hs_error(HS_ERROR_IO, "I/O error while writing to '%s'", h->dev->path); return (ssize_t)size; }
void CLCDConnectionLogitech::SetKBDBacklight(EKBDBrightness eBrightness) { if (GetConnectionState() != CONNECTED || m_pConnectedDevice->GetIndex() != LGLCD_DEVICE_BW) //m_lcdDeviceDesc.deviceFamilyId != LGLCD_DEVICE_FAMILY_KEYBOARD_G15) return; byte *data = new byte[m_HIDCapabilities.FeatureReportByteLength]; data[0] = 0x02; data[1] = 0x01; data[2] = eBrightness; data[3] = 0x00; HidD_SetFeature(m_hHIDDeviceHandle, data, m_HIDCapabilities.FeatureReportByteLength); delete[] data; }
static int usbSetReport(union filedescriptor *fdp, int reportType, char *buffer, int len) { HANDLE handle = (HANDLE)fdp->pfd; BOOLEAN rval = 0; DWORD bytesWritten; switch(reportType){ case USB_HID_REPORT_TYPE_INPUT: break; case USB_HID_REPORT_TYPE_OUTPUT: rval = WriteFile(handle, buffer, len, &bytesWritten, NULL); break; case USB_HID_REPORT_TYPE_FEATURE: rval = HidD_SetFeature(handle, buffer, len); break; } return rval == 0 ? USB_ERROR_IO : 0; }
int usbSetReport(usbDevice_t *device, int reportType, char *buffer, int len) { HANDLE handle = (HANDLE)device; BOOLEAN rval = 0; DWORD bytesWritten; switch(reportType){ case USB_HID_REPORT_TYPE_INPUT: break; case USB_HID_REPORT_TYPE_OUTPUT: rval = WriteFile(handle, buffer, len, &bytesWritten, NULL); break; case USB_HID_REPORT_TYPE_FEATURE: rval = HidD_SetFeature(handle, buffer, len); break; } return rval == 0 ? USB_ERROR_IO : 0; }
BOOLEAN SwitchCSR(__in LPTSTR lpDongleName, __in HANDLE hHidDevice, __in BOOL toHID) { PHIDP_PREPARSED_DATA PreparsedData; if (!HidD_GetPreparsedData(hHidDevice, &PreparsedData)) { LbtReportFunctionError(TEXT("HidD_GetPreparsedData")); return FALSE; } HIDP_CAPS HidCaps; if (!HidP_GetCaps(PreparsedData, &HidCaps)) { LbtReportFunctionError(TEXT("HidP_GetCaps")); HidD_FreePreparsedData(PreparsedData); return FALSE; } if (HidCaps.UsagePage != 0xFF00 || HidCaps.Usage != 0x0001) { // HidD_FreePreparsedData(PreparsedData); // return FALSE; } if (HidCaps.FeatureReportByteLength != sizeof(ToHCICSRReports)) { // HidD_FreePreparsedData(PreparsedData); // return FALSE; } CHAR ReportBuffer[sizeof(ToHCICSRReports)]; RtlCopyMemory(ReportBuffer, ToHCICSRReports, sizeof(ToHCICSRReports)); if (!HidD_SetFeature(hHidDevice, ReportBuffer, HidCaps.FeatureReportByteLength)) { LbtReportFunctionError(TEXT("HidD_SetOutputReport")); HidD_FreePreparsedData(PreparsedData); return FALSE; } HidD_FreePreparsedData(PreparsedData); LbtReportDongleSwitch(lpDongleName, toHID); return TRUE; }
int _ykusb_write(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; } buf[0] = 0; memcpy (buf + 1, buffer, buffer_size); if (!HidD_SetFeature(h, buf, sizeof (buf))) { yk_errno = YK_EUSBERR; return 0; } return 1; }
//------------------------------------------------------------------------------ bool DNAUSB::HID_SetFeature( DNADEVICE device, unsigned char* buf, unsigned int len ) { return (HidD_SetFeature(device, buf, len) ? true : false) || GetLastError() == 31; }
BOOLEAN SetFeature ( PHID_DEVICE HidDevice ) /*++ RoutineDescription: Given a struct _HID_DEVICE, take the information in the HID_DATA array pack it into multiple reports and send it to the hid device via HidD_SetFeature() --*/ { PHID_DATA pData; ULONG Index; BOOLEAN Status; BOOLEAN FeatureStatus; /* // Begin by looping through the HID_DEVICE's HID_DATA structure and setting // the IsDataSet field to FALSE to indicate that each structure has // not yet been set for this SetFeature() call. */ pData = HidDevice -> FeatureData; for (Index = 0; Index < HidDevice -> FeatureDataLength; Index++, pData++) { pData -> IsDataSet = FALSE; } /* // In setting all the data in the reports, we need to pack a report buffer // and call WriteFile for each report ID that is represented by the // device structure. To do so, the IsDataSet field will be used to // determine if a given report field has already been set. */ Status = TRUE; pData = HidDevice -> FeatureData; for (Index = 0; Index < HidDevice -> FeatureDataLength; Index++, pData++) { if (!pData -> IsDataSet) { /* // Package the report for this data structure. PackReport will // set the IsDataSet fields of this structure and any other // structures that it includes in the report with this structure */ PackReport (HidDevice->FeatureReportBuffer, HidDevice->Caps.FeatureReportByteLength, HidP_Feature, pData, HidDevice->FeatureDataLength - Index, HidDevice->Ppd); /* // Now a report has been packaged up...Send it down to the device */ FeatureStatus =(HidD_SetFeature (HidDevice->HidDevice, HidDevice->FeatureReportBuffer, HidDevice->Caps.FeatureReportByteLength)); Status = FeatureStatus && Status; } } return (Status); }
/*! 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::SetFeatureReportRaw(const void* buffer, int report_size) { if (HidD_SetFeature(hDevice, (PVOID) buffer, report_size) != TRUE) ThrowException(L"HidD_SetFeature", ((uint8_t*) buffer)[0]); }
BOOLEAN Hid::SetFeature(HANDLE HidDeviceObject, void *ReportBuffer, ULONG ReportBufferLength) { return HidD_SetFeature(HidDeviceObject, ReportBuffer, ReportBufferLength); }