package dfu;

// Version 0.1

// Definition of enums and types
enum OpCode {
	RESET	= 0;
	INIT	= 1;
}

enum FwType {
	APPLICATION				= 0; // default, compatible with proto3
	SOFTDEVICE				= 1;
	BOOTLOADER				= 2;
	SOFTDEVICE_BOOTLOADER	= 3;
}

enum HashType {
	NO_HASH	= 0;
	CRC		= 1;
	SHA128	= 2;
	SHA256	= 3;
	SHA512	= 4;
}

message Hash
{
	required HashType 	hash_type	= 1;
	required bytes 		hash		= 2;
}

// Commands data
message InitCommand {
	optional uint32	fw_version	= 1;
	optional uint32	hw_version	= 2;
	repeated uint32	sd_req		= 3 [packed = true]; // packed option is default in proto3
	optional FwType	type		= 4;

	optional uint32	sd_size		= 5;
	optional uint32	bl_size		= 6;
	optional uint32	app_size	= 7;

	optional Hash	hash		= 8;
    
    optional bool   is_debug    = 9 [default = false];
}

message ResetCommand
{
	required uint32 timeout	= 1;
}

// Command type
message Command {
	optional OpCode			op_code	= 1;
	optional InitCommand	init 	= 2;
	optional ResetCommand	reset 	= 3;
}

// Signed command types
enum SignatureType {
	ECDSA_P256_SHA256	= 0;
	ED25519				= 1;
}

message SignedCommand {
	required Command		command			= 1;
	required SignatureType	signature_type	= 2;
	required bytes			signature		= 3;
}

// Parent packet type
message Packet {
	optional Command 		command			= 1;
	optional SignedCommand	signed_command	= 2;
}