[sane-devel] HP ScanJet 5590 big endian

Nhan Ngo Dinh nngodinh at tiscali.it
Tue May 22 16:27:57 UTC 2012


Hello,

I've been trying to connect an HP ScanJet 5590 to an Atheros AR7241 rev 
1 system (MIPS 24Kc V7.4 CPU), using OpenWrt. The CPU is big endian. I 
got the error:

[hp5590] hp5590_get_ack
[sanei_usb] sanei_usb_control_msg: rtype = 0xc0, req = 12, value = 142, 
index = 32, len = 1
USB error: error sending control message: Connection timed out
[sanei_usb] sanei_usb_control_msg: libusb complained: error sending 
control message: Connection timed out
[hp5590] hp5590_get_ack: USB-in-USB: error getting acknowledge

Using SANE_DEBUG_SANEI_USB=255 and SANE_DEBUG_HP5590=255 I got exactly 
the same result (even print_buffer() output was the same) as another 
user who tried to use this backend on a PPC (see this post: 
http://lists.alioth.debian.org/pipermail/sane-devel/2010-June/026900.html).

So I tried to run the same device under a little endian platform and I 
saw a difference:

Little Endian (working)
=======================
[hp5590] hp5590_init_scanner
[hp5590] hp5590_cmd: USB-in-USB: command : 0012
[hp5590] hp5590_control_msg: USB-in-USB: core data: no
[hp5590] hp5590_control_msg: USB-in-USB: sending control msg
[sanei_usb] sanei_usb_control_msg: rtype = 0x40, req = 4, value = 143, 
index = 0, len = 8
[sanei_usb] 0000: C0 04 00 12 00 00 32 00

Big Endian (not working)
========================
[hp5590] hp5590_init_scanner
[hp5590] hp5590_cmd: USB-in-USB: command : 0012
[hp5590] hp5590_control_msg: USB-in-USB: core data: no
[hp5590] hp5590_control_msg: USB-in-USB: sending control msg
[sanei_usb] sanei_usb_control_msg: rtype = 0x40, req = 4, value = 143, 
index = 0, len = 8
[sanei_usb] 000 C0 04 00 12 00 00 00 32

There is a difference in the version of the backend (1.0.19 for little 
endian, 1.0.22 for big endian), so the output is not exactly identical, 
but in the last line you see that the last two bytes are swapped. This 
goes to hp5590_control_msg(), in hp5590_low.c line 251 and line 323 
(version 1.0.22):

246: memset (&ctrl, 0, sizeof (ctrl));
247: ctrl.bRequestType = 0xc0;
248: ctrl.bRequest = request;
249: ctrl.wValue = htons (value);
250: ctrl.wIndex = htons (index);
251: ctrl.wLength = size;

Since the module does work in little endian, and the content of ctrl is 
passed through, I assume that the hardware wants ctrl.wLength in little 
endian, so I replaced it with:

ctrl.wLength = htole16 (size);

Then, in hp5590_verify_last_cmd(), the code calls hp5590_control_msg() 
to retrieve a uint16_t buffer (line 469) to read it as it is returned 
without any byte swap (line 477). To correct this I've added the same 
command as above, assuming that the hardware does return a little endian 
16-bit value:

verify_cmd = le16toh (verify_cmd);

I've tested the scanner with such modification and it works, but I've 
not tested it for regressions in little endian. The patch is attached.

Regards,
Nhan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/sane-devel/attachments/20120522/47ff5a10/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 099-swap-bigendian-size.patch
Type: text/x-patch
Size: 1059 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/sane-devel/attachments/20120522/47ff5a10/attachment.bin>


More information about the sane-devel mailing list