diff options
Diffstat (limited to 'utils/scsi/rbscsi.h')
-rw-r--r-- | utils/scsi/rbscsi.h | 83 |
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 | ||
25 | extern "C" { | ||
26 | #endif | ||
27 | |||
28 | struct rb_scsi_device_t; | ||
29 | typedef struct rb_scsi_device_t *rb_scsi_device_t; | ||
30 | |||
31 | typedef 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 */ | ||
55 | struct 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 */ | ||
70 | rb_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 */ | ||
73 | int 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 */ | ||
75 | void rb_scsi_decode_sense(rb_scsi_device_t dev, void *sense, int sense_len); | ||
76 | /* close a device */ | ||
77 | void rb_scsi_close(rb_scsi_device_t dev); | ||
78 | |||
79 | #ifdef __cplusplus | ||
80 | } | ||
81 | #endif | ||
82 | |||
83 | #endif /* __RB_SCSI_H__ */ | ||