Skip to content

Fix so novacomd works with new libusb-compat #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ endif

# compiler flags, default libs to link against
MYCFLAGS := -Wall -W -Wno-multichar -Wno-unused-parameter -Wno-unused-function -g -O2 -Iinclude -DBUILDVERSION=$(BUILDVERSION)
CFLAGS :=
# pull in the machine build name version from OE if it's set
ifneq ($(MACHINE),)
MYCFLAGS += -DMACHINE=\"$(MACHINE)\"
endif
HOSTCFLAGS := $(MYCFLAGS) -Isrc
HOSTCFLAGS := $(MYCFLAGS) $(CFLAGS) -Isrc
DEVICECFLAGS := $(MYCFLAGS) $(OECFLAGS) $(TARGET_CC_ARCH) -DPLATFORM_PTHREADS=1
CPPFLAGS := -g
ASMFLAGS :=
Expand Down
42 changes: 6 additions & 36 deletions src/host/usb-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,8 @@

#define USBDEVFS_IOCTL_TIMEOUT 2000

struct myusb_dev_handle {
int fd;

// other stuff here
};

typedef struct {
union {
usb_dev_handle *handle;

/* XXX cheezy hack to let us get to the file descriptor hidden in the libusb handle */
struct myusb_dev_handle *myhandle;
};

usb_dev_handle *handle;
novacom_usbll_handle_t usbll_handle;

bool shutdown;
Expand Down Expand Up @@ -218,7 +206,7 @@ static novacom_usb_handle_t *novacom_usb_open( void )
if (!handle) continue;

#if USB_SCAN_TRACE
log_printf(LOG_SPEW, "opened usb handle: fd %d\n", ((struct myusb_dev_handle *)handle)->fd);
log_printf(LOG_SPEW, "opened usb handle: devnum %d\n", dev->devnum);
#endif

int eps[2];
Expand Down Expand Up @@ -281,17 +269,10 @@ int novacom_usb_transport_init(void)
static int novacom_usb_read(novacom_usb_handle_t *handle, void *buf, size_t len)
{
// TRACEF("handle %p, buf %p, len %d, timeout %d\n", handle, buf, len, timeout);
// TRACEF("fd %d\n", handle->myhandle->fd);

struct usbdevfs_bulktransfer bulktransfer;

bulktransfer.ep = handle->rxep;
bulktransfer.len = len;
bulktransfer.timeout = handle->rx_timeout;
bulktransfer.data = buf;

int rc;
rc = ioctl(handle->myhandle->fd, USBDEVFS_BULK, &bulktransfer);

rc = usb_bulk_read(handle->handle, handle->rxep, buf, len, handle->rx_timeout);
if (rc > 0) { //now check the packet header

if (novacom_usbll_check_packet_header(buf, rc)) { //bad packet
Expand All @@ -303,22 +284,11 @@ static int novacom_usb_read(novacom_usb_handle_t *handle, void *buf, size_t len)
return rc;
}

static int novacom_usb_write(novacom_usb_handle_t *handle, const void *buf, size_t len)
static int novacom_usb_write(novacom_usb_handle_t *handle, void *buf, size_t len)
{
// TRACEF("handle %p, buf %p, len %d, timeout %d\n", handle, buf, len, timeout);
// TRACEF("fd %d\n", handle->myhandle->fd);

struct usbdevfs_bulktransfer bulktransfer;

bulktransfer.ep = handle->txep;
bulktransfer.len = len;
bulktransfer.timeout = handle->tx_timeout;
bulktransfer.data = (void *)buf;

int rc;
rc = ioctl(handle->myhandle->fd, USBDEVFS_BULK, &bulktransfer);
// TRACEF("rc %d\n", rc);
return rc;
return usb_bulk_write(handle->handle, handle->txep, buf, len, handle->tx_timeout);
}

struct usb_thread_args {
Expand Down
3 changes: 1 addition & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -733,15 +733,14 @@ static int main_loop(void)
struct active_device *temp_dev;
/* device */
if (FD_ISSET(dev->socket, &fds) ) {
int err;
SOCKET newsocket = accept_socket(dev->socket);
TRACEL(LOG_TRACE, "data socket %d\n", newsocket);

if(newsocket != INVALID_SOCKET) {

// Set non-blocking or novacomd will drop offline if the socket fills up
fcntl(newsocket, F_SETFL, fcntl(newsocket, F_GETFL) | O_NONBLOCK);
err = novacom_register_client(dev, newsocket);
novacom_register_client(dev, newsocket);
}
}

Expand Down