libusb-compat: usbbus_bulk_read/write -> transfer
This commit is contained in:
parent
a4129edb69
commit
c2504e0825
@ -617,33 +617,12 @@ int usbbus_set_configuration(usbbus_device_handle *dev, int configuration)
|
|||||||
int usbbus_get_string_simple(usbbus_device_handle *dev, int index, char *buf, size_t buflen)
|
int usbbus_get_string_simple(usbbus_device_handle *dev, int index, char *buf, size_t buflen)
|
||||||
{
|
{
|
||||||
return libusb_get_string_descriptor_ascii((libusb_device_handle *)dev, index & 0xff,
|
return libusb_get_string_descriptor_ascii((libusb_device_handle *)dev, index & 0xff,
|
||||||
(unsigned char *) buf, (int) buflen);
|
(unsigned char *) buf, (int) buflen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usbbus_bulk_io(usbbus_device_handle *dev, int ep, unsigned char *bytes,
|
int usbbus_bulk_transfer(usbbus_device_handle *dev, int ep, char *bytes, int size, int *actual_length, int timeout)
|
||||||
int size, int timeout)
|
|
||||||
{
|
{
|
||||||
int actual_length;
|
return libusb_bulk_transfer((libusb_device_handle *)dev, ep & 0xff, (unsigned char *)bytes, size, actual_length, timeout);
|
||||||
int r;
|
|
||||||
r = libusb_bulk_transfer((libusb_device_handle *)dev, ep & 0xff, bytes, size,
|
|
||||||
&actual_length, timeout);
|
|
||||||
|
|
||||||
/* if we timed out but did transfer some data, report as successful short
|
|
||||||
* read. FIXME: is this how libusb-0.1 works? */
|
|
||||||
if (r == 0 || (r == LIBUSB_ERROR_TIMEOUT && actual_length > 0))
|
|
||||||
return actual_length;
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
int usbbus_bulk_read(usbbus_device_handle *dev, int ep, char *bytes, int size, int timeout)
|
|
||||||
{
|
|
||||||
return usbbus_bulk_io(dev, ep, (unsigned char *) bytes, size, timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
int usbbus_bulk_write(usbbus_device_handle *dev, int ep, const char *bytes, int size, int timeout)
|
|
||||||
{
|
|
||||||
return usbbus_bulk_io(dev, ep, (unsigned char *)bytes, size, timeout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int usbbus_claim_interface(usbbus_device_handle *dev, int interface)
|
int usbbus_claim_interface(usbbus_device_handle *dev, int interface)
|
||||||
@ -666,7 +645,7 @@ int usbbus_reset(usbbus_device_handle *dev)
|
|||||||
return libusb_reset_device((libusb_device_handle *)dev);
|
return libusb_reset_device((libusb_device_handle *)dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * usbbus_strerror(int errcode)
|
const char *usbbus_strerror(int errcode)
|
||||||
{
|
{
|
||||||
return libusb_strerror((enum libusb_error)errcode);
|
return libusb_strerror((enum libusb_error)errcode);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -163,13 +163,12 @@ usbbus_device_handle *usbbus_open(struct usbbus_device *dev);
|
|||||||
void usbbus_close(usbbus_device_handle *dev);
|
void usbbus_close(usbbus_device_handle *dev);
|
||||||
int usbbus_set_configuration(usbbus_device_handle *dev, int configuration);
|
int usbbus_set_configuration(usbbus_device_handle *dev, int configuration);
|
||||||
int usbbus_get_string_simple(usbbus_device_handle *dev, int index, char *buf, size_t buflen);
|
int usbbus_get_string_simple(usbbus_device_handle *dev, int index, char *buf, size_t buflen);
|
||||||
int usbbus_bulk_read(usbbus_device_handle *dev, int ep, char *bytes, int size, int timeout);
|
int usbbus_bulk_transfer(usbbus_device_handle *dev, int ep, char *bytes, int size, int *actual_length, int timeout);
|
||||||
int usbbus_bulk_write(usbbus_device_handle *dev, int ep, const char *bytes, int size, int timeout);
|
|
||||||
int usbbus_claim_interface(usbbus_device_handle *dev, int interface);
|
int usbbus_claim_interface(usbbus_device_handle *dev, int interface);
|
||||||
int usbbus_release_interface(usbbus_device_handle *dev, int interface);
|
int usbbus_release_interface(usbbus_device_handle *dev, int interface);
|
||||||
int usbbus_set_interface_alt_setting(usbbus_device_handle *dev, int interface, int alternate);
|
int usbbus_set_interface_alt_setting(usbbus_device_handle *dev, int interface, int alternate);
|
||||||
int usbbus_reset(usbbus_device_handle *dev);
|
int usbbus_reset(usbbus_device_handle *dev);
|
||||||
const char * usbbus_strerror(int errcode);
|
const char *usbbus_strerror(int errcode);
|
||||||
struct usbbus_bus *usbbus_get_busses(void);
|
struct usbbus_bus *usbbus_get_busses(void);
|
||||||
|
|
||||||
#endif // __NFC_BUS_USB_H__
|
#endif // __NFC_BUS_USB_H__
|
||||||
|
|||||||
@ -217,10 +217,12 @@ static int acr122_usb_send_apdu(nfc_device *pnd,
|
|||||||
static int
|
static int
|
||||||
acr122_usb_bulk_read(struct acr122_usb_data *data, uint8_t abtRx[], const size_t szRx, const int timeout)
|
acr122_usb_bulk_read(struct acr122_usb_data *data, uint8_t abtRx[], const size_t szRx, const int timeout)
|
||||||
{
|
{
|
||||||
int res = usbbus_bulk_read(data->pudh, data->uiEndPointIn, (char *) abtRx, szRx, timeout);
|
int actual_length;
|
||||||
if (res > 0) {
|
int res = usbbus_bulk_transfer(data->pudh, data->uiEndPointIn, (char *) abtRx, szRx, &actual_length, timeout);
|
||||||
LOG_HEX(NFC_LOG_GROUP_COM, "RX", abtRx, res);
|
if (res == 0) {
|
||||||
} else if (res < 0) {
|
LOG_HEX(NFC_LOG_GROUP_COM, "RX", abtRx, actual_length);
|
||||||
|
res = actual_length;
|
||||||
|
} else {
|
||||||
if (res != USBBUS_ERROR_TIMEOUT) {
|
if (res != USBBUS_ERROR_TIMEOUT) {
|
||||||
res = NFC_EIO;
|
res = NFC_EIO;
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to read from USB (%s)", usbbus_strerror(res));
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to read from USB (%s)", usbbus_strerror(res));
|
||||||
@ -235,13 +237,14 @@ static int
|
|||||||
acr122_usb_bulk_write(struct acr122_usb_data *data, uint8_t abtTx[], const size_t szTx, const int timeout)
|
acr122_usb_bulk_write(struct acr122_usb_data *data, uint8_t abtTx[], const size_t szTx, const int timeout)
|
||||||
{
|
{
|
||||||
LOG_HEX(NFC_LOG_GROUP_COM, "TX", abtTx, szTx);
|
LOG_HEX(NFC_LOG_GROUP_COM, "TX", abtTx, szTx);
|
||||||
int res = usbbus_bulk_write(data->pudh, data->uiEndPointOut, (char *) abtTx, szTx, timeout);
|
int actual_length;
|
||||||
if (res > 0) {
|
int res = usbbus_bulk_transfer(data->pudh, data->uiEndPointOut, (char *) abtTx, szTx, &actual_length, timeout);
|
||||||
|
if (res == 0) {
|
||||||
// HACK This little hack is a well know problem of USB, see http://www.libusb.org/ticket/6 for more details
|
// HACK This little hack is a well know problem of USB, see http://www.libusb.org/ticket/6 for more details
|
||||||
if ((res % data->uiMaxPacketSize) == 0) {
|
if ((actual_length > 0) && ((actual_length % data->uiMaxPacketSize) == 0)) {
|
||||||
usbbus_bulk_write(data->pudh, data->uiEndPointOut, "\0", 0, timeout);
|
usbbus_bulk_transfer(data->pudh, data->uiEndPointOut, "\0", 0, &actual_length, timeout);
|
||||||
}
|
}
|
||||||
} else if (res < 0) {
|
} else {
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to write to USB (%s)", usbbus_strerror(res));
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to write to USB (%s)", usbbus_strerror(res));
|
||||||
if (res == USBBUS_ERROR_TIMEOUT) {
|
if (res == USBBUS_ERROR_TIMEOUT) {
|
||||||
res = NFC_ETIMEOUT;
|
res = NFC_ETIMEOUT;
|
||||||
|
|||||||
@ -89,10 +89,12 @@ int pn53x_usb_init(nfc_device *pnd);
|
|||||||
static int
|
static int
|
||||||
pn53x_usb_bulk_read(struct pn53x_usb_data *data, uint8_t abtRx[], const size_t szRx, const int timeout)
|
pn53x_usb_bulk_read(struct pn53x_usb_data *data, uint8_t abtRx[], const size_t szRx, const int timeout)
|
||||||
{
|
{
|
||||||
int res = usbbus_bulk_read(data->pudh, data->uiEndPointIn, (char *) abtRx, szRx, timeout);
|
int actual_length;
|
||||||
if (res > 0) {
|
int res = usbbus_bulk_transfer(data->pudh, data->uiEndPointIn, (char *) abtRx, szRx, &actual_length, timeout);
|
||||||
LOG_HEX(NFC_LOG_GROUP_COM, "RX", abtRx, res);
|
if (res == 0) {
|
||||||
} else if (res < 0) {
|
LOG_HEX(NFC_LOG_GROUP_COM, "RX", abtRx, actual_length);
|
||||||
|
res = actual_length;
|
||||||
|
} else {
|
||||||
if (res != USBBUS_ERROR_TIMEOUT)
|
if (res != USBBUS_ERROR_TIMEOUT)
|
||||||
log_put(NFC_LOG_GROUP_COM, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to read from USB (%s)", usbbus_strerror(res));
|
log_put(NFC_LOG_GROUP_COM, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to read from USB (%s)", usbbus_strerror(res));
|
||||||
}
|
}
|
||||||
@ -103,11 +105,12 @@ static int
|
|||||||
pn53x_usb_bulk_write(struct pn53x_usb_data *data, uint8_t abtTx[], const size_t szTx, const int timeout)
|
pn53x_usb_bulk_write(struct pn53x_usb_data *data, uint8_t abtTx[], const size_t szTx, const int timeout)
|
||||||
{
|
{
|
||||||
LOG_HEX(NFC_LOG_GROUP_COM, "TX", abtTx, szTx);
|
LOG_HEX(NFC_LOG_GROUP_COM, "TX", abtTx, szTx);
|
||||||
int res = usbbus_bulk_write(data->pudh, data->uiEndPointOut, (char *) abtTx, szTx, timeout);
|
int actual_length;
|
||||||
if (res > 0) {
|
int res = usbbus_bulk_transfer(data->pudh, data->uiEndPointOut, (char *) abtTx, szTx, &actual_length, timeout);
|
||||||
|
if (res == 0) {
|
||||||
// HACK This little hack is a well know problem of USB, see http://www.libusb.org/ticket/6 for more details
|
// HACK This little hack is a well know problem of USB, see http://www.libusb.org/ticket/6 for more details
|
||||||
if ((res % data->uiMaxPacketSize) == 0) {
|
if ((actual_length > 0) && ((actual_length % data->uiMaxPacketSize) == 0)) {
|
||||||
usbbus_bulk_write(data->pudh, data->uiEndPointOut, "\0", 0, timeout);
|
usbbus_bulk_transfer(data->pudh, data->uiEndPointOut, "\0", 0, &actual_length, timeout);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log_put(NFC_LOG_GROUP_COM, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to write to USB (%s)", usbbus_strerror(res));
|
log_put(NFC_LOG_GROUP_COM, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to write to USB (%s)", usbbus_strerror(res));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user