123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- #ifndef NRF_DFU_REQ_HANDLER_H__
- #define NRF_DFU_REQ_HANDLER_H__
- #include <stdint.h>
- #include <stdbool.h>
- #include "app_util_platform.h"
- #include "nrf_dfu_flash.h"
- #include "nrf_dfu_types.h"
- #ifdef __cplusplus
- extern "C"
- {
- #endif
- ANON_UNIONS_ENABLE;
- typedef enum
- {
- NRF_DFU_OBJ_TYPE_INVALID,
- NRF_DFU_OBJ_TYPE_COMMAND,
- NRF_DFU_OBJ_TYPE_DATA,
- } nrf_dfu_obj_type_t;
- typedef enum
- {
- NRF_DFU_OP_PROTOCOL_VERSION = 0x00,
- NRF_DFU_OP_OBJECT_CREATE = 0x01,
- NRF_DFU_OP_RECEIPT_NOTIF_SET = 0x02,
- NRF_DFU_OP_CRC_GET = 0x03,
- NRF_DFU_OP_OBJECT_EXECUTE = 0x04,
- NRF_DFU_OP_OBJECT_SELECT = 0x06,
- NRF_DFU_OP_MTU_GET = 0x07,
- NRF_DFU_OP_OBJECT_WRITE = 0x08,
- NRF_DFU_OP_PING = 0x09,
- NRF_DFU_OP_HARDWARE_VERSION = 0x0A,
- NRF_DFU_OP_FIRMWARE_VERSION = 0x0B,
- NRF_DFU_OP_ABORT = 0x0C,
- NRF_DFU_OP_RESPONSE = 0x60,
- NRF_DFU_OP_INVALID = 0xFF,
- } nrf_dfu_op_t;
- typedef enum
- {
- NRF_DFU_RES_CODE_INVALID = 0x00,
- NRF_DFU_RES_CODE_SUCCESS = 0x01,
- NRF_DFU_RES_CODE_OP_CODE_NOT_SUPPORTED = 0x02,
- NRF_DFU_RES_CODE_INVALID_PARAMETER = 0x03,
- NRF_DFU_RES_CODE_INSUFFICIENT_RESOURCES = 0x04,
- NRF_DFU_RES_CODE_INVALID_OBJECT = 0x05,
- NRF_DFU_RES_CODE_UNSUPPORTED_TYPE = 0x07,
- NRF_DFU_RES_CODE_OPERATION_NOT_PERMITTED = 0x08,
- NRF_DFU_RES_CODE_OPERATION_FAILED = 0x0A,
- NRF_DFU_RES_CODE_EXT_ERROR = 0x0B,
- } nrf_dfu_result_t;
- typedef enum
- {
- NRF_DFU_FIRMWARE_TYPE_SOFTDEVICE = 0x00,
- NRF_DFU_FIRMWARE_TYPE_APPLICATION = 0x01,
- NRF_DFU_FIRMWARE_TYPE_BOOTLOADER = 0x02,
- NRF_DFU_FIRMWARE_TYPE_UNKNOWN = 0xFF,
- } nrf_dfu_firmware_type_t;
- typedef struct
- {
- uint8_t version;
- } nrf_dfu_response_protocol_t;
- typedef struct
- {
- uint32_t part;
- uint32_t variant;
- struct
- {
- uint32_t rom_size;
- uint32_t ram_size;
- uint32_t rom_page_size;
- } memory;
- } nrf_dfu_response_hardware_t;
- typedef struct
- {
- nrf_dfu_firmware_type_t type;
- uint32_t version;
- uint32_t addr;
- uint32_t len;
- } nrf_dfu_response_firmware_t;
- typedef struct
- {
- uint32_t offset;
- uint32_t crc;
- uint32_t max_size;
- } nrf_dfu_response_select_t;
- typedef struct
- {
- uint32_t offset;
- uint32_t crc;
- } nrf_dfu_response_create_t;
- typedef struct
- {
- uint32_t offset;
- uint32_t crc;
- } nrf_dfu_response_write_t;
- typedef struct
- {
- uint32_t offset;
- uint32_t crc;
- } nrf_dfu_response_crc_t;
- typedef struct
- {
- uint8_t id;
- } nrf_dfu_response_ping_t;
- typedef struct
- {
- uint16_t size;
- } nrf_dfu_response_mtu_t;
- typedef struct
- {
- nrf_dfu_op_t request;
- nrf_dfu_result_t result;
- union
- {
- nrf_dfu_response_protocol_t protocol;
- nrf_dfu_response_hardware_t hardware;
- nrf_dfu_response_firmware_t firmware;
- nrf_dfu_response_select_t select;
- nrf_dfu_response_create_t create;
- nrf_dfu_response_write_t write;
- nrf_dfu_response_crc_t crc;
- nrf_dfu_response_ping_t ping;
- nrf_dfu_response_mtu_t mtu;
- };
- } nrf_dfu_response_t;
- typedef struct
- {
- uint8_t image_number;
- } nrf_dfu_request_firmware_t;
- typedef struct
- {
- uint32_t object_type;
- } nrf_dfu_request_select_t;
- typedef struct
- {
- uint32_t object_type;
- uint32_t object_size;
- } nrf_dfu_request_create_t;
- typedef struct
- {
- uint8_t const * p_data;
- uint16_t len;
- } nrf_dfu_request_write_t;
- typedef struct
- {
- uint8_t id;
- } nrf_dfu_request_ping_t;
- typedef struct
- {
- uint16_t size;
- } nrf_dfu_request_mtu_t;
- typedef struct
- {
- uint32_t target;
- } nrf_dfu_request_prn_t;
- typedef void (*nrf_dfu_response_callback_t)(nrf_dfu_response_t * p_res, void * p_context);
- typedef struct
- {
- nrf_dfu_op_t request;
- void * p_context;
- struct
- {
- nrf_dfu_response_callback_t response;
- nrf_dfu_flash_callback_t write;
- } callback;
- union
- {
- nrf_dfu_request_firmware_t firmware;
- nrf_dfu_request_select_t select;
- nrf_dfu_request_create_t create;
- nrf_dfu_request_write_t write;
- nrf_dfu_request_ping_t ping;
- nrf_dfu_request_mtu_t mtu;
- nrf_dfu_request_prn_t prn;
- };
- } nrf_dfu_request_t;
- ret_code_t nrf_dfu_req_handler_init(nrf_dfu_observer_t observer);
- ret_code_t nrf_dfu_req_handler_on_req(nrf_dfu_request_t * p_req);
- ANON_UNIONS_DISABLE;
- #ifdef __cplusplus
- }
- #endif
- #endif
|