SANEI 1.3.1.76-0750
|
This file provides a generic USB interface. More...
Go to the source code of this file.
USB directions | |
#define | USB_DIR_OUT 0x00 |
Check if sanei_usb_set_timeout() is available. | |
#define | USB_DIR_IN 0x80 |
Check if sanei_usb_set_timeout() is available. | |
#define | HAVE_SANEI_USB_SET_TIMEOUT |
Check if sanei_usb_set_timeout() is available. | |
#define | HAVE_SANEI_USB_CLEAR_HALT |
Check if sanei_usb_clear_halt() is available. | |
SANE_Status | sanei_usb_testing_enable_replay (SANE_String_Const path, int development_mode) |
Initialize sanei_usb for replay testing. More... | |
SANE_Status | sanei_usb_testing_enable_record (SANE_String_Const path, SANE_String_Const be_name) |
Initialize sanei_usb for recording. More... | |
SANE_String | sanei_usb_testing_get_backend (void) |
Returns backend name for testing. More... | |
SANE_Bool | sanei_usb_is_replay_mode_enabled (void) |
Returns SANE_TRUE if replay testing mode is enabled, i.e. More... | |
void | sanei_usb_testing_record_clear (void) |
Clears currently recorded data. More... | |
void | sanei_usb_testing_record_message (SANE_String_Const message) |
Records a debug message in the captured USB data if testing mode is enabled. More... | |
void | sanei_usb_init (void) |
Initialize sanei_usb. More... | |
void | sanei_usb_exit (void) |
End sanei_usb use, freeing resources when needed. More... | |
void | sanei_usb_scan_devices (void) |
Search for USB devices. More... | |
SANE_Status | sanei_usb_get_vendor_product_byname (SANE_String_Const devname, SANE_Word *vendor, SANE_Word *product) |
Get the vendor and product ids by device name. More... | |
SANE_Status | sanei_usb_get_vendor_product (SANE_Int dn, SANE_Word *vendor, SANE_Word *product) |
Get the vendor and product ids. More... | |
SANE_Status | sanei_usb_find_devices (SANE_Int vendor, SANE_Int product, SANE_Status(*attach)(SANE_String_Const devname)) |
Find devices that match given vendor and product ids. More... | |
SANE_Status | sanei_usb_open (SANE_String_Const devname, SANE_Int *dn) |
Open a USB device. More... | |
void | sanei_usb_set_endpoint (SANE_Int dn, SANE_Int ep_type, SANE_Int ep) |
Set the endpoint for the USB communication. More... | |
SANE_Int | sanei_usb_get_endpoint (SANE_Int dn, SANE_Int ep_type) |
Retrieve the endpoint used for the USB communication. More... | |
void | sanei_usb_close (SANE_Int dn) |
Close a USB device. More... | |
void | sanei_usb_set_timeout (SANE_Int timeout) |
Set the libusb timeout for bulk and interrupt reads. More... | |
SANE_Status | sanei_usb_clear_halt (SANE_Int dn) |
Clear halt condition on bulk endpoints. More... | |
SANE_Status | sanei_usb_reset (SANE_Int dn) |
Reset device. More... | |
SANE_Status | sanei_usb_read_bulk (SANE_Int dn, SANE_Byte *buffer, size_t *size) |
Initiate a bulk transfer read. More... | |
SANE_Status | sanei_usb_write_bulk (SANE_Int dn, const SANE_Byte *buffer, size_t *size) |
Initiate a bulk transfer write. More... | |
SANE_Status | sanei_usb_control_msg (SANE_Int dn, SANE_Int rtype, SANE_Int req, SANE_Int value, SANE_Int index, SANE_Int len, SANE_Byte *data) |
Send/receive a control message to/from a USB device. More... | |
SANE_Status | sanei_usb_read_int (SANE_Int dn, SANE_Byte *buffer, size_t *size) |
Initiate a interrupt transfer read. More... | |
void | sanei_usb_attach_matching_devices (const char *name, SANE_Status(*attach)(const char *dev)) |
Expand device name patterns into a list of devices. More... | |
SANE_Status | sanei_usb_set_configuration (SANE_Int dn, SANE_Int configuration) |
Initiate set configuration. More... | |
SANE_Status | sanei_usb_claim_interface (SANE_Int dn, SANE_Int interface_number) |
Initiate claim interface. More... | |
SANE_Status | sanei_usb_release_interface (SANE_Int dn, SANE_Int interface_number) |
Initiate release interface. More... | |
SANE_Status | sanei_usb_set_altinterface (SANE_Int dn, SANE_Int alternate) |
Initiate a set altinterface. More... | |
SANE_Status | sanei_usb_get_descriptor (SANE_Int dn, struct sanei_usb_dev_descriptor *desc) |
Get some information from the device descriptor. More... | |
This file provides a generic USB interface.
Currently, two access methods to USB devices are provided:
A general remark: Do not mix sanei_usb functions with "normal" file-related libc functions like open() or close. The device numbers used in sanei_usb are not file descriptors.
SANE_Status sanei_usb_testing_enable_replay | ( | SANE_String_Const | path, |
int | development_mode | ||
) |
Initialize sanei_usb for replay testing.
Initializes sanei_usb for testing by mocking whole USB stack. This function must be called before sanei_usb_init().
The sanei_usb subsystem also implements a "development mode". It modifies the XML data file with the actual commands of the test run and attempts to proceed testing until a mismatching input command is found for which input data is required.
A <known_commands_end> node in the data XML file will cause sanei_usb not to continue to the subsequent command in the XML file and instead it will prepend all output commands before that node before an output command is encountered.
path | Path to the XML data file. |
development_mode | Enables development mode. |
SANE_Status sanei_usb_testing_enable_record | ( | SANE_String_Const | path, |
SANE_String_Const | be_name | ||
) |
Initialize sanei_usb for recording.
Initializes sanei_usb for recording communication with the scanner. This function must be called before sanei_usb_init().
path | Path to the XML data file. |
be_name | The name of the backend to enable recording for. |
SANE_String sanei_usb_testing_get_backend | ( | void | ) |
Returns backend name for testing.
Returns backend name for the file registered in sanei_usb_testing_enable. The caller is responsible for freeing it.
SANE_Bool sanei_usb_is_replay_mode_enabled | ( | void | ) |
Returns SANE_TRUE if replay testing mode is enabled, i.e.
whether we are working with fake scan data.
void sanei_usb_testing_record_clear | ( | void | ) |
Clears currently recorded data.
This is useful on certain backends to clear the currently recorded data if it relates to other devices than the one that the scan will be performed on. On these backends all devices that the backend supports are opened multiple times. Recording this interaction to XML file makes it impossible to replay it, as the existence of these devices is not mocked currently.
This function may only be called when no USB devices are open, otherwise the behavior is unpredictable.
void sanei_usb_testing_record_message | ( | SANE_String_Const | message | ) |
Records a debug message in the captured USB data if testing mode is enabled.
If testing mode is not enabled, this function does nothing.
msg | Message to record |
void sanei_usb_init | ( | void | ) |
Initialize sanei_usb.
Call this before any other sanei_usb function.
void sanei_usb_exit | ( | void | ) |
End sanei_usb use, freeing resources when needed.
When the use count of sanei_usb reach 0, free resources and end sanei_usb use.
void sanei_usb_scan_devices | ( | void | ) |
Search for USB devices.
Search USB buses for scanner devices.
SANE_Status sanei_usb_get_vendor_product_byname | ( | SANE_String_Const | devname, |
SANE_Word * | vendor, | ||
SANE_Word * | product | ||
) |
Get the vendor and product ids by device name.
devname | |
vendor | vendor id |
product | product id |
SANE_Status sanei_usb_get_vendor_product | ( | SANE_Int | dn, |
SANE_Word * | vendor, | ||
SANE_Word * | product | ||
) |
Get the vendor and product ids.
Currently, only libusb devices and scanners supported by the Linux USB scanner module can be found. For the latter method, the Linux version must be 2.4.8 or higher.
dn | device number of an already sanei_usb_opened device |
vendor | vendor id |
product | product id |
SANE_Status sanei_usb_find_devices | ( | SANE_Int | vendor, |
SANE_Int | product, | ||
SANE_Status(*)(SANE_String_Const devname) | attach | ||
) |
Find devices that match given vendor and product ids.
For limitations, see function sanei_usb_get_vendor_product(). The function attach is called for every device which has been found.
vendor | vendor id |
product | product id |
attach | attach function |
SANE_Status sanei_usb_open | ( | SANE_String_Const | devname, |
SANE_Int * | dn | ||
) |
Open a USB device.
The device is opened by its name devname and the device number is returned in dn on success.
Device names can be either device file names for direct access over kernel drivers (like /dev/usb/scanner) or libusb names. The libusb format looks like this: "libusb:bus-id:device-id". Bus-id and device-id are platform-dependent. An example could look like this: "libusb:001:002" (Linux).
devname | name of the device to open |
dn | device number |
void sanei_usb_set_endpoint | ( | SANE_Int | dn, |
SANE_Int | ep_type, | ||
SANE_Int | ep | ||
) |
Set the endpoint for the USB communication.
Allows to switch to a different endpoint for the USB communication than the default (auto-detected) endpoint. This function can only be called after sanei_usb_open.
dn | device number |
ep_type | type of endpoint to set (bitwise or of USB_DIR_IN/OUT and USB_ENDPOINT_TYPE_BULK/CONTROL/INTERRUPT/ISOCHRONOUS |
ep | endpoint to use for the given type |
SANE_Int sanei_usb_get_endpoint | ( | SANE_Int | dn, |
SANE_Int | ep_type | ||
) |
Retrieve the endpoint used for the USB communication.
Returns the endpoint used for the USB communication of the given type. This function can only be called after sanei_usb_open.
dn | device number |
ep_type | type of endpoint to retrieve (bitwise or of USB_DIR_IN/OUT and USB_ENDPOINT_TYPE_BULK/CONTROL/INTERRUPT/ISOCHRONOUS |
void sanei_usb_close | ( | SANE_Int | dn | ) |
Close a USB device.
dn | device number |
void sanei_usb_set_timeout | ( | SANE_Int | timeout | ) |
Set the libusb timeout for bulk and interrupt reads.
timeout | the new timeout in ms |
SANE_Status sanei_usb_clear_halt | ( | SANE_Int | dn | ) |
Clear halt condition on bulk endpoints.
dn | device number |
SANE_Status sanei_usb_reset | ( | SANE_Int | dn | ) |
Reset device.
dn | device number |
SANE_Status sanei_usb_read_bulk | ( | SANE_Int | dn, |
SANE_Byte * | buffer, | ||
size_t * | size | ||
) |
Initiate a bulk transfer read.
Read up to size bytes from the device to buffer. After the read, size contains the number of bytes actually read.
dn | device number |
buffer | buffer to store read data in |
size | size of the data |
SANE_Status sanei_usb_write_bulk | ( | SANE_Int | dn, |
const SANE_Byte * | buffer, | ||
size_t * | size | ||
) |
Initiate a bulk transfer write.
Write up to size bytes from buffer to the device. After the write size contains the number of bytes actually written.
dn | device number |
buffer | buffer to write to device |
size | size of the data |
SANE_Status sanei_usb_control_msg | ( | SANE_Int | dn, |
SANE_Int | rtype, | ||
SANE_Int | req, | ||
SANE_Int | value, | ||
SANE_Int | index, | ||
SANE_Int | len, | ||
SANE_Byte * | data | ||
) |
Send/receive a control message to/from a USB device.
This function is only supported for libusb devices and kernel access with Linux 2.4.13 and newer. For a detailed explanation of the parameters, have a look at the USB specification at the www.usb.org developers information page.
dn | device number |
rtype | specifies the characteristics of the request (e.g. data direction) |
req | actual request |
value | parameter specific to the request |
index | parameter specific to the request (often used to select endpoint) |
len | length of data to send/receive |
data | buffer to send/receive data |
SANE_Status sanei_usb_read_int | ( | SANE_Int | dn, |
SANE_Byte * | buffer, | ||
size_t * | size | ||
) |
Initiate a interrupt transfer read.
Read up to size bytes from the interrupt endpoint from the device to buffer. After the read, size contains the number of bytes actually read.
dn | device number |
buffer | buffer to store read data in |
size | size of the data |
void sanei_usb_attach_matching_devices | ( | const char * | name, |
SANE_Status(*)(const char *dev) | attach | ||
) |
Expand device name patterns into a list of devices.
Apart from a normal device name (such as /dev/usb/scanner0 or libusb:002:003), this function currently supports USB device specifications of the form:
usb VENDOR PRODUCT
VENDOR and PRODUCT are non-negative integer numbers in decimal or hexadecimal format. A similar function for SCSI devices can be found in include/sane/config.h.
name | device name pattern |
attach | attach function |
SANE_Status sanei_usb_set_configuration | ( | SANE_Int | dn, |
SANE_Int | configuration | ||
) |
Initiate set configuration.
Change set configuration
dn | device number |
configuration,configuration | nummber |
SANE_Status sanei_usb_claim_interface | ( | SANE_Int | dn, |
SANE_Int | interface_number | ||
) |
Initiate claim interface.
Change claim interface
dn | device number |
interface_number | interface number |
SANE_Status sanei_usb_release_interface | ( | SANE_Int | dn, |
SANE_Int | interface_number | ||
) |
Initiate release interface.
Change release interface
dn | device number |
interface_number | interface number |
SANE_Status sanei_usb_set_altinterface | ( | SANE_Int | dn, |
SANE_Int | alternate | ||
) |
Initiate a set altinterface.
Change set alternate
dn | device number |
alternate,alternate | nummber |
SANE_Status sanei_usb_get_descriptor | ( | SANE_Int | dn, |
struct sanei_usb_dev_descriptor * | desc | ||
) |
Get some information from the device descriptor.
Sometimes it's useful to know something about revisions and other stuff reported by the USB system
dn | device number |
desc | where to put the information to |