Skip to content

Commit

Permalink
Added function calls to detach/attach the kernel driver in linux. Als…
Browse files Browse the repository at this point in the history
…o added a 99-polar.rules file that MUST be copied to

the /etc/udev/rules directory in order to allow non-root users to run the downloader. Unfortunately there is no way around
this as the default USB permissions in linux only allow root write access. Once the .rules file has been added the downloader
works perfect on my test system, Linux Mint 17 64 bit. It's statically linking against libusb right now to make it easier
to deploy in the new few days. For now it's only available as source for linux, but an intrepid user should be good to go
and start downloading files on their linux machines.
  • Loading branch information
profanum429 committed Aug 2, 2014
1 parent 6b995a3 commit f0574f2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions 99-polar.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="0da4", ATTRS{idProduct}=="0008", MODE="0666"
20 changes: 20 additions & 0 deletions native_usb.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "native_usb.h"
#include <QByteArray>
#include <unistd.h>

#if defined(Q_OS_MAC)
extern "C"
Expand Down Expand Up @@ -36,6 +37,15 @@ int native_usb::open_usb(int vid, int pid)
return -1;
}

#if defined(Q_OS_LINUX)
r = libusb_detach_kernel_driver(usb, 0);
if(r != 0)
{
qDebug("Detach Kernel Driver: %s", libusb_error_name(r));
return -1;
}
#endif

r = libusb_claim_interface(usb, 0);
if(r != 0)
{
Expand All @@ -48,7 +58,12 @@ int native_usb::open_usb(int vid, int pid)
libusb_close(usb);
usb = NULL;

#if defined(Q_OS_WIN)
Sleep(500);
#endif
#if defined(Q_OS_LINUX)
usleep(500000);
#endif

qDebug("Reopening the USB device...");
usb = libusb_open_device_with_vid_pid(NULL, vid, pid);
Expand All @@ -65,7 +80,12 @@ int native_usb::open_usb(int vid, int pid)
return -1;
}

#if defined(Q_OS_WIN)
Sleep(500);
#endif
#if defined(Q_OS_LINUX)
usleep(500000);
#endif

return 0;
#endif
Expand Down
2 changes: 2 additions & 0 deletions v800_downloader.pro
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ UI_DIR = $$DESTDIR/tmp
osx:LIBS += -framework CoreFoundation -framework IOKit
win32:INCLUDEPATH += C:/Qt/libusb-1.0
win32:LIBS += C:/Qt/libusb-1.0/libusb-1.0.a
unix:!macx:INCLUDEPATH += /usr/local/include/libusb-1.0
unix:!macx:LIBS += /usr/local/lib/libusb-1.0.a -ludev

0 comments on commit f0574f2

Please sign in to comment.