Re: COMPAT_32BIT libusb ABI problem

2013-07-25 Thread Damjan Jovanovic
On Thu, Jul 25, 2013 at 6:11 AM, Hans Petter Selasky h...@bitfrost.no wrote:
 On 07/24/13 22:09, Damjan Jovanovic wrote:

 Hi

 The ioctl:
 #define USB_FS_INIT _IOW ('U', 195, struct usb_fs_init)
 when used by a COMPAT_32BIT libusb on amd64, fails (causing
 libusb_open() to fail) due to:

 freebsd32_ioctl(0x6,0x800c55c3,0xc710,0x0,0x0,0x0) ERR#25
 'Inappropriate ioctl for device'
 but when hacked a bit:
 freebsd32_ioctl(0x6,0x801055c3,0xc710,0x0,0x0,0x0) = 0 (0x0)

 because sizeof(struct usb_fs_init) is 12 bytes on i386, and 16 bytes on
 amd64.

 But the failure of even libusb_open() - a fundamental libusb function
 - must mean that the COMPAT_32BIT libusb never worked. Can we please
 take this opportunity to kill it and do a real 32 bit compatibility
 layer in the kernel that will work from 32 bit chroots and statically
 linked 32 bit binaries? I'll help.


 Hi,

 How did you compile it? Is the structure the same size, compiled with GCC
 and LLVM?

GCC 4.2.1
gcc file.c -o file -lusb in a 32 bit chroot = 12 bytes
gcc file.c -o file -lusb 64 bit = 16 bytes

Clang 3.1
clang file.c -o file -lusb in a 32 bit chroot = 12 bytes
clang file.c -o file -lusb 64 bit = 16 bytes

The uint8_t ep_index_max field at the end of struct usb_fs_init must
be getting padded to a 4 byte boundary on 32 bit, and 8 byte boundary
on 64 bit.

 The LIB32 for USB has been tested. I did a quick test and found on 9-stable:

 cc -m32 -I . -L /usr/lib32 -lusb usbconfig.c dump.c
 env LD_PRELOAD=/usr/lib32/libusb.so ./a.out
 ugen0.1: UHCI root HUB Intel at usbus0, cfg=0 md=HOST spd=FULL (12Mbps)
 pwr=SAVE (0mA)
 ugen1.1: UHCI root HUB Intel at usbus1, cfg=0 md=HOST spd=FULL (12Mbps)
 pwr=SAVE (0mA)

 ...

But usbconfig uses the libusb20 API and never seems to get to that broken ioctl.

 Your approach requires much more code. It is not just about some structures,
 but also about code accessing those structures. Feel free to submit a patch
 however.

I'll see what I can do.

 I would rather fix this by adding the proper __aligned() to the structures
 in question.

Do that in the meanwhile?

 --HPS


Damjan
___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org


COMPAT_32BIT libusb ABI problem

2013-07-24 Thread Damjan Jovanovic
Hi

The ioctl:
#define USB_FS_INIT _IOW ('U', 195, struct usb_fs_init)
when used by a COMPAT_32BIT libusb on amd64, fails (causing
libusb_open() to fail) due to:

freebsd32_ioctl(0x6,0x800c55c3,0xc710,0x0,0x0,0x0) ERR#25
'Inappropriate ioctl for device'
but when hacked a bit:
freebsd32_ioctl(0x6,0x801055c3,0xc710,0x0,0x0,0x0) = 0 (0x0)

because sizeof(struct usb_fs_init) is 12 bytes on i386, and 16 bytes on amd64.

But the failure of even libusb_open() - a fundamental libusb function
- must mean that the COMPAT_32BIT libusb never worked. Can we please
take this opportunity to kill it and do a real 32 bit compatibility
layer in the kernel that will work from 32 bit chroots and statically
linked 32 bit binaries? I'll help.

Regards
Damjan
___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org


usb/177897: [u3g][patch] add support for the Huawei E352 modem

2013-04-17 Thread Damjan Jovanovic

Number: 177897
Category:   usb
Synopsis:   [u3g][patch] add support for the Huawei E352 modem
Confidential:   no
Severity:   non-critical
Priority:   low
Responsible:freebsd-usb
State:  open
Quarter:
Keywords:   
Date-Required:
Class:  change-request
Submitter-Id:   current-users
Arrival-Date:   Wed Apr 17 06:50:00 UTC 2013
Closed-Date:
Last-Modified:
Originator: Damjan Jovanovic
Release:PCBSD 9.1
Organization:
Environment:
FreeBSD pcbsd-2516 9.1-RELEASE-p2 FreeBSD 9.1-RELEASE-p2 #9 r249522M: Wed Apr 
17 07:59:19 SAST 2013 root@pcbsd-2516:/usr/obj/usr/src/sys/U3GTEST  amd64
Description:
Add support for the Huawei E352 3G modem, and get u3g to reset it from 
mass-storage device to a 3G modem which can be dialled using /dev/cuaU0.0.

