u3_scsi.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * u3_tool - U3 USB stick manager
  3. * Copyright (C) 2007 Daviedev, daviedev@users.sourceforge.net
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. */
  19. #ifndef __U3_SCSI_H__
  20. #define __U3_SCSI_H__
  21. /**
  22. * @file u3_scsi.h
  23. *
  24. * @description Declare some helper functions to provide a subsystem
  25. * independent way of sending SCSI commands to a U3 device.
  26. */
  27. #include "u3.h"
  28. #define U3_CMD_LEN 12
  29. /**
  30. * Open U3 device
  31. *
  32. * This opens the device addressed by the variable 'which'.
  33. *
  34. * @param device pointer to U3 handle that will be used to access the
  35. * newly openned device.
  36. *
  37. * @returns U3_SUCCESS if successful, else U3_FAILURE and
  38. * an error string can be obtained using u3_error()
  39. */
  40. int u3_open(u3_handle_t *device, const char *which);
  41. /**
  42. * Close U3 device
  43. *
  44. * This closes the u3 device handle pointed to by 'device'
  45. *
  46. * @param device U3 handle
  47. */
  48. void u3_close(u3_handle_t *device);
  49. /**
  50. * dxfer_direction values as used by u3_send_cmd()
  51. *
  52. * @see 'u3_send_cmd()'
  53. */
  54. enum {
  55. U3_DATA_NONE = 0, // dont transfer extra data
  56. U3_DATA_TO_DEV = 1, // send data to device
  57. U3_DATA_FROM_DEV = 2, // read data from device
  58. };
  59. /**
  60. * Execute a scsi command at device
  61. *
  62. * This send the given SCSI CDB in 'cmd' to the device given by 'device'.
  63. * Optional data is transfered from or to the device. The SCSI status as
  64. * returned by the device is placed in 'status'.
  65. *
  66. * @param device U3 handle
  67. * @param cmd SCSI CDB
  68. * @param dxfer_direction Direction of extra data, given by on of the
  69. * U3_DATA_* enum values
  70. * @param dxfer_len Length of extra data
  71. * @param dxfer_data Buffer with extra data
  72. * @param status Pointer to variable to return SCSI status in
  73. *
  74. * @returns U3_SUCCESS if successful, else U3_FAILURE and
  75. * an error string can be obtained using u3_error()
  76. */
  77. int u3_send_cmd(u3_handle_t *device, uint8_t cmd[U3_CMD_LEN],
  78. int dxfer_direction, int dxfer_length, uint8_t *dxfer_data,
  79. uint8_t *status);
  80. #endif // __U3_SCSI_H__