Hi,Gurus,
I need to convert a legacy app from win api calls to libusbx, most of the
legacy app is using DeviceIoControl , from libusbx docs, the I believe I
need to use libusb_control_transfer, but I am not sure how to change the
calls from DeviceIoControl calls to libusb_control_transfer as
the parameters for those api are total different.
Would anyone give me some advice how to do that? maybe some examples?
Thanks in advance.
John
Below is some of our legacy calls in window api.
{
const unsigned int VENDOR_REQUEST_DIRECTION_DEVICE2HOST = 1;
const unsigned int VENDOR_REQUEST_DIRECTION_HOST2DEVICE = 0;
const unsigned int VENDOR_REQUEST_REQUESTTYPE_CLASS = 1;
const unsigned int VENDOR_REQUEST_REQUESTTYPE_VENDOR = 2;
const unsigned int VENDOR_REQUEST_RECEPIENT_ENDPOINT = 2;
#define VR_I2C_COMMAND 0xb9 // pokes/peeks I2C bus
// IN/OUT control transfer, value
contains C0xx, where xx is
// 0xA2: DPH, 0xA4: DPL, or 0xAA: DPL
Brk out board
// index contains the offset in the
eeprom to read or
// write. (if you write to DPH offset
0-8 you can mess
// up the VID/PID/DID for ITP-XDP!!
// length should be the length of the
associated EP0 out
// data, or the amount of data you want
returned in EP0
// if it's an IN transaction.
const USHORT c_usDeviceId = 0xC0A2; // device ID
const USHORT c_usOffset = 0x20; // location of device
const uint c_uiLength = 0xA; // in bytes
enError = SendVendorRequest(
VENDOR_REQUEST_DIRECTION_DEVICE2HOST, // direction
VENDOR_REQUEST_REQUESTTYPE_VENDOR, // request type
VENDOR_REQUEST_RECEPIENT_ENDPOINT, // recipient
VR_I2C_COMMAND, // request
c_usDeviceId, // device id
c_usOffset, // offset
c_uiLength, // size
reinterpret_cast<UCHAR*>(pszAssNum)); // buffer
pszAssNum[c_uiLength] = '\0';
}
ErrNo SendVendorRequest(
const UCHAR direction,
const UCHAR requestType,
const UCHAR recepient,
const UCHAR request,
const USHORT value,
const USHORT index,
const UINT nBufferSize,
UCHAR* pBuffer)
{
ErrNo enError = ErrNo_OK;
if (ErrNo_OK == enError)
{
VENDOR_OR_CLASS_REQUEST_CONTROL sControl;
sControl.direction = direction;
sControl.requestType = requestType;
sControl.recepient = recepient;
sControl.request = request;
sControl.value = value;
sControl.index = index;
DWORD dwIoControlCode;
if(_usbDriverType == UMDF)
{
dwIoControlCode = direction == VENDOR_REQUEST_DIRECTION_DEVICE2HOST ?
IOCTL_EZUSB_VENDOR_OR_CLASS_REQUEST_DIRECTOUT :
IOCTL_EZUSB_VENDOR_OR_CLASS_REQUEST_DIRECTIN;
} else {
dwIoControlCode = IOCTL_EZUSB_VENDOR_OR_CLASS_REQUEST;
}
DWORD length = 0;
BOOL bStatus = *DeviceIoControl*(
m_hDeviceObject,
dwIoControlCode, //moved to using _usbDriverType instead of the ifdef fix
above
&sControl,
sizeof(VENDOR_OR_CLASS_REQUEST_CONTROL),
pBuffer,
nBufferSize,
&length,
0);
}
return enError;
}
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel