//-----------------------------------------------------------------------------
//    C O M P A N Y       C O N F I D E N T I A L       S O F T W A R E
//-----------------------------------------------------------------------------
//    © Copyright 2001 - 2005 by Quantum Corporation. All Rights Reserved.
//
//    No part of this publication or source code  may be reproduced or
//	  transmitted in any form or by any means, electronic or mechanical,
//	  including photocopying, recording or by any information storage and
//	  retrieval system, without written permission from Quantum Corporation.
//
//	  No part of this publication or source code may be compiled, linked or
//	  ohterwise built into any machine object code, executable or software
//	  library without written permission from Quantum Corporation.
//-----------------------------------------------------------------------------

////////////////////////////////////////////////////////////////////////
// DLL Function prototypes
//
//
// Revision History
//  date     author           description
//  -------- ----------       --------------------------------
//  06/25/02 Chuck Richardson Initial version.
//
//  12/08/02 Chuck Richardson Added Java Native Interface methods
//                            so library can be accessed by a 
//							  Java Applet web application.
//
//	08/22/05 Chuck Richardson Put SubTest error code declarations in
//							  this file.  They were previously delclared
//							  in the ScsiInt file.
//
////////////////////////////////////////////////////////////////////////

#ifndef DLL_FUNCTIONS_H
#define DLL_FUNCTIONS_H


typedef struct _SCSI_DEVICE_ADDRESS
{	
	int port;       // SCSI port number
	int bus;		// bus number on port
	int target;		// SCSI target ID
	int lun;		// SCSI lun -- normally 0
}SCSI_DEVICE_ADDRESS;

#ifndef __DLL_VERSION
	#define __DLL_VERSION

	typedef struct _DLL_VERSION_INFO
	{
		char Version_Major[4];   
		char Version_Minor[4];
	}DLL_VERSION_INFO;
#endif

#define SUBTEST_START_FAILED			0x000
#define SUBTEST_START_SUCCEEDED         0x001
#define SUBTEST_START_NOT_IMPLEMENTED	0x002
#define SUBTEST_START_DEVICE_BUSY		0x003


// return values for GetSubTestStatus(...)
#define SUBTEST_STATUS_PASSED			0x000
#define SUBTEST_STATUS_RUNNING			0x001
#define SUBTEST_STATUS_FAILED			0x002
#define SUBTEST_STATUS_UNUSUAL			0x003
#define SUBTEST_STATUS_CANCELLED        0x004


