Xiaofan Chen | 4 Dec 12:44 2005
Picon

Re: I need the SerialNumber for a plain linux-user

On Mon, Sep 26, 2005 at 01:42:35PM -0400, Charles Lepple wrote:
> On 9/26/05, Peter Stuge <stuge-libusb <at> cdy.org> wrote:
> > I am not sure whether detaching the kernel driver requires root
> > privileges or if write access to the /proc/bus/usb/*/* file is
> > enough.
>
> I'm pretty sure that only write access is necessary, because NUT's
> USB drivers (in the Debian packages) and libhid/libphidgets use
> special groups for access.

This is the follow up to the issues with hotplugging of PICkit 1/2
PIC MCU programmers. They both have dual configurations
(HID and vendor specific).

Finally Mark Rages (the develper of the Python application to
control PICkit 1/2 application using the BitPim libusb wrapper)
solved the issue with PICkit 1/2 hotplugging. We need to detach
the kernel HID driver in the hotplug script.

With this hotplug script, we can now run PICkit 1/2 libusb
based application under Linux using a normal user account.

Regards,
Xiaofan

mcuee <at> ubuntu:/etc/hotplug/usb$ cat pickit
#!/bin/bash

if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ]
then
(Continue reading)

Shawn Jackson | 8 Dec 18:09 2005
Picon

usb_bulk_write issue

 I am having a problem with libusb 0.1.10a with Fedora Core 3.

I run the following test code with no problems on a RedHat 9 machine with kernel 2.4.20-30.9smp.  However, when I run it on a Fedora Core 3 machine with kernels 2.6.12-1.1381_FC3smp and 2.6.9-1.667smp, I have problems.

------------------------------------------------------ Code ------------------------------------------------
#include <stdio.h>
#include <string.h>
#include <usb.h>

int main(int argc, char *argv[])
{
  struct usb_bus *bus;
  struct usb_bus *busses;
  struct usb_device *dev = NULL;

  usb_set_debug(255);

  usb_init();
  usb_find_busses();
  usb_find_devices();

  busses = usb_get_busses();

  for (bus = busses; bus; bus = bus->next)
  {
    for (dev = bus->devices; dev; dev = dev->next)
    {
      if (dev->descriptor.idVendor == 0x0765 && dev->descriptor.idProduct == 0xD094)
      {
        //Now lets open the device...
        struct usb_dev_handle *_handle = usb_open(dev);

        int res = usb_claim_interface(_handle, 0);
        if (res < 0)
        {
          printf("Could not claim device...\n");
          return -1;
        }

        unsigned char buffer[8];
        memset(buffer, 0, sizeof(buffer));
        buffer[0] = 'S';
        buffer[1] = 'N';
        buffer[2] = '\r';
        buffer[3] = '\n';

        res = usb_bulk_write(_handle, 0x02, buffer, sizeof(buffer), 65535);
        if (res < 0)
        {
          printf("Could not write to the device...\n");
          return -1;
        }

        //Wrote... now read...
        res = usb_bulk_read(_handle, 0x81, buffer, sizeof(buffer), 65535);
        if (res < 0)
        {
          printf("Could not read from the device...\n");
          return -1;
        }

        printf("Buffer returned: %s\n", buffer);

        res = usb_release_interface(_handle, 0);
        if (res < 0)
        {
          printf("Could not release device...\n");
          return -1;
        }


        usb_close(_handle);
        _handle = NULL;

      }
    }
  }

  return 0;
}

--------------------------------------------- Results --------------------------------------------------
[jackson]$ ./test
usb_set_debug: Setting debugging level to 255 (on)
usb_os_init: Found USB VFS at /proc/bus/usb
usb_os_find_busses: Found 003
usb_os_find_busses: Found 002
usb_os_find_busses: Found 001
usb_os_find_busses: Skipping non bus directory devices
usb_os_find_devices: couldn't get connect info
usb_os_find_devices: Found 001 on 003
error obtaining child information: Operation not permitted
usb_os_find_devices: couldn't get connect info
usb_os_find_devices: Found 001 on 002
error obtaining child information: Operation not permitted
usb_os_find_devices: Found 002 on 001
usb_os_find_devices: couldn't get connect info
usb_os_find_devices: Found 001 on 001
error obtaining child information: Inappropriate ioctl for device
error obtaining child information: Operation not permitted
USB error: error submitting URB: Invalid argument
Could not write to the device...

[jackson]$ dmesg | grep usb
usbcore: registered new driver usbfs
usbcore: registered new driver hub
usbcore: registered new driver hiddev
usbcore: registered new driver usbhid
drivers/usb/input/hid-core.c: v2.01:USB HID core driver
usb 1-2: new low speed USB device using uhci_hcd and address 2
usb 1-2: usbfs: usb_submit_urb returned -22



Any clues as to what I'm doing wrong?

Thank you,

--Shawn Jackson

Yahoo! Shopping
Find Great Deals on Holiday Gifts at Yahoo! Shopping
Chris Frey | 8 Dec 19:36 2005
Picon

Re: usb_bulk_write issue

On Thu, Dec 08, 2005 at 09:09:27AM -0800, Shawn Jackson wrote:
>   error obtaining child information: Inappropriate ioctl for device
>   error obtaining child information: Operation not permitted

Are you running as root, or can you write to the device?

- Chris

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
Shawn Jackson | 9 Dec 03:44 2005
Picon

Re: Re: usb_bulk_write issue

I've tried running as root to the same results.  It always ends with the error -22.  What confuses me is that it runs perfectly fine when running RedHat 9.
 
The device runs fine in RedHat 9 and Enterprise 3, as well as Windows.

Yahoo! Shopping
Find Great Deals on Holiday Gifts at Yahoo! Shopping
Charles Lepple | 9 Dec 04:00 2005
Picon

Re: Re: usb_bulk_write issue

What does /proc/bus/usb/devices say about this device?

--
- Charles Lepple

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
Shawn Jackson | 9 Dec 14:52 2005
Picon

Re: Re: usb_bulk_write issue

T:  Bus=03 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
B:  Alloc=  0/900 us ( 0%), #Int=  0, #Iso=  0
D:  Ver= 1.10 Cls=09(hub  ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
P:  Vendor=0000 ProdID=0000 Rev= 2.06
S:  Manufacturer=Linux 2.6.12-1.1381_FC3smp uhci_hcd
S:  Product=UHCI Host Controller
S:  SerialNumber=0000:00:1d.2
C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr=  0mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
E:  Ad=81(I) Atr=03(Int.) MxPS=   2 Ivl=255ms

T:  Bus=02 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
B:  Alloc=  0/900 us ( 0%), #Int=  0, #Iso=  0
D:  Ver= 1.10 Cls=09(hub  ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
P:  Vendor=0000 ProdID=0000 Rev= 2.06
S:  Manufacturer=Linux 2.6.12-1.1381_FC3smp uhci_hcd
S:  Product=UHCI Host Controller
S:  SerialNumber=0000:00:1d.1
C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr=  0mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
E:  Ad=81(I) Atr=03(Int.) MxPS=   2 Ivl=255ms

T:  Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
B:  Alloc=  0/900 us ( 0%), #Int=  0, #Iso=  0
D:  Ver= 1.10 Cls=09(hub  ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
P:  Vendor=0000 ProdID=0000 Rev= 2.06
S:  Manufacturer=Linux 2.6.12-1.1381_FC3smp uhci_hcd
S:  Product=UHCI Host Controller
S:  SerialNumber=0000:00:1d.0
C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr=  0mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
E:  Ad=81(I) Atr=03(Int.) MxPS=   2 Ivl=255ms

T:  Bus=01 Lev=01 Prnt=01 Port=01 Cnt=01 Dev#=  2 Spd=1.5 MxCh= 0
D:  Ver= 2.00 Cls=ff(vend.) Sub=ff Prot=ff MxPS= 8 #Cfgs=  1
P:  Vendor=0765 ProdID=d094 Rev= 0.00
S:  Manufacturer=X-Rite
S:  Product=X-Rite DTP94
S:  SerialNumber=013285
C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr= 20mA
I:  If#= 0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=(none)
E:  Ad=81(I) Atr=03(Int.) MxPS=   8 Ivl=10ms
E:  Ad=02(O) Atr=03(Int.) MxPS=   8 Ivl=10ms


Charles Lepple <clepple <at> gmail.com> wrote:
What does /proc/bus/usb/devices say about this device?

--
- Charles Lepple


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
Libusb-devel mailing list
Libusb-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusb-devel

Yahoo! Shopping
Find Great Deals on Holiday Gifts at Yahoo! Shopping
Charles Lepple | 9 Dec 16:39 2005
Picon

Re: Re: usb_bulk_write issue

On 12/9/05, Shawn Jackson <srjacks0n <at> yahoo.com> wrote:
>  T:  Bus=01 Lev=01 Prnt=01 Port=01 Cnt=01 Dev#=&nbs p; 2 Spd=1.5 MxCh= 0
>  D:  Ver= 2.00 Cls=ff(vend.) Sub=ff Prot=ff MxPS= 8 #Cfgs=  1
>  P:  Vendor=0765 ProdID=d094 Rev= 0.00
>  S:  Manufacturer=X-Rite
>  S:  Product=X-Rite DTP94
>  S:  SerialNumber=013285
>  C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr= 20mA
>  I:  If#= 0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=(none)
>  E:  Ad=81(I) Atr=03(Int.) MxPS=   8 Ivl=10ms
>  E:  Ad=02(O) Atr=03(Int.) MxPS=   8 Ivl=10ms

There was a problem with the 2.4 kernel where, on low-speed devices,
you had to use usb_bulk_read/write on interrupt endpoints, or
something silly like that. Under 2.6, you should use
usb_interrupt_write.

--
- Charles Lepple

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
Shawn Jackson | 9 Dec 17:43 2005
Picon

Re: Re: usb_bulk_write issue

Well, I switched from bulk to interrupt and got slight progress.  I can write and read from the device once.  It only works 1 time after being plugged in.  Every subsequent try, it fails.  If I unplug it and replug it, it's fine.  Any thoughts?

--Shawn

Yahoo! Shopping
Find Great Deals on Holiday Gifts at Yahoo! Shopping
Dan Ellis | 9 Dec 18:51 2005

RE: Re: usb_bulk_write issue

I've come across some development boards presenting interrupt endpoints which require alternate reads and writes for them to operate properly. Maybe this is like that?
 
Dan.

From: libusb-devel-admin <at> lists.sourceforge.net [mailto:libusb-devel-admin <at> lists.sourceforge.net] On Behalf Of Shawn Jackson
Sent: 09 December 2005 16:44
To: Charles Lepple
Cc: libusb-devel <at> lists.sourceforge.net
Subject: Re: [Libusb-devel] Re: usb_bulk_write issue

Well, I switched from bulk to interrupt and got slight progress.  I can write and read from the device once.  It only works 1 time after being plugged in.  Every subsequent try, it fails.  If I unplug it and replug it, it's fine.  Any thoughts?

--Shawn

Yahoo! Shopping
Find Great Deals on Holiday Gifts at Yahoo! Shopping
Charles Lepple | 9 Dec 18:59 2005
Picon

Re: Re: usb_bulk_write issue

On 12/9/05, Shawn Jackson <srjacks0n <at> yahoo.com> wrote:
> Well, I switched from bulk to interrupt and got slight progress.  I can
> write and read from the device once.  It only works 1 time after being
> plugged in.  Every subsequent try, it fails.  If I unplug it and replug it,
> it's fine.  Any thoughts?

Do you mean subsequent tries in one run of the program, or running the
program multiple times?

If it's the latter, maybe the device needs some sort of reset
sequence? (usb_clear_halt() might be useful.)

What error codes do you get?

--
- Charles Lepple

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click

Gmane