int xusb_send(struct xusb *xusb, char *buf, int len, int timeout) { int ret; dump_packet(LOG_DEBUG, DBG_MASK, __FUNCTION__, buf, len); if(EP_OUT(xusb) & USB_ENDPOINT_IN) { ERR("%s called with an input endpoint 0x%x\n", __FUNCTION__, EP_OUT(xusb)); return -EINVAL; } ret = usb_bulk_write(xusb->handle, EP_OUT(xusb), buf, len, timeout); if(ret < 0) { /* * If the device was gone, it may be the * result of renumeration. Ignore it. */ if(ret != -ENODEV) { ERR("bulk_write to endpoint 0x%x failed: (%d) %s\n", EP_OUT(xusb), ret, usb_strerror()); dump_packet(LOG_ERR, DBG_MASK, "xbus_send[ERR]", buf, len); //exit(2); } else { DBG("bulk_write to endpoint 0x%x got ENODEV\n", EP_OUT(xusb)); xusb_close(xusb); } return ret; } else if(ret != len) { ERR("bulk_write to endpoint 0x%x short write: (%d) %s\n", EP_OUT(xusb), ret, usb_strerror()); dump_packet(LOG_ERR, DBG_MASK, "xbus_send[ERR]", buf, len); return -EFAULT; } return ret; }
void xusb_destroy(struct xusb *xusb) { if(xusb) { xusb_close(xusb); memset(xusb, 0, sizeof(*xusb)); free(xusb); } }
void astribank_close(struct astribank_device *astribank, int disconnected) { assert(astribank != NULL); if (astribank->xusb) { xusb_close(astribank->xusb); astribank->xusb = NULL; } astribank->tx_sequenceno = 0; }
int xusb_send(struct xusb *xusb, char *buf, int len, int timeout) { int ret; int retries = 0; dump_packet(LOG_DEBUG, DBG_MASK, __func__, buf, len); if (EP_OUT(xusb) & USB_ENDPOINT_IN) { ERR("%s called with an input endpoint 0x%x\n", __func__, EP_OUT(xusb)); return -EINVAL; } retry_write: ret = usb_bulk_write(xusb->handle, EP_OUT(xusb), buf, len, timeout); if (ret < 0) { /* * If the device was gone, it may be the * result of renumeration. Ignore it. */ if (ret != -ENODEV) { ERR("bulk_write to endpoint 0x%x failed: (%d) %s\n", EP_OUT(xusb), ret, usb_strerror()); dump_packet(LOG_ERR, DBG_MASK, "xusb_send[ERR]", buf, len); /*exit(2);*/ } else { DBG("bulk_write to endpoint 0x%x got ENODEV\n", EP_OUT(xusb)); xusb_close(xusb); } return ret; } if (!ret) { ERR("bulk_write to endpoint 0x%x short write[%d]: (%d)\n", EP_OUT(xusb), retries, ret); if (retries++ > MAX_RETRIES) return -EFAULT; usleep(100); goto retry_write; } if (ret != len) { ERR("bulk_write to endpoint 0x%x short write: (%d) %s\n", EP_OUT(xusb), ret, usb_strerror()); dump_packet(LOG_ERR, DBG_MASK, "xusb_send[ERR]", buf, len); return -EFAULT; } return ret; }