1 /* 2 * Copyright (c) 2020 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_DFU_H__ 8 #define ZEPHYR_INCLUDE_BLUETOOTH_MESH_DFU_H__ 9 10 #include <sys/types.h> 11 12 #include <zephyr/kernel.h> 13 #include <zephyr/bluetooth/mesh/blob.h> 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 /** 20 * @defgroup bt_mesh_dfu Bluetooth Mesh Device Firmware Update 21 * @ingroup bt_mesh 22 * @{ 23 */ 24 25 #ifndef CONFIG_BT_MESH_DFU_FWID_MAXLEN 26 #define CONFIG_BT_MESH_DFU_FWID_MAXLEN 0 27 #endif 28 29 #ifndef CONFIG_BT_MESH_DFU_METADATA_MAXLEN 30 #define CONFIG_BT_MESH_DFU_METADATA_MAXLEN 0 31 #endif 32 33 #ifndef CONFIG_BT_MESH_DFU_URI_MAXLEN 34 #define CONFIG_BT_MESH_DFU_URI_MAXLEN 0 35 #endif 36 37 /** DFU transfer phase. */ 38 enum bt_mesh_dfu_phase { 39 /** Ready to start a Receive Firmware procedure. */ 40 BT_MESH_DFU_PHASE_IDLE, 41 42 /** The Transfer BLOB procedure failed. */ 43 BT_MESH_DFU_PHASE_TRANSFER_ERR, 44 45 /** The Receive Firmware procedure is being executed. */ 46 BT_MESH_DFU_PHASE_TRANSFER_ACTIVE, 47 48 /** The Verify Firmware procedure is being executed. */ 49 BT_MESH_DFU_PHASE_VERIFY, 50 51 /** The Verify Firmware procedure completed successfully. */ 52 BT_MESH_DFU_PHASE_VERIFY_OK, 53 54 /** The Verify Firmware procedure failed. */ 55 BT_MESH_DFU_PHASE_VERIFY_FAIL, 56 57 /** The Apply New Firmware procedure is being executed. */ 58 BT_MESH_DFU_PHASE_APPLYING, 59 60 /** Firmware transfer has been canceled. */ 61 BT_MESH_DFU_PHASE_TRANSFER_CANCELED, 62 63 /** Firmware applying succeeded. */ 64 BT_MESH_DFU_PHASE_APPLY_SUCCESS, 65 66 /** Firmware applying failed. */ 67 BT_MESH_DFU_PHASE_APPLY_FAIL, 68 69 /** The current phase is unknown. 70 * 71 * This is a metaphase, used by the Firmware Update Client to keep track of 72 * the Target state, and is not defined by the specification. 73 */ 74 BT_MESH_DFU_PHASE_UNKNOWN, 75 }; 76 77 78 /** DFU status. */ 79 enum bt_mesh_dfu_status { 80 /** The message was processed successfully. */ 81 BT_MESH_DFU_SUCCESS, 82 83 /** Insufficient resources on the node */ 84 BT_MESH_DFU_ERR_RESOURCES, 85 86 /** The operation cannot be performed while the Server is in the current 87 * phase. 88 */ 89 BT_MESH_DFU_ERR_WRONG_PHASE, 90 91 /** An internal error occurred on the node. */ 92 BT_MESH_DFU_ERR_INTERNAL, 93 94 /** The message contains a firmware index value that is not expected. */ 95 BT_MESH_DFU_ERR_FW_IDX, 96 97 /** The metadata check failed. */ 98 BT_MESH_DFU_ERR_METADATA, 99 100 /** The Server cannot start a firmware update. */ 101 BT_MESH_DFU_ERR_TEMPORARILY_UNAVAILABLE, 102 103 /** Another BLOB transfer is in progress. */ 104 BT_MESH_DFU_ERR_BLOB_XFER_BUSY, 105 }; 106 107 /** Expected effect of a DFU transfer. */ 108 enum bt_mesh_dfu_effect { 109 /** No changes to node Composition Data. */ 110 BT_MESH_DFU_EFFECT_NONE, 111 112 /** Node Composition Data changed and the node does not support remote 113 * provisioning. 114 */ 115 BT_MESH_DFU_EFFECT_COMP_CHANGE_NO_RPR, 116 117 /** Node Composition Data changed, and remote provisioning is supported. 118 * The node supports remote provisioning and Composition Data Page 119 * 0x80. Page 0x80 contains different Composition Data than Page 0x0. 120 */ 121 BT_MESH_DFU_EFFECT_COMP_CHANGE, 122 123 /** Node will be unprovisioned after the update. */ 124 BT_MESH_DFU_EFFECT_UNPROV, 125 }; 126 127 /** Action for DFU iteration callbacks. */ 128 enum bt_mesh_dfu_iter { 129 /** Stop iterating. */ 130 BT_MESH_DFU_ITER_STOP, 131 132 /** Continue iterating. */ 133 BT_MESH_DFU_ITER_CONTINUE, 134 }; 135 136 /** DFU image instance. 137 * 138 * Each DFU image represents a single updatable firmware image. 139 */ 140 struct bt_mesh_dfu_img { 141 /** Firmware ID. */ 142 const void *fwid; 143 144 /** Length of the firmware ID. */ 145 size_t fwid_len; 146 147 /** Update URI, or NULL. 148 * 149 * Must use one of the http: or https: schemes. 150 */ 151 const char *uri; 152 }; 153 154 /** DFU image slot for DFU distribution. */ 155 struct bt_mesh_dfu_slot { 156 /** Size of the firmware in bytes. */ 157 size_t size; 158 /** Length of the firmware ID. */ 159 size_t fwid_len; 160 /** Length of the metadata. */ 161 size_t metadata_len; 162 /** Length of the image URI. */ 163 size_t uri_len; 164 /** Firmware ID. */ 165 uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN]; 166 /** Metadata. */ 167 uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN]; 168 /** Image URI. */ 169 char uri[CONFIG_BT_MESH_DFU_URI_MAXLEN]; 170 }; 171 172 /** @} */ 173 174 #ifdef __cplusplus 175 } 176 #endif 177 178 #endif /* ZEPHYR_INCLUDE_BLUETOOTH_MESH_DFU_H__ */ 179