LEFT | RIGHT |
1 /* sane - Scanner Access Now Easy. | 1 /* sane - Scanner Access Now Easy. |
2 Copyright (C) 2001, 2002 Henning Meier-Geinitz | 2 Copyright (C) 2001, 2002 Henning Meier-Geinitz |
3 Copyright (C) 2003, 2005 Rene Rebe (sanei_read_int,sanei_set_timeout) | 3 Copyright (C) 2003, 2005 Rene Rebe (sanei_read_int,sanei_set_timeout) |
4 Copyright (C) 2008 m. allan noah (sanei_usb_clear_halt) | 4 Copyright (C) 2008 m. allan noah (sanei_usb_clear_halt) |
5 This file is part of the SANE package. | 5 This file is part of the SANE package. |
6 | 6 |
7 SANE is free software; you can redistribute it and/or modify it | 7 SANE is free software; you can redistribute it and/or modify it |
8 under the terms of the GNU General Public License as published by | 8 under the terms of the GNU General Public License as published by |
9 the Free Software Foundation; either version 2 of the License, or | 9 the Free Software Foundation; either version 2 of the License, or |
10 (at your option) any later version. | 10 (at your option) any later version. |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 * @param vendor vendor id | 223 * @param vendor vendor id |
224 * @param product product id | 224 * @param product product id |
225 * @param attach attach function | 225 * @param attach attach function |
226 * | 226 * |
227 * @return SANE_STATUS_GOOD - on success (even if no scanner was found) | 227 * @return SANE_STATUS_GOOD - on success (even if no scanner was found) |
228 */ | 228 */ |
229 extern SANE_Status | 229 extern SANE_Status |
230 sanei_usb_find_devices (SANE_Int vendor, SANE_Int product, | 230 sanei_usb_find_devices (SANE_Int vendor, SANE_Int product, |
231 SANE_Status (*attach) (SANE_String_Const devname)); | 231 SANE_Status (*attach) (SANE_String_Const devname)); |
232 | 232 |
233 /** Callback function to specify default USB endpoints for sanei_usb_open | |
234 * | |
235 * @param ep_typ type of endpoint (or'ed from USB_DIR_IN/USB_DIR_OUT and | |
236 * one USB_ENDPOINT_TYPE_* value) | |
237 * @return default USB endpoint to override auto-detection for given type, 0 | |
238 * to use results of the auto-detection | |
239 */ | |
240 typedef SANE_Int (*sanei_usb_default_endpoint_callback) (SANE_Int ep_type); | |
241 | |
242 /** Open a USB device. | 233 /** Open a USB device. |
243 * | 234 * |
244 * The device is opened by its name devname and the device number is | 235 * The device is opened by its name devname and the device number is |
245 * returned in dn on success.·· | 236 * returned in dn on success.·· |
246 * | |
247 * Device names can be either device file names for direct access over | |
248 * kernel drivers (like /dev/usb/scanner) or libusb names. The libusb format | |
249 * looks like this: "libusb:bus-id:device-id". Bus-id and device-id are | |
250 * platform-dependent. An example could look like this: "libusb:001:002" | |
251 * (Linux). Internally, sanei_usb_open_extended is called with a NULL callback | |
252 * function. | |
253 * | |
254 * @param devname name of the device to open | |
255 * @param dn device number | |
256 * | |
257 * @return | |
258 * - SANE_STATUS_GOOD - on success | |
259 * - SANE_STATUS_ACCESS_DENIED - if the file couldn't be accessed due to | |
260 * permissions | |
261 * - SANE_STATUS_INVAL - on every other error | |
262 */ | |
263 extern SANE_Status sanei_usb_open (SANE_String_Const devname, SANE_Int * dn); | |
264 | |
265 /** Open a USB device. | |
266 * | |
267 * The device is opened by its name devname and the device number is | |
268 * returned in dn on success. | |
269 * | 237 * |
270 * Device names can be either device file names for direct access over | 238 * Device names can be either device file names for direct access over |
271 * kernel drivers (like /dev/usb/scanner) or libusb names. The libusb format | 239 * kernel drivers (like /dev/usb/scanner) or libusb names. The libusb format |
272 * looks like this: "libusb:bus-id:device-id". Bus-id and device-id are | 240 * looks like this: "libusb:bus-id:device-id". Bus-id and device-id are |
273 * platform-dependent. An example could look like this: "libusb:001:002" | 241 * platform-dependent. An example could look like this: "libusb:001:002" |
274 * (Linux). | 242 * (Linux). |
275 * By default, the first endpoint encountered for each of the available USB | |
276 * endpoint types (bulk IN/OUT, iso IN/OUT, interrupt IN/OUT and control | |
277 * IN/OUT) is auto-detected. Other default endpoints can be set with the | |
278 * callback function. | |
279 * | 243 * |
280 * @param devname name of the device to open | 244 * @param devname name of the device to open |
281 * @param dn device number | 245 * @param dn device number |
282 * @param callback sanei_usb_default_endpoint_callback to override the | |
283 * auto-detection of the USB endpoints | |
284 * | 246 * |
285 * @return | 247 * @return |
286 * - SANE_STATUS_GOOD - on success | 248 * - SANE_STATUS_GOOD - on success |
287 * - SANE_STATUS_ACCESS_DENIED - if the file couldn't be accessed due to | 249 * - SANE_STATUS_ACCESS_DENIED - if the file couldn't be accessed due to |
288 * permissions | 250 * permissions |
289 * - SANE_STATUS_INVAL - on every other error | 251 * - SANE_STATUS_INVAL - on every other error |
290 */ | 252 */ |
291 extern SANE_Status | 253 extern SANE_Status sanei_usb_open (SANE_String_Const devname, SANE_Int * dn); |
292 sanei_usb_open_extended (SANE_String_Const devname, SANE_Int * dn, | 254 |
293 sanei_usb_default_endpoint_callback callback); | 255 /** Set the endpoint for the USB communication |
| 256 * |
| 257 * Allows to switch to a different endpoint for the USB communication than |
| 258 * the default (auto-detected) endpoint. This function can only be called |
| 259 * after sanei_usb_open. |
| 260 * |
| 261 * @param dn device number |
| 262 * @param ep_type type of endpoint to set (bitwise or of USB_DIR_IN/OUT and |
| 263 * USB_ENDPOINT_TYPE_BULK/CONTROL/INTERRUPT/ISOCHRONOUS |
| 264 * @param ep endpoint to use for the given type |
| 265 * |
| 266 */ |
| 267 extern void sanei_usb_set_endpoint (SANE_Int dn, SANE_Int ep_type, SANE_Int ep); |
294 | 268 |
295 /** Close a USB device. | 269 /** Close a USB device. |
296 *· | 270 *· |
297 * @param dn device number | 271 * @param dn device number |
298 */ | 272 */ |
299 extern void sanei_usb_close (SANE_Int dn); | 273 extern void sanei_usb_close (SANE_Int dn); |
300 | 274 |
301 /** Set the libusb timeout for bulk and interrupt reads. | 275 /** Set the libusb timeout for bulk and interrupt reads. |
302 *· | 276 *· |
303 * @param timeout the new timeout in ms | 277 * @param timeout the new timeout in ms |
304 */ | 278 */ |
305 extern void sanei_usb_set_timeout (SANE_Int timeout); | 279 extern void sanei_usb_set_timeout (SANE_Int timeout); |
306 | 280 |
307 /** Check if sanei_usb_set_timeout() is available. | 281 /** Check if sanei_usb_set_timeout() is available. |
308 */ | 282 */ |
309 #define HAVE_SANEI_USB_SET_TIMEOUT | 283 #define HAVE_SANEI_USB_SET_TIMEOUT |
310 | 284 |
311 /** Clear halt condition on bulk endpoints | 285 /** Clear halt condition on bulk endpoints |
312 * | 286 *· |
313 * Internally, sanei_usb_clear is called with endpoints -1. The default | |
314 * endpoints detected during sanei_usb_open are used in that case. | |
315 * | |
316 * @param dn device number | 287 * @param dn device number |
317 */ | 288 */ |
318 extern SANE_Status sanei_usb_clear_halt (SANE_Int dn); | 289 extern SANE_Status sanei_usb_clear_halt (SANE_Int dn); |
319 | |
320 /** Clear halt condition on bulk endpoints | |
321 * | |
322 * @param dn device number | |
323 * @param in_ep bulk-in endpoint | |
324 * @param out_ep bulk-out endpoint | |
325 */ | |
326 extern SANE_Status sanei_usb_clear_halt_extended (SANE_Int dn, SANE_Int in_ep, S
ANE_Int out_ep); | |
327 | 290 |
328 /** Check if sanei_usb_clear_halt() is available. | 291 /** Check if sanei_usb_clear_halt() is available. |
329 */ | 292 */ |
330 #define HAVE_SANEI_USB_CLEAR_HALT | 293 #define HAVE_SANEI_USB_CLEAR_HALT |
331 | 294 |
332 /** Reset device | 295 /** Reset device |
333 *· | 296 *· |
334 * @param dn device number | 297 * @param dn device number |
335 */ | 298 */ |
336 extern SANE_Status sanei_usb_reset (SANE_Int dn); | 299 extern SANE_Status sanei_usb_reset (SANE_Int dn); |
337 | 300 |
338 /** Initiate a bulk transfer read. | 301 /** Initiate a bulk transfer read. |
339 * | 302 * |
340 * Read up to size bytes from the device to buffer. After the read, size | 303 * Read up to size bytes from the device to buffer. After the read, size |
341 * contains the number of bytes actually read. | 304 * contains the number of bytes actually read. |
342 * Internally, sanei_usb_read_build_extended is called with ep=-1. The default | |
343 * bulk endpoints detected during sanei_usb_open are used in that case. | |
344 * | 305 * |
345 * @param dn device number | 306 * @param dn device number |
346 * @param buffer buffer to store read data in | 307 * @param buffer buffer to store read data in |
347 * @param size size of the data | 308 * @param size size of the data |
348 * | 309 * |
349 * @return· | 310 * @return· |
350 * - SANE_STATUS_GOOD - on succes | 311 * - SANE_STATUS_GOOD - on succes |
351 * - SANE_STATUS_EOF - if zero bytes have been read | 312 * - SANE_STATUS_EOF - if zero bytes have been read |
352 * - SANE_STATUS_IO_ERROR - if an error occured during the read | 313 * - SANE_STATUS_IO_ERROR - if an error occured during the read |
353 * - SANE_STATUS_INVAL - on every other error | 314 * - SANE_STATUS_INVAL - on every other error |
354 * | 315 * |
355 */ | 316 */ |
356 extern SANE_Status | 317 extern SANE_Status |
357 sanei_usb_read_bulk (SANE_Int dn, SANE_Byte * buffer, size_t * size); | 318 sanei_usb_read_bulk (SANE_Int dn, SANE_Byte * buffer, size_t * size); |
358 | 319 |
359 /** Initiate a bulk transfer read. | |
360 * | |
361 * Read up to size bytes from the device to buffer. After the read, size | |
362 * contains the number of bytes actually read. | |
363 * | |
364 * @param dn device number | |
365 * @param ep bulk-out endpoint | |
366 * @param buffer buffer to store read data in | |
367 * @param size size of the data | |
368 * | |
369 * @return | |
370 * - SANE_STATUS_GOOD - on succes | |
371 * - SANE_STATUS_EOF - if zero bytes have been read | |
372 * - SANE_STATUS_IO_ERROR - if an error occured during the read | |
373 * - SANE_STATUS_INVAL - on every other error | |
374 * | |
375 */ | |
376 extern SANE_Status | |
377 sanei_usb_read_bulk_extended (SANE_Int dn, SANE_Int ep, SANE_Byte * buffer, size
_t * size); | |
378 | |
379 /** Initiate a bulk transfer write. | 320 /** Initiate a bulk transfer write. |
380 * | 321 * |
381 * Write up to size bytes from buffer to the device. After the write size | 322 * Write up to size bytes from buffer to the device. After the write size |
382 * contains the number of bytes actually written. | 323 * contains the number of bytes actually written. |
383 * Internally, sanei_usb_write_bulk_extended is called with ep=-1. The default | |
384 * bulk endpoints detected during sanei_usb_open are used in that case. | |
385 * | 324 * |
386 * @param dn device number | 325 * @param dn device number |
387 * @param buffer buffer to write to device | 326 * @param buffer buffer to write to device |
388 * @param size size of the data | 327 * @param size size of the data |
389 * | 328 * |
390 * @return· | 329 * @return· |
391 * - SANE_STATUS_GOOD - on succes | 330 * - SANE_STATUS_GOOD - on succes |
392 * - SANE_STATUS_IO_ERROR - if an error occured during the write | 331 * - SANE_STATUS_IO_ERROR - if an error occured during the write |
393 * - SANE_STATUS_INVAL - on every other error | 332 * - SANE_STATUS_INVAL - on every other error |
394 */ | 333 */ |
395 extern SANE_Status | 334 extern SANE_Status |
396 sanei_usb_write_bulk (SANE_Int dn, const SANE_Byte * buffer, size_t * size); | 335 sanei_usb_write_bulk (SANE_Int dn, const SANE_Byte * buffer, size_t * size); |
397 | |
398 /** Initiate a bulk transfer write. | |
399 * | |
400 * Write up to size bytes from buffer to the device. After the write size | |
401 * contains the number of bytes actually written. | |
402 * | |
403 * @param dn device number | |
404 * @param ep bulk-out endpoint | |
405 * @param buffer buffer to write to device | |
406 * @param size size of the data | |
407 * | |
408 * @return | |
409 * - SANE_STATUS_GOOD - on succes | |
410 * - SANE_STATUS_IO_ERROR - if an error occured during the write | |
411 * - SANE_STATUS_INVAL - on every other error | |
412 */ | |
413 extern SANE_Status | |
414 sanei_usb_write_bulk_extended (SANE_Int dn, SANE_Int ep, const SANE_Byte * buffe
r, size_t * size); | |
415 | 336 |
416 /** Send/receive a control message to/from a USB device. | 337 /** Send/receive a control message to/from a USB device. |
417 * | 338 * |
418 * This function is only supported for libusb devices and kernel acces with | 339 * This function is only supported for libusb devices and kernel acces with |
419 * Linux 2.4.13 and newer. | 340 * Linux 2.4.13 and newer. |
420 * For a detailed explanation of the parameters, have a look at the USB | 341 * For a detailed explanation of the parameters, have a look at the USB |
421 * specification at the <a href="http://www.usb.org/developers/docs/"> | 342 * specification at the <a href="http://www.usb.org/developers/docs/"> |
422 * www.usb.org developers information page</a>. | 343 * www.usb.org developers information page</a>. |
423 *· | 344 *· |
424 * @param dn device number | 345 * @param dn device number |
(...skipping 14 matching lines...) Expand all Loading... |
439 */ | 360 */ |
440 extern SANE_Status | 361 extern SANE_Status |
441 sanei_usb_control_msg (SANE_Int dn, SANE_Int rtype, SANE_Int req, | 362 sanei_usb_control_msg (SANE_Int dn, SANE_Int rtype, SANE_Int req, |
442 SANE_Int value, SANE_Int index, SANE_Int len, | 363 SANE_Int value, SANE_Int index, SANE_Int len, |
443 SANE_Byte * data); | 364 SANE_Byte * data); |
444 | 365 |
445 /** Initiate a interrupt transfer read. | 366 /** Initiate a interrupt transfer read. |
446 * | 367 * |
447 * Read up to size bytes from the interrupt endpoint from the device to | 368 * Read up to size bytes from the interrupt endpoint from the device to |
448 * buffer. After the read, size contains the number of bytes actually read. | 369 * buffer. After the read, size contains the number of bytes actually read. |
449 * Internally, sanei_usb_read_int_extended is called with ep=-1. The default | |
450 * interrup endpoints detected during sanei_usb_open are used in that case. | |
451 * | 370 * |
452 * @param dn device number | 371 * @param dn device number |
453 * @param buffer buffer to store read data in | 372 * @param buffer buffer to store read data in |
454 * @param size size of the data | 373 * @param size size of the data |
455 * | 374 * |
456 * @return· | 375 * @return· |
457 * - SANE_STATUS_GOOD - on succes | 376 * - SANE_STATUS_GOOD - on succes |
458 * - SANE_STATUS_EOF - if zero bytes have been read | 377 * - SANE_STATUS_EOF - if zero bytes have been read |
459 * - SANE_STATUS_IO_ERROR - if an error occured during the read | 378 * - SANE_STATUS_IO_ERROR - if an error occured during the read |
460 * - SANE_STATUS_INVAL - on every other error | 379 * - SANE_STATUS_INVAL - on every other error |
461 * | 380 * |
462 */ | 381 */ |
463 | 382 |
464 extern SANE_Status | 383 extern SANE_Status |
465 sanei_usb_read_int (SANE_Int dn, SANE_Byte * buffer, size_t * size); | 384 sanei_usb_read_int (SANE_Int dn, SANE_Byte * buffer, size_t * size); |
466 | |
467 /** Initiate a interrupt transfer read. | |
468 * | |
469 * Read up to size bytes from the interrupt endpoint from the device to | |
470 * buffer. After the read, size contains the number of bytes actually read. | |
471 * | |
472 * @param dn device number | |
473 * @param ep bulk-in endpoint | |
474 * @param buffer buffer to store read data in | |
475 * @param size size of the data | |
476 * | |
477 * @return | |
478 * - SANE_STATUS_GOOD - on succes | |
479 * - SANE_STATUS_EOF - if zero bytes have been read | |
480 * - SANE_STATUS_IO_ERROR - if an error occured during the read | |
481 * - SANE_STATUS_INVAL - on every other error | |
482 * | |
483 */ | |
484 | |
485 extern SANE_Status | |
486 sanei_usb_read_int_extended (SANE_Int dn, SANE_Int ep, SANE_Byte * buffer, size_
t * size); | |
487 | 385 |
488 /** Expand device name patterns into a list of devices. | 386 /** Expand device name patterns into a list of devices. |
489 * | 387 * |
490 * Apart from a normal device name (such as /dev/usb/scanner0 or | 388 * Apart from a normal device name (such as /dev/usb/scanner0 or |
491 * libusb:002:003), this function currently supports USB device | 389 * libusb:002:003), this function currently supports USB device |
492 * specifications of the form: | 390 * specifications of the form: |
493 * | 391 * |
494 * usb VENDOR PRODUCT | 392 * usb VENDOR PRODUCT |
495 * | 393 * |
496 * VENDOR and PRODUCT are non-negative integer numbers in decimal or | 394 * VENDOR and PRODUCT are non-negative integer numbers in decimal or |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 * SANE. | 489 * SANE. |
592 * - SANE_STATUS_INVAL - on every other error | 490 * - SANE_STATUS_INVAL - on every other error |
593 * | 491 * |
594 */ | 492 */ |
595 | 493 |
596 extern SANE_Status | 494 extern SANE_Status |
597 sanei_usb_get_descriptor( SANE_Int dn, struct sanei_usb_dev_descriptor *desc ); | 495 sanei_usb_get_descriptor( SANE_Int dn, struct sanei_usb_dev_descriptor *desc ); |
598 | 496 |
599 /*------------------------------------------------------*/ | 497 /*------------------------------------------------------*/ |
600 #endif /* sanei_usb_h */ | 498 #endif /* sanei_usb_h */ |
LEFT | RIGHT |