From ae84354b4062e4c4ceb3ce402468d6c095a760c2 Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Tue, 3 Jan 2017 22:19:24 +0100 Subject: 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 --- utils/scsi/rbscsi.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 utils/scsi/rbscsi.h (limited to 'utils/scsi/rbscsi.h') 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 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2014 by Amaury Pouly + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef __RB_SCSI_H__ +#define __RB_SCSI_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +struct rb_scsi_device_t; +typedef struct rb_scsi_device_t *rb_scsi_device_t; + +typedef void (*rb_scsi_printf_t)(void *user, const char *fmt, ...); + +/* flags for rb_scsi_open */ +#define RB_SCSI_READ_ONLY (1 << 0) +#define RB_SCSI_DEBUG (1 << 1) + +/* transfer direction */ +#define RB_SCSI_NONE 0 +#define RB_SCSI_READ 1 +#define RB_SCSI_WRITE 2 + +/* most common status */ +#define RB_SCSI_GOOD 0 +#define RB_SCSI_CHECK_CONDITION 2 +#define RB_SCSI_COMMAND_TERMINATED 0x22 + +/* return codes */ +#define RB_SCSI_OK 0 /* Everything worked */ +#define RB_SCSI_STATUS 1 /* Device returned an error in status */ +#define RB_SCSI_SENSE 2 /* Device returned sense data */ +#define RB_SCSI_OS_ERROR 3 /* Transfer failed, got OS error */ +#define RB_SCSI_ERROR 4 /* Transfer failed, got transfer/host error */ + +/* structure for raw transfers */ +struct rb_scsi_raw_cmd_t +{ + int dir; /* direction: none, read or write */ + int cdb_len; /* command buffer length */ + void *cdb; /* command buffer */ + int buf_len; /* data buffer length (will be overwritten with actual count) */ + void *buf; /* buffer */ + int sense_len; /* sense buffer length (will be overwritten with actual count) */ + void *sense; /* sense buffer */ + int tmo; /* timeout (in seconds) */ + int status; /* status returned by device (STATUS) or errno (OS_ERROR) or other error (ERROR) */ +}; + +/* open a device, returns a handle or NULL on error + * the caller can optionally provide an error printing function */ +rb_scsi_device_t rb_scsi_open(const char *path, unsigned flags, void *user, + rb_scsi_printf_t printf); +/* performs a raw transfer, returns !=0 on error */ +int rb_scsi_raw_xfer(rb_scsi_device_t dev, struct rb_scsi_raw_cmd_t *raw); +/* decode sense and print information if debug flag is set */ +void rb_scsi_decode_sense(rb_scsi_device_t dev, void *sense, int sense_len); +/* close a device */ +void rb_scsi_close(rb_scsi_device_t dev); + +#ifdef __cplusplus +} +#endif + +#endif /* __RB_SCSI_H__ */ -- cgit v1.2.3