#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.
 */

/*
 * author:         Tino Reichardt <milky-mcdp@mcmilk.de>
 * status:         untestet (I got only some headers in the web)
 *
 * details:
 * - for hp-ux 1x.x
 *
 * todo:
 * - some simple checking for errors ?
 * - sense
 * - testing!
 */

#if WANT_HPUX_SCTL
int cmd_hpux_sctl(u8 *cmd, int cmdl, u8 *dstp, int dstl, int d)
{
	struct sctl_io io;
	int r;
#if DEBUG_CDB
	char *file="hpux.log";
#endif

	if (isset(cd->flags, F_CANT_SEND_CMD)) return -1;

	zero(&io, sizeof(io));
	io.cdb_length = cmdl;
	io.data = dstp;
	io.data_length = dstl;
	io.max_msecs = 1000 * MCDP_SCSI_TIMEOUT;
	byte_copy(io.cdb, cmdp, cmdl);

	if isset(d, D_READ)  set(io.flags, SCTL_READ);

#if DEBUG_CDB
	cmd_debug(file, CDB_BEFORE);
#endif

	r=ioctl(cd->fd, SG_IO, &io);
	byte_copy(cmd->sense.s, MCDP_MAX_SENSE, io.sbp);

#if DEBUG_CDB
	cmd_debug(file, CDB_AFTER);
#endif

	return r;
}
#endif

#if 0
/* HP-UX 10.? */
struct sctl_io
{
	unsigned flags;			/* IN: SCTL_READ */
	unsigned cdb_length;		/* IN */
	unsigned char cdb[16];		/* IN */
	void *data;			/* IN */
	unsigned data_length;		/* IN */
	unsigned max_msecs;		/* IN: milli-seconds before abort */
	unsigned data_xfer;		/* OUT */
	unsigned cdb_status;		/* OUT: SCSI status */
	unsigned char sense[256];	/* OUT */
	unsigned sense_status;		/* OUT: SCSI status */
	unsigned sense_xfer;		/* OUT: bytes of sense data received */
	unsigned reserved[16];		/* IN: Must be zero; OUT: undefined */
};

/* HP-UX 11i Version 1.6: June 2002 */
struct sctl_io
{
	unsigned        flags;
	unsigned char   cdb_length;
	unsigned char   cdb[16];
	void            *data;
	unsigned        data_length;
	unsigned        max_msecs;
	unsigned        data_xfer;
	unsigned        cdb_status;
	unsigned char   sense[256];
	unsigned        sense_status;
	unsigned char   sense_xfer;
	unsigned char   reserved[64];
};
#endif

