u3_scsi.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. extern const char *u3_subsystem_name;
  30. extern const char *u3_subsystem_help;
  31. /**
  32. * Open U3 device
  33. *
  34. * This opens the device addressed by the variable 'which'.
  35. *
  36. * @param device pointer to U3 handle that will be used to access the
  37. * newly openned device.
  38. *
  39. * @returns U3_SUCCESS if successful, else U3_FAILURE and
  40. * an error string can be obtained using u3_error()
  41. */
  42. int u3_open(u3_handle_t *device, const char *which);
  43. /**
  44. * Close U3 device
  45. *
  46. * This closes the u3 device handle pointed to by 'device'
  47. *
  48. * @param device U3 handle
  49. */
  50. void u3_close(u3_handle_t *device);
  51. /**
  52. * dxfer_direction values as used by u3_send_cmd()
  53. *
  54. * @see 'u3_send_cmd()'
  55. */
  56. enum {
  57. U3_DATA_NONE = 0, // dont transfer extra data
  58. U3_DATA_TO_DEV = 1, // send data to device
  59. U3_DATA_FROM_DEV = 2, // read data from device
  60. };
  61. /**
  62. * Execute a scsi command at device
  63. *
  64. * This send the given SCSI CDB in 'cmd' to the device given by 'device'.
  65. * Optional data is transfered from or to the device. The SCSI status as
  66. * returned by the device is placed in 'status'.
  67. *
  68. * @param device U3 handle
  69. * @param cmd SCSI CDB
  70. * @param dxfer_direction Direction of extra data, given by on of the
  71. * U3_DATA_* enum values
  72. * @param dxfer_len Length of extra data
  73. * @param dxfer_data Buffer with extra data
  74. * @param status Pointer to variable to return SCSI status in
  75. *
  76. * @returns U3_SUCCESS if successful, else U3_FAILURE and
  77. * an error string can be obtained using u3_error()
  78. */
  79. int u3_send_cmd(u3_handle_t *device, uint8_t cmd[U3_CMD_LEN],
  80. int dxfer_direction, int dxfer_length, uint8_t *dxfer_data,
  81. uint8_t *status);
  82. #endif // __U3_SCSI_H__