A new SCSI reset command had to be added for this, as using the old 
U3GINIT_HUAWEISCSI command turns the device into a broken Huawei E173 instead.

How-To-Repeat:

Fix:


Patch attached with submission follows:

Index: sys/dev/usb/quirk/usb_quirk.c
===
--- sys/dev/usb/quirk/usb_quirk.c   (revision 249522)
+++ sys/dev/usb/quirk/usb_quirk.c   (working copy)
@@ -532,6 +532,7 @@
[UQ_BAD_MIDI]   = UQ_BAD_MIDI,
[UQ_AU_VENDOR_CLASS]= UQ_AU_VENDOR_CLASS,
[UQ_SINGLE_CMD_MIDI]= UQ_SINGLE_CMD_MIDI,
+   [UQ_MSC_EJECT_HUAWEISCSI2]  = UQ_MSC_EJECT_HUAWEISCSI2,
 };
 
 /**
Index: sys/dev/usb/quirk/usb_quirk.h
===
--- sys/dev/usb/quirk/usb_quirk.h   (revision 249522)
+++ sys/dev/usb/quirk/usb_quirk.h   (working copy)
@@ -104,6 +104,8 @@
UQ_AU_VENDOR_CLASS, /* audio device uses vendor and not audio class 
*/
UQ_SINGLE_CMD_MIDI, /* at most one command per USB packet */
 
+   UQ_MSC_EJECT_HUAWEISCSI2,   /* ejects after another Huawei SCSI 
command */
+
USB_QUIRK_MAX
 };
 
Index: sys/dev/usb/serial/u3g.c
===
--- sys/dev/usb/serial/u3g.c(revision 249522)
+++ sys/dev/usb/serial/u3g.c(working copy)
@@ -95,6 +95,7 @@
 #defineU3GINIT_SAEL_M460   8   /* Requires vendor init */
 #defineU3GINIT_HUAWEISCSI  9   /* Requires Huawei SCSI init 
command */
 #defineU3GINIT_TCT 10  /* Requires TCT Mobile init 
command */
+#defineU3GINIT_HUAWEISCSI2 11  /* Requires another Huawei SCSI 
init command */
 
 enum {
U3G_BULK_WR,
@@ -285,6 +286,8 @@
U3G_DEV(HUAWEI, E180V, U3GINIT_HUAWEI),
U3G_DEV(HUAWEI, E220, U3GINIT_HUAWEI),
U3G_DEV(HUAWEI, E220BIS, U3GINIT_HUAWEI),
+   U3G_DEV(HUAWEI, E352, 0),
+   U3G_DEV(HUAWEI, E352_INIT, U3GINIT_HUAWEISCSI2),
U3G_DEV(HUAWEI, MOBILE, U3GINIT_HUAWEI),
U3G_DEV(HUAWEI, E1752, U3GINIT_HUAWEISCSI),
U3G_DEV(HUAWEI, E1820, U3GINIT_HUAWEISCSI),
@@ -683,6 +686,8 @@
method = U3GINIT_WAIT;
else if (usb_test_quirk(uaa, UQ_MSC_EJECT_HUAWEISCSI))
method = U3GINIT_HUAWEISCSI;
+   else if (usb_test_quirk(uaa, UQ_MSC_EJECT_HUAWEISCSI2))
+   method = U3GINIT_HUAWEISCSI2;
else if (usb_test_quirk(uaa, UQ_MSC_EJECT_TCT))
method = U3GINIT_TCT;
else if (usbd_lookup_id_by_uaa(u3g_devs, sizeof(u3g_devs), uaa) == 0)
@@ -703,6 +708,9 @@
case U3GINIT_HUAWEISCSI:
error = usb_msc_eject(udev, 0, MSC_EJECT_HUAWEI);
break;
+   case U3GINIT_HUAWEISCSI2:
+   error = usb_msc_eject(udev, 0, MSC_EJECT_HUAWEI2);
+   break;
case U3GINIT_SCSIEJECT:
error = usb_msc_eject(udev, 0, MSC_EJECT_STOPUNIT);
break;
Index: sys/dev/usb/usb_msctest.c
===
--- sys/dev/usb/usb_msctest.c   (revision 249522)
+++ sys/dev/usb/usb_msctest.c   (working copy)
@@ -98,6 +98,9 @@
 static uint8_t scsi_huawei_eject[] =   { 0x11, 0x06, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00 };
+static uint8_t scsi_huawei_eject2[] =  { 0x11, 0x06, 0x20, 0x00, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00 };
 static uint8_t scsi_tct_eject[] =  { 0x06, 0xf5, 0x04, 0x02, 0x52, 0x70 };
 static uint8_t scsi_sync_cache[] = { 0x35, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00 };
@@ -781,6 +784,11 @@
scsi_huawei_eject, sizeof