You are not logged in.
Pages: 1
I am trying to write code to communicate with a USB device using Raw HID and am having some issues. I am getting a segmentation fault because i can't access the memory of the usb_interface struct. The pointers appear to be good and i am able to get a bunch of information about the USB device, This code works in other linux distributions, so im wondering if maybe i dont have something set up/installed right? Im not sure what to try next so any help would be appreciated. Thanks
int rawhid_open(int max, int vid, int pid, int usage_page, int usage)
{
printf("%s:%d\n", __FILE__, __LINE__);
struct usb_bus *bus;
struct usb_device *dev;
struct usb_interface *iface;
struct usb_interface_descriptor *desc;
struct usb_endpoint_descriptor *ep;
usb_dev_handle *u;
uint8_t buf[1024], *p;
int i, n, len, tag, ep_in, ep_out, count=0, claimed;
uint32_t val=0, parsed_usage, parsed_usage_page;
hid_t *hid;
if (first_hid) free_all_hid();
printf("rawhid_open, max=%d\n", max);
if (max < 1) return 0;
usb_init();
usb_find_busses();
usb_find_devices();
for (bus = usb_get_busses(); bus; bus = bus->next) {
for (dev = bus->devices; dev; dev = dev->next) {
if (vid > 0 && dev->descriptor.idVendor != vid) continue;
if (pid > 0 && dev->descriptor.idProduct != pid) continue;
if (!dev->config) continue;
if (dev->config->bNumInterfaces < 1) continue;
printf("device: vid=%04X, pic=%04X, with %d iface\n",
dev->descriptor.idVendor,
dev->descriptor.idProduct,
dev->config->bNumInterfaces);
iface = dev->config->interface;
u = NULL;
claimed = 0;
for (i=0; i<dev->config->bNumInterfaces && iface; i++, iface++) {
printf("%s:%d\n", __FILE__, __LINE__);
desc = iface->altsetting; //SEGMENTATION FAULT HERE
printf("I dont get here. %s:%d\n", __FILE__, __LINE__);
(gdb) print/x dev->descriptor.idVendor
$12 = 0x16c0
(gdb) print/x dev->descriptor.idProduct
$13 = 0x486
(gdb) print/x dev->config->bNumInterfaces
$14 = 0x8
(gdb) print/x dev->config->interface
$15 = 0x21
(gdb) print/x iface
$16 = 0x21
(gdb) print/x iface->altsetting
Cannot access memory at address 0x21
(gdb) step
Program received signal SIGSEGV, Segmentation fault.
0x000091f8 in rawhid_open (max=1, vid=5824, pid=1158, usage_page=65451,
usage=512) at hid_LINUX.c:202
202 desc = iface->altsetting;
Last edited by Inxsible (2012-06-01 15:32:42)
Offline
Only because i could reuse some code that uses libusb 0.1, I think ill try using libusb 1.0 and see how that goes.
Offline
Newby3, please use code tags when posting large/long code snippets. Makes it easier to read. I have edited your post this time.
There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !
Offline
Pages: 1