|
From: <Gan...@De...> - 2004-07-07 14:37:25
|
Modify as below:
=20
1) struct usbdevfs_hub_portinfo* hubPortInfo =3D (struct
usbdevfs_hub_portinfo*)malloc(sizeof(struct usbdevfs_hub_portinfo));
//----- hubPortInfo was not allocated any memory :o)
=20
2) open("/proc/bus/usb/001/001", O_RDWR);
//----- device needs to be opened in read-write mode
=20
Thanks,
Ganesh
=20
-----Original Message-----
From: David Doiron [mailto:dd...@me...]
Sent: Wednesday, July 07, 2004 7:01 PM
To: Borse, Ganesh; mva...@ca...;
lib...@li...
Subject: RE: [Libusb-devel] Get The Port number from the Bus/Dev number
Thank you for your help, what you say for the open() function is quite
logical. But, the ioctl() function still won't work. The errno I get is
Operation not permitted. It's kind of weird since everything seems to be
in place: Includes, declarations, etc...
=20
Maybe is there something I forget ? What do you think ?
=20
#include <usb.h>
#include <linux/usbdevice_fs.h> //To get port #
=20
{
struct usbdevfs_hub_portinfo* hubPortInfo;
=20
struct usbdevfs_ioctl command =3D {0};
command.ifno =3D 0;
command.ioctl_code =3D USBDEVFS_HUB_PORTINFO;
command.data =3D (void*)hubPortInfo;
errno =3D 0;
int nCntr;
=20
int fd =3D open("/proc/bus/usb/001/001", O_RDONLY); // Reads the =
UHCI
for existing devices
if(fd !=3D -1)
{
int ret =3D
ioctl(fd,USBDEVFS_IOCTL,&command); // this call is for USB hubs
if(ret !=3D -1)
{
=20
printf("NPORT:%d\n",hubPortInfo->nports);
for (nCntr=3D0;
nCntr<hubPortInfo->nports; nCntr++)
{
=20
printf("%03d\n",hubPortInfo->port[nCntr]);
}
}
=20
else=20
{
printf("IOCTL
FAILED!\n");
if (errno =3D=3D EBADF)
printf("ERRNO: EBADF\n");
if (errno =3D=3D EFAULT)
printf("ERRNO: EFAULT\n");
if (errno =3D=3D ENOTTY)
printf("ERRNO: ENOTTY\n");
if (errno =3D=3D EINVAL)
printf("ERRNO: EINVAL\n");
if (errno =3D=3D EPERM)
printf("ERRNO: EPERM\n"); //Errno =3D 1, which is : Operation not
permitted
}
=20
close(fd); =20
}
else printf("OPEN FAILED !\n");
=20
}
=20
Thanks a lot!
David
=20
-----Original Message-----
From: Gan...@De... [mailto:Gan...@De...]=20
Sent: 7 juillet, 2004 01:48
To: mva...@ca...; lib...@li...
Cc: dd...@me...
Subject: RE: [Libusb-devel] Get The Port number from the Bus/Dev number
=20
The call open("/proc/bus/usb/001", O_RDONLY); is to be changed as:
open("/proc/bus/usb/001/001", O_RDONLY);
=20
This is because /proc/bus/usb/001 is a directory in /proc/bus/usb path.
We need to open a file in it, which is 001. Hence the path
/proc/bus/usb/001/001.
=20
Another thing is that when you get -1 as return value from ioctl or any
other syscall, check "errno". It gives us the right information as to
why the call is failing. You can do this with your code also. You will
be able to figure out the problem
=20
-----Original Message-----
From: Martin Vaillancourt [mailto:mva...@ca...]
Sent: Wednesday, July 07, 2004 2:02 AM
To: Borse, Ganesh; lib...@li...
Cc: dd...@me...
Subject: RE: [Libusb-devel] Get The Port number from the Bus/Dev number
Hi,
Thank you for your support. This makes sense :-) but, it is not working
on my PC?
I cannot explain, but the ioctl() return always -1.=20
On the /proc/bus/usb/001 I have my device number 004 (by example).
Do you see something wrong in this code ?
=20
#include <usb.h>
#include <linux/usbdevice_fs.h> //To get port #
=20
{
struct usbdevfs_hub_portinfo* hubPortInfo;
=20
struct usbdevfs_ioctl command =3D {0};
command.ifno =3D 0;
command.ioctl_code =3D USBDEVFS_HUB_PORTINFO;
command.data =3D (void*)hubPortInfo;
errno =3D 0;
int nCntr;
=20
int fd =3D open("/proc/bus/usb/001", O_RDONLY); // say
/proc/bus/usb/001
if(fd !=3D -1)
{
int ret =3D
ioctl(fd,USBDEVFS_IOCTL,&command); // this call is for USB hubs
if(ret !=3D -1)
{
=20
printf("\nNPORT:%d\n",hubPortInfo->nports);
for (nCntr=3D0;
nCntr<hubPortInfo->nports; nCntr++)
{
=20
printf("%03d\n",hubPortInfo->port[nCntr]);
}
}
else printf("\nIOCTL FAILED !\n");
close(fd); =20
}
=20
}
=20
=20
=20
=20
-----Original Message-----
From: lib...@li...
[mailto:lib...@li...] On Behalf Of
Gan...@De...
Sent: Tuesday, July 06, 2004 12:29 AM
To: mva...@ca...; lib...@li...
Subject: RE: [Libusb-devel] Get The Port number from the Bus/Dev number
=20
=20
-----Original Message-----
From: lib...@li...
[mailto:lib...@li...]On Behalf Of Martin
Vaillancourt
Sent: Tuesday, July 06, 2004 1:37 AM
To: lib...@li...
Subject: [Libusb-devel] Get The Port number from the Bus/Dev number
Hi,
From the Libusb-0.1.8 with the Linux 2.6.5-1 running on a Dell PC.
I can detect USB Device USB2.0 easily with the "TestLibusb" tool.
=20
I would like to know how to get the port number. I explain:
From the /proc/dev/bus/devices , I can see this info
T: Bus=3D01 Lev=3D01 Prnt=3D07 Cnt=3D01 Dev#=3D13 Spd=3D480 Mxch=3D 2
=20
From the ./TestLibusb, I have the bus->dirname =3D 001 and the
dev->filename =3D 013.=20
From 001/013, I would like to be able to have the others parameters Lev,
Prnt and Cnt.
=20
Is there already a function that could be easily add to the "Libusb" ???
=20
Thank you
Martin
PS: Johannes. I don't see the 4Kytes size of Bulk limitation that I had
on a usb1.1 platform a few weeks ago with the 2.6.5-1 kernel running on
a Dell PC.
=20
------- Reply to the query-----------------------------------
=20
=20
try this
#include <linux/usb.h>
#include <linux/usbdevice_fs.h>
=20
struct usbdevfs_hub_portinfo* hubPortInfo
struct usbdevfs_ioctl command =3D {0};
command.ifno =3D 0;
command.ioctl_code =3D USBDEVFS_HUB_PORTINFO;
command.data =3D (void*)hubPortInfo;
errno =3D 0;
int fd =3D open(" some USB Hub"); // say /proc/bus/usb/001
int ret =3D ioctl(fd,USBDEVFS_IOCTL,&command); // this call is for =
USB
hubs
=20
for (int nCntr=3D0;nCntr<hubPortInfo.nports;nCntr++) {
printf("%03d\n",hubPortInfo.port[nCntr]);
}
=20
structure usbdevfs_hub_portinfo has two elements: int nports and char
port[]
=20
second element is char array, which gives device num of every usb device
connected to the hub on which this ioctl is called. read that array and
compare it with device num you got from /proc/bus/usb/devices file.
Whereas nports element gives total number of ports on the hub. You can
iterate thru these number of ports and check for every char position in
array (port), if it is not 0, then there is a device located there.
|