#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,
	INVALID_STATE,
	INVALID_INPUT,
	ID_INVALID,
	ID_NOT_OPEN,
	TAG_INVALID,
	WRITE_FAILED,
	NOT_LOGGED_IN,
	NOT_INITIALIZED,
	BAD_PASSWORD,
	IN_PROGRESS,
	NOT_ENOUGH_SPACE,
	DONE,
	BUTTON_PRESS_CANCELED,
	BUTTON_PRESS_TIMEOUT,
	UNKNOWN_DB_FORMAT,
	DEVICE_NOT_WIPED
};

#define SIGNET_MAJOR_VERSION 1
#define SIGNET_MINOR_VERSION 3
#define SIGNET_STEP_VERSION 4

#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
