//	STAUTO32.H Header file.

/*****************************************************************************
 * COPYRIGHT (C) 2002 by RSA Security Inc.                                   *
 *                       ---ALL RIGHTS RESERVED---                           * 
 *                                                                           *  
 * THIS SOFTWARE IS PROPRIETARY AND CONFIDENTIAL TO RSA SECURITY INC.,       *
 * IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED                   *
 * ONLY IN ACCORDANCE THE TERMS OF SUCH LICENSE AND WITH THE INCLUSION       *   
 * OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR ANY OTHER COPIES THEREOF *
 * MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER PERSON.  NO  * 
 * TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY TRANSFERRED.             *
 *                                                                           *
 * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND  *
 * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY RSA SECURITY INC.              *
 ****************************************************************************/

#ifndef _SOFTAPI_H
#define _SOFTAPI_H

#ifdef __cplusplus
extern "C" {
#endif  /* __cplusplus */

// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the STAUTO32_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// STAUTO32_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.

#define SDIAPI WINAPI

#define STAUTO32_API_INT  INT  WINAPI
#define STAUTO32_API_BOOL BOOL WINAPI
#define STAUTO32_API_LONG LONG WINAPI

#define TRUE            1
#define FALSE           0


// ********* For Previous version comaptibilty *******************
// RETURN CODES FOR StartSoftID().  These are here to resolve the 
// 2.0 and previous version compatibility issues.

#define RETURN_NO_ERROR                 TRUE
#define RETURN_ERROR			        FALSE
#define SOFTID_RUNNING	                1
#define SOFTID_CANNOTRUN	            2
#define SOFTID_DEAD				        3
#define SOFTID_ERROR			        4
        
#define ERROR_DISPLAY_STRING		    -1                                         
#define ERROR_NONE				        0                                         
#define ERROR_INIT          		    1
#define ERROR_INVALID_PNTR              1
#define ERROR_TIME					    2
#define ERROR_DLL_LOADED                2
#define ERROR_LOAD_DLL_ERROR            3
#define ERROR_SECURITY				    3
#define ERROR_RESOURCE_ERROR            4
#define ERROR_READ_REG_ERROR            5    
#define ERROR_WRITE_REG_ERROR           6
#define ERROR_INVALID_SET_NUMBER        7
#define ERROR_PROC_ADDRESS_ERROR        8
#define ERROR_INVALID_NAME_ERROR        9
#define ERROR_DLL_CALL_ERROR            10
#define ERROR_INACTIVE_DLL              11
#define ERROR_DATA_INVALID              12
#define ERROR_HANDLE_INVALID            13    
#define ERROR_KEY_INVALID               14
#define ERROR_TOKEN_INVALID             15                                          
#define ERROR_TOKEN_NOTFOUND            16                                          
#define ERROR_BUFFER_TOO_SMALL_ERROR    17
#define ERROR_TOKEN_SERVICE_OPEN        18
#define ERROR_INVALID_COMP_NAME         19
#define ERROR_SET_ONE_DELETED           20                              
#define ERROR_PASSWORD_INVALID          21
#define ERROR_NONE_MATCHING_PASSWORD    22 
#define ERROR_SOFTID_CANNOTRUN          SOFTID_CANNOTRUN
#define ERROR_SOFTID_DEAD               SOFTID_DEAD
#define ERROR_PASSWORD_FAILURE	        216                                       



// **************************************************************
// Config Token Function Types

#define  GETTOKENINFORMATION           1  
#define  SETTOKENPASSWORD              2
#define  TRANSFERTOKENTOSMARTCARD      3   
#define  SETTOKENMASTERPASSWORD        4
#define  UNLOCKSCWITHMASTERPASWORD     5 
#define  GETSMARTCARDCOMPONETINFO      6

#define  SMARTCARD_PASSWORDTYPE_ENCRYPTION      1  
#define  SMARTCARD_PASSWORDTYPE_SMARTCARDPIN    2   

typedef struct SCCOMPONENTINFO
{
	DWORD        dwSize;
	char         ReaderName[24];
	int		     iNumberOfTokens;
	int		     iPasswordType;
	BOOL	     bMustHaveUserPassword;
	BOOL	     bMustHaveMasterPassword;
	BOOL	     bSupportMasterPassword;
	BOOL	     bUserPasswordNumeric;
	BOOL 	     bMasterPasswordNumeric;
	BOOL	     bComponetISPasswordProtected;
	BOOL	     bAllowSCTransfer;
	BOOL	     bSCIsLocked;
	BOOL	     bUnused3;
	BOOL	     bUnused4;
} SCCOMPONENTINFO, FAR * LPSCCOMPONENTINFO;


// GETTOKENINFORMATION Structs
//
typedef struct tagCONFIGTKNFunc1Input
{
	DWORD    dwSize;
	char     serialnumber      [24];
	char     deviceID          [24];

} CONFIGTKNFunc1Input, FAR* LPFGETTOKENINFORMATIONINPUT;

typedef struct tagCONFIGTKNFunc1Output
{
	DWORD    dwSize;
	BOOL     bPasswordProtected;
 	char     TokenType         [24];
    char     CopyProtection    [24];    // "On"-If File has Copy Protection,"Off"-If none ,"SmartCard"- If Smart Card

} CONFIGTKNFunc1Output, FAR* LPFGETTOKENINFORMATIONOUTPUT;


// SETTOKENPASSWORD Structs
//
typedef struct tagCONFIGTKNFunc2Input
{
	DWORD    dwSize;
	char     serialnumber         [24];
	char     deviceID             [24];
    char     oldpassword          [24];
    char     newpassword          [24];

} CONFIGTKNFunc2Input, FAR* LPFSETTOKENPASSWORD;


// TRANSFERTOKENTOSMARTCARD Structs
//
typedef struct tagCONFIGTKNFunc3Input
{
	DWORD    dwSize;
	char     serialnumber                   [24];
	char     deviceID                       [24];
    char     currentpassword                [24];
    char     SmartCardUserPINorPassword     [24];
    char     SmartCardMasterPINorPassword   [24];

} CONFIGTKNFunc3Input, FAR* LPFTRANSFERTOKENTOSMARTCARD;


// SETTOKENMASTERPASSWORD Structs
//
typedef struct tagCONFIGTKNFunc4Input
{
	DWORD    dwSize;
	char     serialnumber         [24];
	char     deviceID             [24];
    char     oldpassword          [24];
    char     newpassword          [24];

} CONFIGTKNFunc4Input, FAR* LPFSETTOKENMASTERPASSWORD;

// UNLOCKSCWITHMASTERPASWORD Structs
//
typedef struct tagCONFIGTKNFunc5Input
{
	DWORD    dwSize;
	char     serialnumber         [24];
	char     deviceID             [24];
    char     masterpassword       [24];
    char     newpassword          [24];

} CONFIGTKNFunc5Input, FAR* LPFUNLOCKSCWITHMASTERPASWORD;


// GETSMARTCARDCOMPONENTS Structs
//
typedef struct tagCONFIGTKNFunc6Input
{
   DWORD            dwSize;
   int              iNumberOfComponents;
   int              iDefaultComponent;
   SCCOMPONENTINFO  sComponentInfo [10];
  
} CONFIGTKNFunc6Input, FAR* LPFGETSMARTCARDCOMPONENTS;

 
// **************************************************************

// Possible Token Types
#define  TT_STANDARD_PRN            100   
#define  TT_STANDARD_SEED           101
#define  TT_CHALLENGE_RSP           102
#define  TT_PRN_PASSWORD            103
#define  TT_PASSCODE_PIN            104
#define  TT_SEED_PASSWORD           105    

#define  MAXKEYLENGTH      32             // Max Key length (in BYTES)

typedef struct tagPRNINFO
{
	long			   dll_version_num;
	long			   product_release_num;
	long			   product_version_num; 
	long			   prn_num_length;
	char			   product_serial_num[12];
	long			   option_flags;
	char			   current_PRN[20];
	char			   next_PRN[20];
	unsigned long	   current_time;
	long			   time_zone;
	long			   user_id;
	char			   user_name[20];
	long			   PRN_source;
	long			   error_code;
	char			   error_string[24]; 
	char			   extraspace[50];
} PRNINFO;
typedef PRNINFO FAR* LPPRNINFO;

typedef struct tagTOKENBASICINFO
{
	DWORD    dwSize;
	char     serialnumber[24];
	char     username[24];
	char     deviceID[24];
	char     descriptor[48];

} TOKENBASICINFO, FAR* LPTOKENBASICINFO;

// structure returned by GetTokenError()
typedef struct tagTOKENERRORINFO
{
	int error;
	char error_string[24];
	char detailed_error_string[64];

} TOKENERRORINFO, FAR* LPTOKENERRORINFO;

// struct returned by GetDLLInfo()
typedef struct tagDLLINFO
{
	long dll_version_num;
	long PRN_source;

} DLLINFO, FAR * LPDLLINFO;

#define DLL_VERSION_NUM 5                    
  
// POSSIBLE PRN SOURCE                  
#define SOURCE_SOFTID   1
#define SOURCE_PC1		2
#define SOURCE_SC1		2
#define SOURCE_MODEM1	3
#define SOURCE_OTHER	4

///////////////////////////////////////////////////////////////////////////////
// Old Token API definitions  (Stub functions only)
//
STAUTO32_API_INT  StartSoftID ();
STAUTO32_API_BOOL StopSoftID ();
STAUTO32_API_LONG SetPRNInfo(LPPRNINFO pPRNInfo);
STAUTO32_API_LONG GetPRNInfo (LPPRNINFO pPRNInfo);
STAUTO32_API_BOOL AddPINToPRN (LPCSTR pszPRN, LPCSTR pszPIN, LPSTR pszPRNOut);
STAUTO32_API_INT  GetSelectTokenInfo(LPSTR pSERIALNUMBER, LPSTR pDEVICEID , LPSTR pPinORPassword);
STAUTO32_API_INT  SetEnumTokenInfo(LONG pNumberOfTokens, LONG pDefaultToken, LPTOKENBASICINFO pBUFFER, DWORD BUFFERSIZE);


///////////////////////////////////////////////////////////////////////////////
// New Token API definitions SOFTID 2.0
//

STAUTO32_API_INT OpenTokenService (LPLONG pServiceHandle);

STAUTO32_API_INT ConfigToken (LONG ServiceHandle, INT iFunction, LPVOID pInputBuffer, LPVOID pOutputBuffer, 
                                                                                                LPDWORD pOutputBufferSize);

STAUTO32_API_INT EnumToken (LONG ServiceHandle, LPLONG pNumberOfTokens, LPLONG pDefaultToken, 
                             					         LPVOID  pBuffer, LPDWORD pBufferSize);
STAUTO32_API_INT GetPasscode (LONG ServiceHandle, LPCSTR pPin, LPSTR pPasscode, LPSTR pNextPasscode, 
                                                                  LPSTR pPRN, LPSTR pNextPRN);
STAUTO32_API_INT GetTokenError (LONG ServiceHandle, LPTOKENERRORINFO pErrorInfo);

STAUTO32_API_INT GetDLLInfo (LPDLLINFO pDllInfo);
STAUTO32_API_INT GetDeviceInfo (LONG ServiceHandle, LPCSTR pPinORPassword, LPPRNINFO pPRNInfo);
STAUTO32_API_INT SelectToken (LONG ServiceHandle, LPCSTR pSerialNumber, LPCSTR pDEVICEID, LPCSTR pPassword);

STAUTO32_API_INT NewPinMode (LONG ServiceHandle, LPCSTR pOldPin, LPCSTR pNewPin);
STAUTO32_API_INT CloseTokenService (LONG ServiceHandle);
STAUTO32_API_INT SetTokenTime (LONG ServiceHandle, LONG time);

//If Token API is being used for internal RSA projects then include the 
//extended Token API functionality, 3rd parties need not to have access to this functionality.
#ifdef _RSA_INTERNAL
#include "stauto32ext.h"
#endif

//////////////////////////////////////////////////////////////////////////////
// USEFULL TYPEDEFS: use when casting values from GetProcAddress()
//  
// "Old" API functions
typedef int    (SDIAPI *STARTSOFTID)         ();
typedef int    (SDIAPI *STOPSOFTID)          ();
typedef BOOL   (SDIAPI *ADDPINTOPRN)         (LPCSTR, LPCSTR, LPSTR);
typedef long   (SDIAPI *GETPRNINFO)          (LPPRNINFO);
typedef long   (SDIAPI *SETPRNINFO)          (LPPRNINFO);
typedef int    (SDIAPI *GETSELECTTOKENINFO)  (LONG, LPSTR, LPSTR, LPSTR);
typedef int    (SDIAPI *SETENUMTOKENINFO)	   (LONG, LONG, LONG, LPTOKENBASICINFO, DWORD);


// "New" API functions (SOFTID 2.0)
typedef int  (SDIAPI *OPENTOKENSERVICE)   (LPLONG);
typedef int  (SDIAPI *CONFIGTOKEN)        (LONG, INT, LPVOID, LPVOID, LPDWORD);
typedef int  (SDIAPI *ENUMTOKEN)		      (LONG, LPLONG, LPLONG, LPTOKENBASICINFO, LPDWORD);
typedef int  (SDIAPI *GETPASSCODE)        (LONG, LPCSTR, LPSTR, LPSTR, LPSTR, LPSTR);
typedef int  (SDIAPI *GETTOKENERROR)      (LONG, LPTOKENERRORINFO);
typedef int  (SDIAPI *GETDLLINFO)         (LPDLLINFO);
typedef int  (SDIAPI *GETDEVICEINFO)      (LONG,LPCSTR, LPPRNINFO);
typedef int  (SDIAPI *NEWPINMODE)         (LONG, LPCSTR, LPCSTR);
typedef int  (SDIAPI *CLOSETOKENSERVICE)  (LONG);
typedef int  (SDIAPI *SELECTTOKEN)        (LONG, LPCSTR, LPCSTR, LPCSTR);
typedef int  (SDIAPI *SETTOKENTIME)		   (LONG, LONG);

#ifdef __cplusplus
}
#endif

#endif
