#ifndef M_DEV_H
#define M_DEV_H

#include "mcdp.h"

/**
 * Copyright (C) 2001-2006 Tino Reichardt
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 2, as
 * published by the Free Software Foundation.
 *
 * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/**
 * device layer for controlling cd devices on different unix systems
 */

#define DEBUG_CDB 0
#define MCDP_MAX_SENSE 32

/* initialize / open cd devices */
extern void dev_init(void);

typedef struct {

	/* we use 6,10,12 commands */
	stralloc cmd;
	unsigned int cmdlen;

	/* buffer for data */
	stralloc buf;
	unsigned int buflen;

	/* buffer for sense */
	stralloc sense;

#if DEBUG_CDB
	/* buffer for command description in logfile */
	stralloc name;
#endif

	/* 1. direction of the cdb */
	int flags;
#define D_NONE     0x01
#define D_READ     0x02
#define D_WRITE    0x04
} scmd_t;

#if DEBUG_CDB
#define CDB_BEFORE 0x01
#define CDB_AFTER  0x02
extern void cmd_debug(char *file, int what);
#endif


/**
 * general OS independant scsi / atapi command functions
 */

/* space allocation for the cdb's */
extern void scmd_ready(int cmdlen, int buflen);

/* startstop unit command */
extern void scmd_startstop(int loej, int start);
extern void scmd_stop(void);
extern void scmd_eject(void);
extern void scmd_close(void);

/* pause / resume command */
extern void scmd_pauseresume(void);

/* play track command */
extern void scmd_play(int track);

/* inquiry command */
extern void scmd_inquiry(void);

/* read toc command */
extern void scmd_initdisc(void);


/**
 * OS dependant functions (special ioctl's and ...)
 * - if someone makes them os independant... O would be happy ;)
 */

/* seek some seconds */
extern void cd_seek(int seconds);

/* get current volume and playing status */
extern void cd_getstatus(void);

/* for setting the volume */
extern void cd_volume(int volume);


#if defined(WANT_LINUX_SCSI_GENERIC) || defined(WANT_LINUX_SEND_PACKET)
extern void dev_linux(void);
/* linux, via scsi generic ioctl, mostly: /dev/sg0 /dev/scd0 */
#if WANT_LINUX_SCSI_GENERIC
#include <scsi/scsi.h>
#include <scsi/sg.h>
extern int cmd_lx_sg(scmd_t *cdb);
#endif
/* linux, via scsi send_packet ioctl, mostly: /dev/hdc /dev/sr0 */
#if WANT_LINUX_SEND_PACKET
#include "dev_linux.h" /* <linux/cdrom.h> makes trouble */
extern int cmd_lx_sp(scmd_t *cdb);
#endif
#endif


/* bsd (free/open/net) */
#if WANT_BSD_SCSIIO
#include <sys/scsiio.h>
extern int cmd_bsd_scsiio(scmd_t *cdb);
extern void dev_bsd(void);
#endif


/* hpux, via scsi commands */
#if WANT_HPUX_SCSI_CONTROL
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/scsi.h>
#include <ustat.h>
extern int cmd_hpux_sctl(scmd_t *cdb);
extern void dev_hpux(void);
#endif


/* sun, via scsi user scsi commands */
#if WANT_SUN_USCSI
#include <sys/scsi/impl/uscsi.h>
extern int cmd_sun_uscsi(scmd_t *cdb);
extern void dev_sun(void);
#endif

#if defined(WANT_LINUX_SCSI_GENERIC) \
 || defined(WANT_LINUX_SEND_PACKET)  \
 || defined(WANT_BSD_SCSIIO) \
 || defined(WANT_HPUX_SCTL) \
 || defined(WANT_SUN_USCSI)
#else
#error "rtfm!"
#endif

#endif

