#ifndef SIGNETDEV_COMMON_H
#define SIGNETDEV_COMMON_H

enum device_state {
	DS_DISCONNECTED,
	DS_RESET, //Defunct
	DS_UNINITIALIZED,
	DS_INITIALIZING,
	DS_WIPING,
	DS_ERASING_PAGES,
	DS_FIRMWARE_UPDATE,
	DS_LOGGED_OUT,
	DS_LOGGED_IN,
	DS_BACKING_UP_DEVICE,
	DS_RESTORING_DEVICE,
	DS_BOOTLOADER
};

enum command_responses {
	OKAY,		// 0
	INVALID_STATE,	// 1
	INVALID_INPUT,	// 2
	ID_INVALID,	// 3
	ID_NOT_OPEN,	// 4
	TAG_INVALID,	// 5
	WRITE_FAILED,	// 6
	NOT_LOGGED_IN,	// 7
	NOT_INITIALIZED,// 8
	BAD_PASSWORD,	// 9
	IN_PROGRESS,	// 10
	NOT_ENOUGH_SPACE,	// 11
	DONE,			// 12
	BUTTON_PRESS_CANCELED,	// 13
	BUTTON_PRESS_TIMEOUT,	// 14
	UNKNOWN_DB_FORMAT,	// 15
	DEVICE_NOT_WIPED	// 16
};

#define SIGNET_MAJOR_VERSION 1
#define SIGNET_MINOR_VERSION 3
#define SIGNET_STEP_VERSION 6

#define SIGNET_ERROR_UNKNOWN -1
#define SIGNET_ERROR_DISCONNECT -2
#define SIGNET_ERROR_QUIT -3
#define SIGNET_ERROR_OVERFLOW -4

#define AES_BLK_SIZE (16)
#define AES_128_KEY_SIZE (16)
#define AES_256_KEY_SIZE (32)

#define LOGIN_KEY_SZ (AES_256_KEY_SIZE)
#define SALT_SZ_V1 (AES_128_KEY_SIZE)
#define SALT_SZ_V2 (AES_256_KEY_SIZE)
#define HASH_FN_SZ (AES_BLK_SIZE)

#define INVALID_UID (0)
#define MAX_UID ((1<<12)-1)
#define MIN_UID (1)

#ifdef FIRMWARE
#include "types.h"
#else
#include <stdint.h>
typedef unsigned long long u64;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;
typedef int32_t s32;
typedef int16_t s16;
typedef int8_t s8;
#endif

#define NUM_CLEARTEXT_PASS 4
#define CLEARTEXT_PASS_SIZE 256
#define CLEARTEXT_PASS_NAME_SIZE 64
#define CLEARTEXT_PASS_PASS_SIZE 64
#define CLEARTEXT_PASS_SCANCODE_ENTRIES ((CLEARTEXT_PASS_SIZE - 2 - CLEARTEXT_PASS_NAME_SIZE - CLEARTEXT_PASS_PASS_SIZE)/2)

struct cleartext_pass {
	u8 format;
	u8 scancode_entries;
	char name_utf8[CLEARTEXT_PASS_NAME_SIZE];
	char password_utf8[CLEARTEXT_PASS_PASS_SIZE];
	u8 scancodes[CLEARTEXT_PASS_SCANCODE_ENTRIES * 2];
};

#endif