#ifdef __cplusplus
extern "C" {
#endif

#ifdef WIN32
	#include <wtypes.h>
	#include <conio.h>

	#define DllExport   __stdcall

	#ifndef UCHAR
	#define UCHAR unsigned char
	#endif

#else
	#if _TARGET == _NLM
		#define DllExport  
		#define JNIEXPORT
		#define JNIIMPORT
		#define JNICALL
		#include "novell.h"
	#else
		#define DllExport  
		#define JNIEXPORT
		#define JNIIMPORT
		#define JNICALL
		#include "unix.h"
	#endif
#endif

int  DllExport    test_main(int argc, char* argv[]);

///////////////////////////////////////////////////////////////
//   DLL INITIALIZATION & CLEANUP
//
bool DllExport   q_scsi_IsSequential(void);
bool DllExport   q_scsi_IsChanger(void);

int DllExport    q_scsi_ScanDevices(bool rescan, int listAllSequentials, int listAllChangers, int listAnything);
int DllExport    q_scsi_CleanUp();
char*  DllExport q_scsi_GetDllVersionString();


bool DllExport	 q_scsi_XTalkInitialize();
void DllExport	 q_scsi_SetAutoFupEject(bool val);

	/////////////////////////////////////////////
	// Example of how to call ScanDevices
	//

	// LIST ANY SEQUENTIALS
	// long retVal = SCSI.ScanDevices(true, 1, -1);

	// LIST KNOWN SEQUENTIALS
	// long retVal = SCSI.ScanDevices(true, 0, -1);

	// LIST KNOWN CHANGERS
	// long retVal = SCSI.ScanDevices(true, -1, 0);

	// LIST ANY CHANGERs
	// long retVal = SCSI.ScanDevices(true, -1, 1);

	// LIST ANY SEQUENTIALS OR ANY CHANGERS
	// long retVal = SCSI.ScanDevices(true, 1, 1);

	// LIST ANYTHING SCSI
	// long retVal = SCSI.ScanDevices(true, 1, 1, 1);

	void DllExport q_scsi_PrintDataBuffer(UCHAR* DataBuffer, ULONG BufferLength);
	void DllExport q_scsi_SystemError(int errNum, char* str1);
	void DllExport q_scsi_PrintError();
	int  DllExport q_scsi_SetUnixDeviceType(char* str1);
	int  DllExport q_scsi_PrintDevices();
	void DllExport q_scsi_SetAutoFupEject(bool val);
	bool DllExport q_scsi_GetAutoFupEject();
	int  DllExport q_scsi_GetDeviceCount();
	int  DllExport q_scsi_GetAdapterCount();
	int  DllExport q_scsi_GetDeviceIndex();
	void DllExport q_scsi_SetDeviceIndex(long devIdx);


/////////////////////////////////////////////////////
//  DELL DIAGNOSTIC ROUTINES
//

	// This is the chance for the vendor to do any preparation, such
	// as enumerating all devices and storing the relevent info.
	//	Return:	TRUE under normal circumstances
	//			FALSE to indicate the client should no proceed to make   
	//			function calls F
	bool DllExport InitDellDiagDLL();

	// This shall be called before freeing the DLL.  This allows the user
	// to perform an necessary cleanup and should have a 1-1 relationship to
	// InitDLL(void)--every time the Init function is called, the 
	// Cleanup function will eventually be called
	//  Return: 
	bool DllExport CleanupDLL();		
	bool DllExport CleanupDellDiagDLL();		
	//	Return:	TRUE under normal circumstances
	//			FALSE if some failure was occured
	//  Note: For now, the return value of the function is ignored


	// This function should return a unique identifier for the SCSI 
	// device indicated by devAddr.  In the event that a device
	// does not exist at that address, this function shall return 0.
	// The unique identifier will be used by subsequent calls to 
	// functions in this DLL
	// NOTE: The identifier need not be globally unique--just unique
	// within the vendor implemented DLLs (Two separate vendors may 
	// use identifiers that are the same).
	int DllExport GetUniqueDeviceNum(SCSI_DEVICE_ADDRESS * devAddr);

	// This function is a reverse implementation of GetUniqueDeviceNum--
	// the devAddr fields should be populated based on the uniqueNum 
	// supplied. 
	//  Return: TRUE if the uniqueNum is valid (devAddr should be filled in 
	//			appropriately
	//			FALSE if the uniqueNum is invalid
	bool DllExport GetDeviceScsiAddress(int uniqueNum, SCSI_DEVICE_ADDRESS * devAddr);

	// This function is called to kick off a subtest.  The value of 
	// subtest should correspond to the test definitions at the beginning
	// of this file.  All attempts should be made to implement this function
	// with params argument set to NULL.  This function should return one of
	// the values defined above as return values for this function.  The function
	// shall return as soon as the necessary steps have been taken to ensure that 
	// the subtest can be run (ensure device is not busy).
	int DllExport StartSubTest(
						int  subtest,  // corresponds to the test definitions in this file
						int  devNumber, // unique device indicator provided by GetUniqueDeviceNum(...)
						void *params,  // NULL if not needed
						int  *uniqueKey // if function succeeds, this value shall be set to a uniqueKey 
									   // for the Subtest.  This key will be used in subsequent calls 
									   // related to this subtest instance.
						);

	int DllExport StartFwUpdate(int  devNumber, // unique device indicator provided by GetUniqueDeviceNum(...)
                                char *params,   // NULL if not needed
                                int  *uniqueKey // if function succeeds, this value shall be set to a uniqueKey 
                                                // for the Subtest.  This key will be used in subsequent calls 
                                                // related to this subtest instance.
                               );

	// This function is called to cancel a running subtest.  The subtest should
	// only be cancelled if the value in uniqueKey corresponds to the value returned
	// when the StartSubTest(...) call was made.  This function shall not wait for all
	// device activity to halt before return.  
	int DllExport CancelSubTest( int *uniqueKey ); // uniqueKey set in StartSubTest(...)

	// This function is used to determine the status of a running test. Return values
	// are defined in the definition section of this file.  If the test status is pending,
	// the percentComplete parameter shall be set to an approximate value between 0 and 100
	int DllExport GetSubTestStatus(int uniqueKey, int *percentComplete);


	// This function shall return an integer that corresponds to the error code that was generated
	// when the subtest identified by uniqueKey was run.  In the event that no error code was generated
	// this fuction shall return 0.  
	int DllExport GetSubtestError(int uniqueKey);


	//  This function should return the DLL version.
	void DllExport GetDllVersion(DLL_VERSION_INFO *verInfo);


	// This function will perform a firmware update to a drive.
	// The first call is a blocking call, where process control is not
	// returned to the caller until the update process is complete.
	// The second call will start a thread  that will perform the update
	// and the status of the update and percent complete can be obtained
	// by calling the GetSubTestStatus function.  The second function is
	// equivalent to calling StartSubTest(...) and passing a char * in as
	// the params argument and a subtest argument of FW_UPDATE (0x01a).
	// The return value for the first call is an integer error code, where
	// a return of zero indicates success and non-zero values correspond to
	// specific types of errors.
	// The return value for the second call will fall under the same range
	// and meanings for the return values of the StartSubTest(...) function.
	// The status codes for the second method will be defined and added to
	// list of error codes currently defined for the Dell Sub Tests.

	int DllExport FwUpdate(int channel, int bus, int target, int lun, char* fwimage_file_path);

//
//  DELL DIAGNOSTIC ROUTINES
/////////////////////////////////////////////////////



///////////////////////////////////////////////////////////////
//   BUILT IN SUB TEST ROUTINES
//
int DllExport    q_scsi_CommunicationTest();
int DllExport    q_scsi_RamTest();
int DllExport    q_scsi_SendDiagnosticTest();
int DllExport    q_scsi_LoadTest();
int DllExport    q_scsi_MediaReadyTest();
int DllExport    q_scsi_ReadWriteTest();
int DllExport    q_scsi_EraseTest();
int DllExport    q_scsi_InventoryTest();
int DllExport    q_scsi_SlotToSlotTest();
int DllExport    q_scsi_SlotToDriveTest();

int DllExport    q_scsi_ScsiSIT();
int DllExport    q_scsi_ScsiQuickWriteRead();
int DllExport    q_scsi_ScsiStuckAtOne();
int DllExport    q_scsi_ScsiDiagLevel2();
int DllExport    q_scsi_ScsiSLT(long block_size);
int DllExport    q_scsi_ScsiBC8008();
int DllExport    q_scsi_ScsiPatternFiles();
int DllExport    q_scsi_ScsiBER(long block_size);
int DllExport    q_scsi_ScsiBaseline(long block_size);
int DllExport    q_scsi_ScsiBRC4kNative();
int DllExport    q_scsi_ScsiBRC4kReadRef();
int DllExport    q_scsi_ScsiBRC8kNative();
int DllExport    q_scsi_ScsiBRC8kReadRef();
int DllExport    q_scsi_ScsiBRC220Native();
int DllExport    q_scsi_ScsiBRC220ReadRef();
int DllExport    q_scsi_ScsiBRC320Native();
int DllExport    q_scsi_ScsiBRC320ReadRef();



///////////////////////////////////////////////////////////////
//   MISC SCSI FUNCTIONS
//
int    DllExport q_scsi_Status();
int    DllExport q_scsi_GetSenseKey();
int    DllExport q_scsi_GetAsc();
int    DllExport q_scsi_GetAscQ();


int    DllExport q_scsi_GetBusId();
int    DllExport q_scsi_GetPortId();
int    DllExport q_scsi_GetTargetId();
int    DllExport q_scsi_GetLunId();


UCHAR* DllExport q_scsi_GetRevData();
UCHAR* DllExport q_scsi_GetBuildData();

char*  DllExport q_scsi_GetDeviceTypeString(INT64 num);
INT64  DllExport q_scsi_GetDriveType(char* buffer);

char*  DllExport q_scsi_GetDescription();
char*  DllExport q_scsi_GetDeviceFilename();
char*  DllExport q_scsi_GetSerialNumber();
int    DllExport q_scsi_SetSerialNumber(char* val);
long   DllExport q_scsi_GetAdapterIdx();

	///////////////////////////////////////
	// Finds the device with the specified
	// serial number and sets the defualt
	// device to that one
long   DllExport q_scsi_FindSerialNumber(char* SerialNumber);



double DllExport q_scsi_GetKBytesRead();
double DllExport q_scsi_GetReadMbPerSec();
double DllExport q_scsi_GetReadMbPerSecAvg();
double DllExport q_scsi_GetReadSecs();

double DllExport q_scsi_GetKBytesWritten();
double DllExport q_scsi_GetWriteMbPerSec();
double DllExport q_scsi_GetWriteMbPerSecAvg();
double DllExport q_scsi_GetWriteSecs();

long   DllExport q_scsi_GetCommandCount();

bool   DllExport q_scsi_GetIliFlag();
bool   DllExport q_scsi_GetFileMarkFlag();
bool   DllExport q_scsi_GetEomFlag();
long   DllExport q_scsi_GetResidual();
long   DllExport q_scsi_GetTapeMotionHours();
long   DllExport q_scsi_GetPowerOnHours();
bool   DllExport q_scsi_GetCleaningFlag();

long   DllExport q_scsi_GetRevMajor();
long   DllExport q_scsi_GetRevMinor();
long   DllExport q_scsi_GetPersMajor();
long   DllExport q_scsi_GetPersMinor();

char*  DllExport q_scsi_GetVersionMajor();
char*  DllExport q_scsi_GetVersionMinor();
char*  DllExport q_scsi_GetVersionString();

char*  DllExport q_scsi_GetRevString();
char*  DllExport q_scsi_GetRevStringShort();
char*  DllExport q_scsi_GetPersString();

BYTE   DllExport q_scsi_GetCompression();
int    DllExport q_scsi_SetCompression( BYTE compression );


int    DllExport q_scsi_RequestSense();

int    DllExport q_scsi_TestUnitReady();
int    DllExport q_scsi_WaitForUnitReady();
void   DllExport q_scsi_MediaCheck();


int    DllExport q_scsi_Inquiry();

int    DllExport q_scsi_SetParameter( char* parameterName, char* val );
int    DllExport q_scsi_SetScsiEject(long val);
int    DllExport q_scsi_SetRawErrorLogging(long val);
int    DllExport q_scsi_SetRebuild(long val);

int    DllExport q_scsi_Load();
int    DllExport q_scsi_Unload();
int	   DllExport q_scsi_SetMediumRemoval(bool prevent); // 0 = allowed,  1 = prevent
int    DllExport q_scsi_Rewind(long timeout);
int    DllExport q_scsi_Erase();

int    DllExport q_scsi_InitializeElementStatus();
int    DllExport q_scsi_MoveElement(BYTE* srcAddr, BYTE* destAddr);
int    DllExport q_scsi_ReadElementStatus( long elementType, long maxElements );
char*  DllExport q_scsi_PrintElementReport();

int    DllExport q_scsi_Read(long dataSize);
int    DllExport q_scsi_ReadBlock(long block_count);
int    DllExport q_scsi_ReadBuffer(UCHAR* Data, long dataSize, UCHAR mode, UCHAR page, long offset);
int    DllExport q_scsi_ReadRef(long block_size, long read_size, long read_count);


int    DllExport q_scsi_Write(UCHAR* Data, long dataSize);
int    DllExport q_scsi_WriteBlock(UCHAR* Data, long dataSize);
int    DllExport q_scsi_WriteBuffer(UCHAR* Data, long dataSize, UCHAR mode, UCHAR page, long offset);
INT64  DllExport q_scsi_WriteData(UCHAR* data, ULONG dataLen, ULONG writeCount );


int    DllExport q_scsi_ReadBufferSize();
int    DllExport q_scsi_VerifyBuffer(UCHAR* dataBuffer, long dataSize);


long   DllExport q_scsi_GetBerBlockCount();
long   DllExport q_scsi_SetBerBlockCount(long block_count);
long   DllExport q_scsi_GetBerBlockSize();
long   DllExport q_scsi_SetBerBlockSize(long block_size);

int    DllExport q_scsi_GetTimeout();
int    DllExport q_scsi_SetTimeout(int timeout);
long   DllExport q_scsi_GetCurrentBlockSize();
long   DllExport q_scsi_SetCurrentBlockSize(long block_size);

	//The SetImagePath is useful for when you want the app using the DLL
	// to fup in a separate thread, to keep from blocking the app
	// do do this, you would set the image path and commit zero flag
	// then call StartSubTest, passing in the test idx corresponding to
	// the test name 'FUP_TEST'
void   DllExport q_scsi_SetImagePath(char* path, bool commit_zero = false);
int    DllExport q_scsi_FupDrive(char* imageFileName);

int    DllExport q_scsi_ClearSegments();
int    DllExport q_scsi_ClearEventLog();

int    DllExport q_scsi_LogReset();

long   DllExport q_scsi_GetBufferSize();
long   DllExport q_scsi_GetByteCount();
long   DllExport q_scsi_GetReadBuffer(UCHAR* readBuf, long size );


UCHAR  DllExport q_scsi_GetCurrentBufferMode();
void   DllExport q_scsi_SetCurrentBufferMode(UCHAR mode);
UCHAR  DllExport q_scsi_GetLastBufferMode();


int    DllExport q_scsi_FetchLog(UCHAR pageCode);
UCHAR* DllExport q_scsi_GetLogParameter(long paramCode, long* len );
ULONG  DllExport q_scsi_GetLogParameterValue(long paramCode );
char*  DllExport q_scsi_GetLogParameterString( long paramCode );

int    DllExport q_scsi_ModeSense(BYTE pageCode);
int    DllExport q_scsi_ModeSelect(int len, PUCHAR data);


long   DllExport q_scsi_GetModeSize();
UCHAR* DllExport q_scsi_GetModeBuffer();

long   DllExport q_scsi_GetLogSize();
UCHAR* DllExport q_scsi_GetLogBuffer();

int    DllExport q_scsi_SendCdb(int direction=0, UCHAR* cdb=NULL, UCHAR cdbLen=0, UCHAR* dataBuf=NULL, ULONG dataLen=0);

long   DllExport q_scsi_GetSenseSize();
UCHAR* DllExport q_scsi_GetSenseBuffer();

long   DllExport q_scsi_GetInquirySize();
UCHAR* DllExport q_scsi_GetInquiryBuffer();

char*  DllExport q_scsi_GetErrorText(long errorCode);
char*  DllExport q_scsi_GetErrorBuffer();
char*  DllExport q_scsi_GetMessageBuffer();
char*  DllExport q_scsi_GetDevErrorBuffer();
char*  DllExport q_scsi_GetScsiErrorBuffer();

char*  DllExport q_scsi_GetLastCdb();
long   DllExport q_scsi_GetMaxSubTest();
char*  DllExport q_scsi_GetSubTestName(long testIdx);


	///////////////////////////////////////
	// Gets HP LTT data if present
long   DllExport q_scsi_CollectLTTWriteBackData();
long   DllExport q_scsi_GetWriteBackCount();
char*  DllExport q_scsi_GetWriteBackDataHex(long idx);
UCHAR* DllExport q_scsi_GetWriteBackDataString(long idx);


	///////////////////////////////////////////////////////////////
	// Gets Parameter Values e.g. Log Page 2 & 3 read write metrics
void   DllExport q_scsi_CollectParameters();
INT64  DllExport q_scsi_GetParameterValue( long nParameterType, long ulParameterCode );
long   DllExport q_scsi_ResetDriveParameters();

void   DllExport q_scsi_ClearParameters();
long   DllExport q_scsi_ParseParameters(long type);

	///////////////////////////////////////
	// Gets Log Page 7 Error Even Stuff
void   DllExport q_scsi_CollectEvents();
void   DllExport q_scsi_ResetEvents();
long   DllExport q_scsi_GetEventCount();
char*  DllExport q_scsi_GetEventText( long eventIdx );
long   DllExport q_scsi_GetEventCode( long eventIdx );
long   DllExport q_scsi_GetEventLength( long eventIdx );
long   DllExport q_scsi_GetEventType( long eventIdx );
char*  DllExport q_scsi_GetEventErrorCode( long eventIdx );

	///////////////////////////////////////
	// Gets Log Page 2E Ape Alert Stuff
void   DllExport q_scsi_CollectAlerts();
void   DllExport q_scsi_ResetAlerts();
long   DllExport q_scsi_GetNextAlert();
char*  DllExport q_scsi_GetAlertFlag( long alert );
char*  DllExport q_scsi_GetAlertType( long alert );
char*  DllExport q_scsi_GetAlertMessage( long alert );
char*  DllExport q_scsi_GetAlertCause( long alert );

	//////////////////////////////////////////////////
	// Get Information about an adapter card get idx
	// from the device by calling GetAdapterIdx()
	//
char*  DllExport q_scsi_GetAdapterFilename(long idx);
char*  DllExport q_scsi_GetAdapterDescription(long idx);
char*  DllExport q_scsi_GetAdapterDriver(long idx);
long   DllExport q_scsi_GetAdapterNumberOfBusses(long idx);
long   DllExport q_scsi_GetAdapterBusId(long idx, long bus);
long   DllExport q_scsi_GetAdapterInitiatorId(long idx, long bus);
long   DllExport q_scsi_GetAdapterNumberOfUnits(long idx, long bus);

bool   DllExport q_scsi_GetClaimedFlag();	// Get a flag that is true when device is claimed by a windows
											// device driver.
char*  DllExport q_scsi_GetMfgString();
long   DllExport q_scsi_GetMfgId();

									// Need to call q_scsi_MediaCheck() first to do the Mode Sense
int	   DllExport q_scsi_GetMediaType();		// returns the Media Type as reported from a mode sense on the device
int	   DllExport q_scsi_GetMediaDensity();	// returns the Media Type as reported from a mode sense on the device

int    DllExport q_scsi_SetPersonalityOverride(bool val); // disables the DLL default behavior that will attempt
														  // to overrided one firware personity to another during FUP.

#ifdef __cplusplus

}
#endif

#endif  // DLL_FUNCTIONS_H

