Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of nRF51822 by
ble_dfu.h
00001 /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. 00002 * 00003 * The information contained herein is property of Nordic Semiconductor ASA. 00004 * Terms and conditions of usage are described in detail in NORDIC 00005 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 00006 * 00007 * Licensees are granted free, non-transferable use of the information. NO 00008 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 00009 * the file. 00010 * 00011 */ 00012 00013 /**@file 00014 * 00015 * @defgroup ble_sdk_srv_dfu Device Firmware Update Service 00016 * @{ 00017 * @ingroup ble_sdk_srv 00018 * @brief Device Firmware Update Service 00019 * 00020 * @details The Device Firmware Update (DFU) service is a GATT based service that can be used for 00021 * performing firmware updates over BLE. Note that this implementation uses vendor 00022 * specific UUIDs for service and characteristics and is intended to demonstrate the 00023 * firmware updates over BLE. Refer @ref ota_spec_sec and @ref 00024 * ota_profile_section for more information on the service and profile respectively. 00025 */ 00026 00027 #ifndef BLE_DFU_H__ 00028 #define BLE_DFU_H__ 00029 00030 #include <stdint.h> 00031 #include "ble_gatts.h" 00032 #include "ble_gap.h" 00033 #include "ble.h" 00034 #include "ble_srv_common.h " 00035 00036 #define BLE_DFU_SERVICE_UUID 0x1530 /**< The UUID of the DFU Service. */ 00037 #define BLE_DFU_PKT_CHAR_UUID 0x1532 /**< The UUID of the DFU Packet Characteristic. */ 00038 #define BLE_DFU_CTRL_PT_UUID 0x1531 /**< The UUID of the DFU Control Point. */ 00039 #define BLE_DFU_STATUS_REP_UUID 0x1533 /**< The UUID of the DFU Status Report Characteristic. */ 00040 #define BLE_DFU_REV_CHAR_UUID 0x1534 /**< The UUID of the DFU Revision Characteristic. */ 00041 00042 /**@brief DFU Event type. 00043 * 00044 * @details This enumeration contains the types of events that will be received from the DFU Service. 00045 */ 00046 typedef enum 00047 { 00048 BLE_DFU_START, /**< The event indicating that the peer wants the application to prepare for a new firmware update. */ 00049 BLE_DFU_RECEIVE_INIT_DATA, /**< The event indicating that the peer wants the application to prepare to receive init parameters. */ 00050 BLE_DFU_RECEIVE_APP_DATA, /**< The event indicating that the peer wants the application to prepare to receive the new firmware image. */ 00051 BLE_DFU_VALIDATE, /**< The event indicating that the peer wants the application to validate the newly received firmware image. */ 00052 BLE_DFU_ACTIVATE_N_RESET, /**< The event indicating that the peer wants the application to undergo activate new firmware and restart with new valid application */ 00053 BLE_DFU_SYS_RESET, /**< The event indicating that the peer wants the application to undergo a reset and start the currently valid application image.*/ 00054 BLE_DFU_PKT_RCPT_NOTIF_ENABLED, /**< The event indicating that the peer has enabled packet receipt notifications. It is the responsibility of the application to call @ref ble_dfu_pkts_rcpt_notify each time the number of packets indicated by num_of_pkts field in @ref ble_dfu_evt_t is received.*/ 00055 BLE_DFU_PKT_RCPT_NOTIF_DISABLED, /**< The event indicating that the peer has disabled the packet receipt notifications.*/ 00056 BLE_DFU_PACKET_WRITE, /**< The event indicating that the peer has written a value to the 'DFU Packet' characteristic. The data received from the peer will be present in the @ref BLE_DFU_PACKET_WRITE element contained within @ref ble_dfu_evt_t.*/ 00057 BLE_DFU_BYTES_RECEIVED_SEND /**< The event indicating that the peer is requesting for the number of bytes of firmware data last received by the application. It is the responsibility of the application to call @ref ble_dfu_pkts_rcpt_notify in response to this event. */ 00058 } ble_dfu_evt_type_t; 00059 00060 /**@brief DFU Procedure type. 00061 * 00062 * @details This enumeration contains the types of DFU procedures. 00063 */ 00064 typedef enum 00065 { 00066 BLE_DFU_START_PROCEDURE = 1, /**< DFU Start procedure.*/ 00067 BLE_DFU_INIT_PROCEDURE = 2, /**< DFU Initialization procedure.*/ 00068 BLE_DFU_RECEIVE_APP_PROCEDURE = 3, /**< Firmware receiving procedure.*/ 00069 BLE_DFU_VALIDATE_PROCEDURE = 4, /**< Firmware image validation procedure .*/ 00070 BLE_DFU_PKT_RCPT_REQ_PROCEDURE = 8 /**< Packet receipt notification request procedure. */ 00071 } ble_dfu_procedure_t; 00072 00073 /**@brief DFU Response value type. 00074 */ 00075 typedef enum 00076 { 00077 BLE_DFU_RESP_VAL_SUCCESS = 1, /**< Success.*/ 00078 BLE_DFU_RESP_VAL_INVALID_STATE, /**< Invalid state.*/ 00079 BLE_DFU_RESP_VAL_NOT_SUPPORTED, /**< Operation not supported.*/ 00080 BLE_DFU_RESP_VAL_DATA_SIZE, /**< Data size exceeds limit.*/ 00081 BLE_DFU_RESP_VAL_CRC_ERROR, /**< CRC Error.*/ 00082 BLE_DFU_RESP_VAL_OPER_FAILED /**< Operation failed.*/ 00083 } ble_dfu_resp_val_t; 00084 00085 00086 /**@brief DFU Packet structure. 00087 * 00088 * @details This structure contains the value of the DFU Packet characteristic as written by the 00089 * peer and the length of the value written. It will be filled by the DFU Service when the 00090 * peer writes to the DFU Packet characteristic. 00091 */ 00092 typedef struct 00093 { 00094 uint8_t len; /**< Length of the packet received. */ 00095 uint8_t * p_data; /**< Pointer to the received packet. This will point to a word aligned memory location.*/ 00096 } ble_dfu_pkt_write_t; 00097 00098 /**@brief Packet receipt notification request structure. 00099 * 00100 * @details This structure contains the contents of the packet receipt notification request 00101 * sent by the DFU Controller. 00102 */ 00103 typedef struct 00104 { 00105 uint16_t num_of_pkts; /**< The number of packets of firmware data to be received by application before sending the next Packet Receipt Notification to the peer. */ 00106 } ble_pkt_rcpt_notif_req_t; 00107 00108 /**@brief DFU Event structure. 00109 * 00110 * @details This structure contains the event generated by the DFU Service based on the data 00111 * received from the peer. 00112 */ 00113 typedef struct 00114 { 00115 ble_dfu_evt_type_t ble_dfu_evt_type; /**< Type of the event.*/ 00116 union 00117 { 00118 ble_dfu_pkt_write_t ble_dfu_pkt_write; /**< The DFU packet received. This field is when the @ref ble_dfu_evt_type field is set to @ref BLE_DFU_PACKET_WRITE.*/ 00119 ble_pkt_rcpt_notif_req_t pkt_rcpt_notif_req; /**< Packet receipt notification request. This field is when the @ref ble_dfu_evt_type field is set to @ref BLE_DFU_PKT_RCPT_NOTIF_ENABLED.*/ 00120 } evt; 00121 } ble_dfu_evt_t; 00122 00123 // Forward declaration of the ble_dfu_t type. 00124 typedef struct ble_dfu_s ble_dfu_t; 00125 00126 /**@brief DFU Service event handler type. */ 00127 typedef void (*ble_dfu_evt_handler_t) (ble_dfu_t * p_dfu, ble_dfu_evt_t * p_evt); 00128 00129 /**@brief DFU service structure. 00130 * 00131 * @details This structure contains status information related to the service. 00132 */ 00133 typedef struct ble_dfu_s 00134 { 00135 uint16_t conn_handle; /**< Handle of the current connection (as provided by the S110 SoftDevice). This will be BLE_CONN_HANDLE_INVALID when not in a connection. */ 00136 uint16_t revision; /**< Handle of DFU Service (as provided by the S110 SoftDevice). */ 00137 uint16_t service_handle; /**< Handle of DFU Service (as provided by the S110 SoftDevice). */ 00138 uint8_t uuid_type; /**< UUID type assigned for DFU Service by the S110 SoftDevice. */ 00139 ble_gatts_char_handles_t dfu_pkt_handles; /**< Handles related to the DFU Packet characteristic. */ 00140 ble_gatts_char_handles_t dfu_ctrl_pt_handles; /**< Handles related to the DFU Control Point characteristic. */ 00141 ble_gatts_char_handles_t dfu_status_rep_handles; /**< Handles related to the DFU Status Report characteristic. */ 00142 ble_gatts_char_handles_t dfu_rev_handles; /**< Handles related to the DFU Revision characteristic. */ 00143 ble_dfu_evt_handler_t evt_handler; /**< The event handler to be called when an event is to be sent to the application.*/ 00144 ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */ 00145 } ble_dfu_t; 00146 00147 /**@brief DFU service initialization structure. 00148 * 00149 * @details This structure contains the initialization information for the DFU Service. The 00150 * application needs to fill this structure and pass it to the DFU Service using the 00151 * @ref ble_dfu_init function. 00152 */ 00153 typedef struct 00154 { 00155 uint16_t revision; /**< Revision number to be exposed by the DFU service. */ 00156 ble_dfu_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Device Firmware Update Service. */ 00157 ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */ 00158 } ble_dfu_init_t; 00159 00160 /**@brief Function for handling a BLE event. 00161 * 00162 * @details The DFU service expects the application to call this function each time an event 00163 * is received from the S110 SoftDevice. This function processes the event, if it is 00164 * relevant for the DFU service and calls the DFU event handler of the application if 00165 * necessary. 00166 * 00167 * @param[in] p_dfu Pointer to the DFU service structure. 00168 * @param[in] p_ble_evt Pointer to the event received from S110 SoftDevice. 00169 */ 00170 void ble_dfu_on_ble_evt(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt); 00171 00172 /**@brief Function for initializing the DFU service. 00173 * 00174 * @param[out] p_dfu Device Firmware Update service structure. This structure will have to be 00175 * supplied by the application. It will be initialized by this function, 00176 * and will later be used to identify the service instance. 00177 * @param[in] p_dfu_init Information needed to initialize the service. 00178 * 00179 * @return NRF_SUCCESS if the DFU service and its characteristics were successfully added to the 00180 * S110 SoftDevice. Otherwise an error code. 00181 * This function returns NRF_ERROR_NULL if the value of evt_handler in p_dfu_init 00182 * structure provided is NULL or if the pointers supplied as input are NULL. 00183 */ 00184 uint32_t ble_dfu_init(ble_dfu_t * p_dfu, ble_dfu_init_t * p_dfu_init); 00185 00186 /**@brief Function for sending response to a control point command. 00187 * 00188 * @details This function will encode a DFU Control Point response using the given input 00189 * parameters and will send a notification of the same to the peer. 00190 * 00191 * @param[in] p_dfu Pointer to the DFU service structure. 00192 * @param[in] dfu_proc Procedure for which this response is to be sent. 00193 * @param[in] resp_val Response value. 00194 * 00195 * @return NRF_SUCCESS if the DFU Service has successfully requested the S110 SoftDevice to 00196 * send the notification. Otherwise an error code. 00197 * This function returns NRF_ERROR_INVALID_STATE if the device is not connected to a 00198 * peer or if the DFU service is not initialized or if the notification of the DFU 00199 * Status Report characteristic was not enabled by the peer. It returns NRF_ERROR_NULL 00200 * if the pointer p_dfu is NULL. 00201 */ 00202 uint32_t ble_dfu_response_send(ble_dfu_t * p_dfu, 00203 ble_dfu_procedure_t dfu_proc, 00204 ble_dfu_resp_val_t resp_val); 00205 00206 /**@brief Function for notifying the peer about the number of bytes of firmware data received. 00207 * 00208 * @param[in] p_dfu Pointer to the DFU service structure. 00209 * @param[in] num_of_firmware_bytes_rcvd Number of bytes. 00210 * 00211 * @return NRF_SUCCESS if the DFU Service has successfully requested the S110 SoftDevice to send 00212 * the notification. Otherwise an error code. 00213 * This function returns NRF_ERROR_INVALID_STATE if the device is not connected to a 00214 * peer or if the DFU service is not initialized or if the notification of the DFU 00215 * Status Report characteristic was not enabled by the peer. It returns NRF_ERROR_NULL 00216 * if the pointer p_dfu is NULL. 00217 */ 00218 uint32_t ble_dfu_bytes_rcvd_report(ble_dfu_t * p_dfu, uint32_t num_of_firmware_bytes_rcvd); 00219 00220 /**@brief Function for sending Packet Receipt Notification to the peer. 00221 * 00222 * This function will encode the number of bytes received as input parameter into a 00223 * notification of the control point characteristic and send it to the peer. 00224 * 00225 * @param[in] p_dfu Pointer to the DFU service structure. 00226 * @param[in] num_of_firmware_bytes_rcvd Number of bytes of firmware image received. 00227 * 00228 * @return NRF_SUCCESS if the DFU Service has successfully requested the S110 SoftDevice to send 00229 * the notification. Otherwise an error code. 00230 * This function returns NRF_ERROR_INVALID_STATE if the device is not connected to a 00231 * peer or if the DFU service is not initialized or if the notification of the DFU 00232 * Status Report characteristic was not enabled by the peer. It returns NRF_ERROR_NULL 00233 * if the pointer p_dfu is NULL. 00234 */ 00235 uint32_t ble_dfu_pkts_rcpt_notify(ble_dfu_t * p_dfu, uint32_t num_of_firmware_bytes_rcvd); 00236 00237 #endif // BLE_DFU_H__ 00238 00239 /** @} */
Generated on Tue Jul 12 2022 16:21:02 by
