/**
 *****************************************************************************************
 *	@file etn_mesh_fota_dis.h
 *
 *	@brief eaton ble mesh fota distribution model header file
 *
 *	@details this custom model from eaton, used to get firmware distribution information
 *
 *	@version C Style Guide Version 1.0
 *
 *	@copyright 2022 Eaton Corporation. All Rights Reserved.
 *
 *****************************************************************************************
 */
#ifndef ETN_MESH_FOTA_DIS_H
#define ETN_MESH_FOTA_DIS_H

/*
 *****************************************************************************************
 *		Headers
 *****************************************************************************************
 */
#include <bluetooth/mesh/model_types.h>
#include <etn_mesh_fota.h>

#ifdef __cplusplus
extern "C" {
#endif

/*
 *****************************************************************************************
 *		Opcodes for eaton mesh fota firmware distribution
 *****************************************************************************************
 */

#define BT_MESH_ETN_FOTA_DIS_UPDATE_START_OP          BT_MESH_MODEL_OP_3( 0x0A, BT_MESH_COMPANY_ID_EATON )
#define BT_MESH_ETN_FOTA_DIS_IMAGE_METADATA_GET_OP    BT_MESH_MODEL_OP_3( 0x0B, BT_MESH_COMPANY_ID_EATON )
#define BT_MESH_ETN_FOTA_DIS_RECV_LIST_GET_OP         BT_MESH_MODEL_OP_3( 0x0C, BT_MESH_COMPANY_ID_EATON )
#define BT_MESH_ETN_FOTA_DIS_STATE_GET_OP             BT_MESH_MODEL_OP_3( 0x0D, BT_MESH_COMPANY_ID_EATON )
#define BT_MESH_ETN_FOTA_DIS_IMAGE_GET_OP             BT_MESH_MODEL_OP_3( 0x0E, BT_MESH_COMPANY_ID_EATON )

#define BT_MESH_ETN_FOTA_DIS_UPDATE_START_MSG_MINLEN        1
#define BT_MESH_ETN_FOTA_DIS_IMAGE_METADATA_GET_MSG_MINLEN  sizeof( struct fota_dis_metadata )
#define BT_MESH_ETN_FOTA_DIS_RECV_LIST_GET_MSG_MINLEN       sizeof( uint64_t )
#define BT_MESH_ETN_FOTA_DIS_STATE_GET_MSG_MINLEN           1
#define BT_MESH_ETN_FOTA_DIS_IMAGE_GET_MSG_MINLEN           1

#define BT_MESH_ETN_FOTA_SRV_MESSAGE_MAXLEN ( sizeof( struct fota_dis_metadata ) + 1 )

struct fota_dis_metadata
{
	uint8_t timeout;// timeout in seconds for image download to complete
	uint8_t TTL;// Time To Live in hops, for number of hops an image packet can make on mesh
	uint8_t image_version_int;	// The integer part for version of firmware file being downloaded
	uint8_t image_version_dec;	// The decimal part for version of firmware file being downloaded
	uint16_t user_id;// User ID of the user who initiated DFU
	uint16_t num_of_blocks;// Number of BLOCKs in the firmware BLOB to be received
	uint64_t sz_of_fw_image;// size of firmware file in bytes
} __packed;

/**
 * @brief	Firmware distribution server model's states
 * @details	BLE Mesh Firmware distribution server model's State values
 */
enum fota_dis_srv_state
{
	BT_MESH_DEV_AVLBL_TO_FW_UPDATE,			// =0
	BT_MESH_FW_UPLOAD_METADATA_PARAMS,		// =1
	BT_MESH_FW_DISTRBN_LIST,				// =2
	BT_MESH_FW_BLOB_TRANSFER_IN_PROGRESS,	// =3
	BT_MESH_FW_DISTRBN_IN_PROGRESS,			// =4
	BT_MESH_FW_DISTRBN_SRV_ERROR,			// =5
	BT_MESH_DEV_FW_DSTRBN_STATE_ERR,		// =6
};

/**
 * @brief	Firmware distribution server model's metadata state status indicators
 * @details	BLE Mesh Firmware distribution server model Metadata reception status
 */
enum fota_dis_srv_metadata_status
{
	BT_MESH_DEV_METADATA_RECEIVED,			// =0
	BT_MESH_DEV_METADATA_RESEND,			// =1
	BT_MESH_DEV_METADATA_RECEIVE_FAILED,	// =2
	BT_MESH_DEV_METADATA_STATE_ERR,			// =3
};

/**
 * @brief	Firmware distribution server model's DFU state status indicators
 * @details	BLE Mesh Firmware distribution server model DFU command reception status
 */
enum fota_dis_cmd_status
{
	BT_MESH_DEV_DFU_CMD_RECEIVED,	// =0
	BT_MESH_DEV_DFU_CMD_FAILED,		// =1
};

/**
 * @brief	Firmware distribution server model's distribution list state status indicators
 * @details	BLE Mesh Firmware distribution server distribution list reception status
 */
enum fota_dis_list_status
{
	BT_MESH_DEV_DSTRBN_LIST_RECEIVED,		// =0
	BT_MESH_DEV_DSTRBN_LIST_RESEND,			// =1
	BT_MESH_DEV_DSTRBN_LIST_RECEIVE_FAILED,	// =2
	BT_MESH_DEV_DSTRBN_LIST_STATE_ERR,		// =3
};

#ifdef __cplusplus
}
#endif

#endif