/*
 * SecBus - This file is part of SecBus
 * Copyright (C) 2012 - Telecom ParisTech
 * 
 * This file must be used under the terms of the CeCILL.
 * This source file is licensed as described in the file COPYING, which
 * you should have received as part of this distribution.  The terms
 * are also available at    
 * http://www.cecill.info/licences/Licence_CeCILL_V1.1-US.txt
 *
 */

#ifndef TYPES__H
#define TYPES__H

#include "buffer.h"
#include "global.h"

typedef unsigned int addr_t;
typedef Buffer cacheblock_t;
typedef cacheblock_t * pCacheblock_t;

template<typename _other_t> struct CacheSet_st 
{
  /**< Pointer to an array of cache block */
  pCacheblock_t block; 
  /**< Other information */
  _other_t other;
};

/*! \Other Information needs 1 byte : used in ALAP policy as "dirty counter" by cache set */
typedef CacheSet_st<char> CacheSet_st_t;

#define SECBUS_DEBUG VERB_NONE

#define _secbus_debug(f, l, c)      \
  do {								\
    if (VERB_##l <= SECBUS_DEBUG) {	\
      f<<c;						\
    }                               \
  }while (0)							

enum {
  VERB_NONE,
  VERB_STAT,
  VERB_TRACE,
  VERB_DEBUG,
};

typedef enum 
{
  REGULAR = 0,
  MASTER_BLOCK = 1,
  INTEGRITY = 2
}page_id_e;

typedef enum 
{
  NO_CONFIDENTIALITY = 0,
  OTP = 1, 
  BC = 2,
}confidentiality_mode_e;

typedef enum
{
  NO_INTEGRITY = 0,
  MAC = 1,
  HASH_TREE = 2
}integrity_mode_e;

typedef enum 
{
  READ = 0,
  WRITE, 
  SYNCHRONIZE,
  RESTORE, 
  INVALIDATE,
  IMMEDIATE
}cmd_e;

typedef enum 
{
  READ_SC = 0,
  WRITE_PSPE, 
  WRITE_SP,
}sec_cmd_e;

typedef enum 
{
  CREATE_SP = 0, 
  CREATE_PSPE,
  INITIALIZE_INTEGRITY,
  INIT_MBHT
}secbus_cmd_e;

typedef enum 
{
  SECBUS_IDLE = 0,
  SECBUS_BUSY = 1
}secbus_status_e;

typedef enum 
{
  CHECK = 0,
  UPDATE,
  INITIALIZE,
  INITIALIZE_PAGE,
  INIT_MHT
}integrity_cmd_e;


typedef enum 
{
  MASTER = 0,
  HTM
}initiator_e;

/*! \Cache Replacement Policy when associativity is greater than 1 */
typedef enum 
{
  LRU = 0,
  FIFO
}ReplacementPolicy_e;

typedef enum 
{
  SIZE_4M = 0,
  SIZE_4K,
  SIZE_OTHER
}PageSize_e;

typedef enum 
{
  SLAVE_PSPE = 0,
  MASTER_PSPE
}PSPEtype_e;

typedef enum 
{
  FIRST = 0,
  SECOND
}leveltype_e;

enum WritePolicy_e
{
  WRITE_THROUGH = 0,
  WRITE_BACK
};

typedef struct 
{
  /**< Cache name. */
  char name[10];
  /**< Cache enabled. */
  bool enable;
  /**< Number of blocks per set */
  int associativity ; 
  /**< Size of cache block in word */
  int block_size;
  /**< Number of sets. */
  int set_number;	
  /**<Replacement Policy. */
  ReplacementPolicy_e replacement_policy;
  /**<Write Policy */
  WritePolicy_e write_policy;
  /**<treshold/set */
  int threshold;

} cache_param_st;

typedef struct 
{
  /**< MPSPE */
  int mpspe[2];
  /**< SP */
  int sp[4];
  /**< Page address*/
  addr_t page_addr;
} master_security_context_st;

typedef struct 
{
  /**< SPSPE */
  int spspe[2];
  /**< Page address*/
  addr_t page_addr;
  /**< Slave PSPE address*/
  addr_t spspe_addr;
} slave_security_context_st;

#endif

