#ifndef __SAMPLE_22_H__
#define __SAMPLE_22_H__

//By default, program compiled at IBM-compatible PC	has the address alignment issues which don't exist 
//in C51 environment. For convenience of data-handling,we use the compact-pack mode for storing the
//exchanging data-buffer used between PC and SenseLock EL device.For more ,pls refer to sample 17.

#ifdef _WIN32
#pragma pack(push, 1)
#endif 

#define IO_PACKAGE_HEADER_SIZE 2 //IO package header length:tag+len
#define MAX_IO_DATA_SIZE	0xf8 // maximum IO data size

#define MAX_BUFF_SIZE  0xf0      //maximum buffer size  

/* command group definition */
#define CMD_UPDATE 0x01
#define CMD_READ   0x02
#define CMD_CREATE 0x03

/* common error code. */
#define ERR_SUCCESS				0x00	// success
#define ERR_SES					0x80	// SES function execution error
#define ERR_INVALID_PARAMETER	0x81	// invalid parameter

/* user-specific data block */
typedef struct _FILE_OP_BLOCK
{							                                                                                               
	unsigned short fid;     // objective file ID 
	unsigned short offset;  // operating offset
	unsigned char len; 	    // buffer length(update)
							// read length(read)		
	unsigned char buff[MAX_BUFF_SIZE];
} FILE_OP_BLOCK;


typedef struct _FILE_CREATE_BLOCK
{							                                                                                               
	unsigned short fid;     // objective file ID 
	unsigned short fsize;   // file size
	unsigned char  ftype;	// file type
	unsigned char  flag; 	// create flag
} FILE_CREATE_BLOCK;

/* create file type, quoted from ses_v3.h */
#define SES_FILE_TYPE_EXE		0x00			/* executable file			*/
#define SES_FILE_TYPE_EXE_DATA	0x01			/* data file				*/
#define SES_FILE_TYPE_RSA_PUB	0x02			/* RSA public key file		*/
#define SES_FILE_TYPE_RSA_SEC	0x03			/* RSA secret key file		*/

/* create file flag, quoted from ses_v3.h */
#define CREATE_OPEN_ALWAYS		0x00			/* open if file already exist, create a new file if not existing	*/
#define CREATE_FILE_NEW			0x01			/* create a new file and open it									*/
#define CREATE_OPEN_EXISTING	0x02			/* open a file exist												*/



/* IO package */
typedef struct _IO_PACKAGE
{	
	unsigned char tag;	
	unsigned char len;
	unsigned char buff[MAX_IO_DATA_SIZE];
} IO_PACKAGE;

#ifdef _WIN32
#pragma pack(pop)
#endif


#endif //__SAMPLE_22_H__