2004-06-27 21:58:12 +00:00
|
|
|
/* Common MMC routines.
|
|
|
|
|
|
2004-07-22 09:52:17 +00:00
|
|
|
$Id: scsi_mmc.c,v 1.7 2004/07/22 09:52:17 rocky Exp $
|
2004-06-27 21:58:12 +00:00
|
|
|
|
|
|
|
|
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
|
|
|
|
|
|
|
|
|
|
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 program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
# include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <cdio/cdio.h>
|
|
|
|
|
#include <cdio/scsi_mmc.h>
|
2004-07-22 09:52:17 +00:00
|
|
|
#include "cdio_private.h"
|
2004-06-27 21:58:12 +00:00
|
|
|
|
|
|
|
|
/*!
|
2004-07-19 01:13:31 +00:00
|
|
|
On input a MODE_SENSE command was issued and we have the results
|
2004-06-27 21:58:12 +00:00
|
|
|
in p. We interpret this and return a bit mask set according to the
|
|
|
|
|
capabilities.
|
|
|
|
|
*/
|
2004-07-17 22:16:46 +00:00
|
|
|
void
|
2004-07-22 09:52:17 +00:00
|
|
|
scsi_mmc_get_drive_cap(const uint8_t *p,
|
2004-07-19 01:13:31 +00:00
|
|
|
/*out*/ cdio_drive_read_cap_t *p_read_cap,
|
|
|
|
|
/*out*/ cdio_drive_write_cap_t *p_write_cap,
|
|
|
|
|
/*out*/ cdio_drive_misc_cap_t *p_misc_cap)
|
2004-06-27 21:58:12 +00:00
|
|
|
{
|
|
|
|
|
/* Reader */
|
2004-07-18 03:35:07 +00:00
|
|
|
if (p[2] & 0x01) *p_read_cap |= CDIO_DRIVE_CAP_READ_CD_R;
|
2004-07-17 22:16:46 +00:00
|
|
|
if (p[2] & 0x02) *p_read_cap |= CDIO_DRIVE_CAP_READ_CD_RW;
|
|
|
|
|
if (p[2] & 0x08) *p_read_cap |= CDIO_DRIVE_CAP_READ_DVD_ROM;
|
2004-07-18 03:35:07 +00:00
|
|
|
if (p[4] & 0x01) *p_read_cap |= CDIO_DRIVE_CAP_READ_AUDIO;
|
|
|
|
|
if (p[5] & 0x01) *p_read_cap |= CDIO_DRIVE_CAP_READ_CD_DA;
|
|
|
|
|
if (p[5] & 0x10) *p_read_cap |= CDIO_DRIVE_CAP_READ_C2_ERRS;
|
2004-06-27 21:58:12 +00:00
|
|
|
|
|
|
|
|
/* Writer */
|
2004-07-17 22:16:46 +00:00
|
|
|
if (p[3] & 0x01) *p_write_cap |= CDIO_DRIVE_CAP_WRITE_CD_R;
|
2004-07-18 03:35:07 +00:00
|
|
|
if (p[3] & 0x02) *p_write_cap |= CDIO_DRIVE_CAP_WRITE_CD_RW;
|
2004-07-17 22:16:46 +00:00
|
|
|
if (p[3] & 0x10) *p_write_cap |= CDIO_DRIVE_CAP_WRITE_DVD_R;
|
|
|
|
|
if (p[3] & 0x20) *p_write_cap |= CDIO_DRIVE_CAP_WRITE_DVD_RAM;
|
2004-07-19 01:13:31 +00:00
|
|
|
if (p[4] & 0x80) *p_misc_cap |= CDIO_DRIVE_CAP_WRITE_BURN_PROOF;
|
2004-06-28 00:26:19 +00:00
|
|
|
|
2004-07-17 22:16:46 +00:00
|
|
|
/* Misc */
|
|
|
|
|
if (p[4] & 0x40) *p_misc_cap |= CDIO_DRIVE_CAP_MISC_MULTI_SESSION;
|
|
|
|
|
if (p[6] & 0x01) *p_misc_cap |= CDIO_DRIVE_CAP_MISC_LOCK;
|
2004-07-18 03:35:07 +00:00
|
|
|
if (p[6] & 0x08) *p_misc_cap |= CDIO_DRIVE_CAP_MISC_EJECT;
|
2004-06-27 21:58:12 +00:00
|
|
|
if (p[6] >> 5 != 0)
|
2004-07-17 22:16:46 +00:00
|
|
|
*p_misc_cap |= CDIO_DRIVE_CAP_MISC_CLOSE_TRAY;
|
2004-06-27 21:58:12 +00:00
|
|
|
}
|
2004-07-22 09:52:17 +00:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Return the number of length in bytes of the Command Descriptor
|
|
|
|
|
buffer (CDB) for a given SCSI MMC command. The length will be
|
|
|
|
|
either 6, 10, or 12.
|
|
|
|
|
*/
|
|
|
|
|
uint8_t
|
|
|
|
|
scsi_mmc_get_cmd_len(uint8_t scsi_cmd)
|
|
|
|
|
{
|
|
|
|
|
static const uint8_t scsi_cdblen[8] = {6, 10, 10, 12, 12, 12, 10, 10};
|
|
|
|
|
return scsi_cdblen[((scsi_cmd >> 5) & 7)];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Run a SCSI MMC command.
|
|
|
|
|
|
|
|
|
|
cdio CD structure set by cdio_open().
|
|
|
|
|
i_timeout time in milliseconds we will wait for the command
|
|
|
|
|
to complete. If this value is -1, use the default
|
|
|
|
|
time-out value.
|
|
|
|
|
buf Buffer for data, both sending and receiving
|
|
|
|
|
len Size of buffer
|
|
|
|
|
e_direction direction the transfer is to go
|
|
|
|
|
cdb CDB bytes. All values that are needed should be set on
|
|
|
|
|
input. We'll figure out what the right CDB length should be.
|
|
|
|
|
|
|
|
|
|
We return 0 if command completed successfully and 1 if not.
|
|
|
|
|
*/
|
|
|
|
|
int
|
|
|
|
|
scsi_mmc_run_cmd( const CdIo *cdio, int i_timeout, const scsi_mmc_cdb_t *p_cdb,
|
|
|
|
|
scsi_mmc_direction_t e_direction, unsigned int i_buf,
|
|
|
|
|
/*in/out*/ void *p_buf )
|
|
|
|
|
{
|
|
|
|
|
if (cdio && cdio->op.run_scsi_mmc_cmd) {
|
|
|
|
|
return cdio->op.run_scsi_mmc_cmd(cdio, i_timeout,
|
|
|
|
|
scsi_mmc_get_cmd_len(p_cdb->field[0]),
|
|
|
|
|
p_cdb, e_direction, i_buf, p_buf);
|
|
|
|
|
} else
|
|
|
|
|
return 1;
|
|
|
|
|
}
|