summaryrefslogtreecommitdiff
path: root/utils/scsi/rbscsi.h
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2017-01-03 22:19:24 +0100
committerAmaury Pouly <amaury.pouly@gmail.com>2017-01-07 15:52:33 +0100
commitae84354b4062e4c4ceb3ce402468d6c095a760c2 (patch)
tree892a3d6ad719dc4d45790eba5011b4aa6f7102f8 /utils/scsi/rbscsi.h
parent1728565e243300b5f50d56399931fa19169031d5 (diff)
downloadrockbox-ae84354b4062e4c4ceb3ce402468d6c095a760c2.tar.gz
rockbox-ae84354b4062e4c4ceb3ce402468d6c095a760c2.zip
Add multiplatform library for raw SCSI commands
Several tools need to perform raw SCSI commands, and we need to support Linux, Windows and Mac OS, without pulling tons of dependencies to build it easily. This very simple library has no dependency and supports Linux. TODO: - windows - mac os Change-Id: I496f5ad2490bd3e96ad962d31cce4e511a523c3a
Diffstat (limited to 'utils/scsi/rbscsi.h')
-rw-r--r--utils/scsi/rbscsi.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/utils/scsi/rbscsi.h b/utils/scsi/rbscsi.h
new file mode 100644
index 0000000000..2b56aabad2
--- /dev/null
+++ b/utils/scsi/rbscsi.h
@@ -0,0 +1,83 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2014 by Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef __RB_SCSI_H__
22#define __RB_SCSI_H__
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28struct rb_scsi_device_t;
29typedef struct rb_scsi_device_t *rb_scsi_device_t;
30
31typedef void (*rb_scsi_printf_t)(void *user, const char *fmt, ...);
32
33/* flags for rb_scsi_open */
34#define RB_SCSI_READ_ONLY (1 << 0)
35#define RB_SCSI_DEBUG (1 << 1)
36
37/* transfer direction */
38#define RB_SCSI_NONE 0
39#define RB_SCSI_READ 1
40#define RB_SCSI_WRITE 2
41
42/* most common status */
43#define RB_SCSI_GOOD 0
44#define RB_SCSI_CHECK_CONDITION 2
45#define RB_SCSI_COMMAND_TERMINATED 0x22
46
47/* return codes */
48#define RB_SCSI_OK 0 /* Everything worked */
49#define RB_SCSI_STATUS 1 /* Device returned an error in status */
50#define RB_SCSI_SENSE 2 /* Device returned sense data */
51#define RB_SCSI_OS_ERROR 3 /* Transfer failed, got OS error */
52#define RB_SCSI_ERROR 4 /* Transfer failed, got transfer/host error */
53
54/* structure for raw transfers */
55struct rb_scsi_raw_cmd_t
56{
57 int dir; /* direction: none, read or write */
58 int cdb_len; /* command buffer length */
59 void *cdb; /* command buffer */
60 int buf_len; /* data buffer length (will be overwritten with actual count) */
61 void *buf; /* buffer */
62 int sense_len; /* sense buffer length (will be overwritten with actual count) */
63 void *sense; /* sense buffer */
64 int tmo; /* timeout (in seconds) */
65 int status; /* status returned by device (STATUS) or errno (OS_ERROR) or other error (ERROR) */
66};
67
68/* open a device, returns a handle or NULL on error
69 * the caller can optionally provide an error printing function */
70rb_scsi_device_t rb_scsi_open(const char *path, unsigned flags, void *user,
71 rb_scsi_printf_t printf);
72/* performs a raw transfer, returns !=0 on error */
73int rb_scsi_raw_xfer(rb_scsi_device_t dev, struct rb_scsi_raw_cmd_t *raw);
74/* decode sense and print information if debug flag is set */
75void rb_scsi_decode_sense(rb_scsi_device_t dev, void *sense, int sense_len);
76/* close a device */
77void rb_scsi_close(rb_scsi_device_t dev);
78
79#ifdef __cplusplus
80}
81#endif
82
83#endif /* __RB_SCSI_H__ */