Nordic stack and drivers for the mbed BLE API

Fork of nRF51822 by Nordic Semiconductor

Committer:
Vincent Coubard
Date:
Wed Sep 14 14:39:43 2016 +0100
Revision:
640:c90ae1400bf2
Sync with bdab10dc0f90748b6989c8b577771bb403ca6bd8 from ARMmbed/mbed-os.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vincent Coubard 640:c90ae1400bf2 1 /*
Vincent Coubard 640:c90ae1400bf2 2 * Copyright (c) Nordic Semiconductor ASA
Vincent Coubard 640:c90ae1400bf2 3 * All rights reserved.
Vincent Coubard 640:c90ae1400bf2 4 *
Vincent Coubard 640:c90ae1400bf2 5 * Redistribution and use in source and binary forms, with or without modification,
Vincent Coubard 640:c90ae1400bf2 6 * are permitted provided that the following conditions are met:
Vincent Coubard 640:c90ae1400bf2 7 *
Vincent Coubard 640:c90ae1400bf2 8 * 1. Redistributions of source code must retain the above copyright notice, this
Vincent Coubard 640:c90ae1400bf2 9 * list of conditions and the following disclaimer.
Vincent Coubard 640:c90ae1400bf2 10 *
Vincent Coubard 640:c90ae1400bf2 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this
Vincent Coubard 640:c90ae1400bf2 12 * list of conditions and the following disclaimer in the documentation and/or
Vincent Coubard 640:c90ae1400bf2 13 * other materials provided with the distribution.
Vincent Coubard 640:c90ae1400bf2 14 *
Vincent Coubard 640:c90ae1400bf2 15 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other
Vincent Coubard 640:c90ae1400bf2 16 * contributors to this software may be used to endorse or promote products
Vincent Coubard 640:c90ae1400bf2 17 * derived from this software without specific prior written permission.
Vincent Coubard 640:c90ae1400bf2 18 *
Vincent Coubard 640:c90ae1400bf2 19 *
Vincent Coubard 640:c90ae1400bf2 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
Vincent Coubard 640:c90ae1400bf2 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Vincent Coubard 640:c90ae1400bf2 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Vincent Coubard 640:c90ae1400bf2 23 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
Vincent Coubard 640:c90ae1400bf2 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Vincent Coubard 640:c90ae1400bf2 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Vincent Coubard 640:c90ae1400bf2 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
Vincent Coubard 640:c90ae1400bf2 27 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Vincent Coubard 640:c90ae1400bf2 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Vincent Coubard 640:c90ae1400bf2 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Vincent Coubard 640:c90ae1400bf2 30 *
Vincent Coubard 640:c90ae1400bf2 31 */
Vincent Coubard 640:c90ae1400bf2 32
Vincent Coubard 640:c90ae1400bf2 33 /** @file
Vincent Coubard 640:c90ae1400bf2 34 *
Vincent Coubard 640:c90ae1400bf2 35 * @defgroup nrf_dfu_ble_svc DFU BLE SVC
Vincent Coubard 640:c90ae1400bf2 36 * @{
Vincent Coubard 640:c90ae1400bf2 37 *
Vincent Coubard 640:c90ae1400bf2 38 * @brief DFU BLE SVC in bootloader. The DFU BLE SuperVisor Calls allow an application to execute
Vincent Coubard 640:c90ae1400bf2 39 * functions in the installed bootloader.
Vincent Coubard 640:c90ae1400bf2 40 *
Vincent Coubard 640:c90ae1400bf2 41 * @details This module implements handling of SuperVisor Calls in the bootloader.
Vincent Coubard 640:c90ae1400bf2 42 * SuperVisor Calls allow for an application to execute calls into the bootloader.
Vincent Coubard 640:c90ae1400bf2 43 * Currently, it is possible to exchange bonding information (like keys) from the
Vincent Coubard 640:c90ae1400bf2 44 * application to a bootloader supporting DFU OTA using BLE, so the update process can be
Vincent Coubard 640:c90ae1400bf2 45 * done through an already existing bond.
Vincent Coubard 640:c90ae1400bf2 46 *
Vincent Coubard 640:c90ae1400bf2 47 * @note The application must make sure that all SuperVisor Calls (SVC) are forwarded to the
Vincent Coubard 640:c90ae1400bf2 48 * bootloader to ensure correct behavior. Forwarding of SVCs to the bootloader is
Vincent Coubard 640:c90ae1400bf2 49 * done using the SoftDevice SVC @ref sd_softdevice_vector_table_base_set with the value
Vincent Coubard 640:c90ae1400bf2 50 * present in @c NRF_UICR->BOOTLOADERADDR.
Vincent Coubard 640:c90ae1400bf2 51 */
Vincent Coubard 640:c90ae1400bf2 52
Vincent Coubard 640:c90ae1400bf2 53 #ifndef DFU_BLE_SVC_H__
Vincent Coubard 640:c90ae1400bf2 54 #define DFU_BLE_SVC_H__
Vincent Coubard 640:c90ae1400bf2 55
Vincent Coubard 640:c90ae1400bf2 56 #include "nrf_svc.h"
Vincent Coubard 640:c90ae1400bf2 57 #include <stdint.h>
Vincent Coubard 640:c90ae1400bf2 58 #include "ble_gap.h"
Vincent Coubard 640:c90ae1400bf2 59 #include "nrf.h"
Vincent Coubard 640:c90ae1400bf2 60 #include "nrf_soc.h"
Vincent Coubard 640:c90ae1400bf2 61 #include "nrf_error_sdm.h"
Vincent Coubard 640:c90ae1400bf2 62
Vincent Coubard 640:c90ae1400bf2 63 #define BOOTLOADER_SVC_BASE 0x0 /**< The number of the lowest SVC number reserved for the bootloader. */
Vincent Coubard 640:c90ae1400bf2 64 #define SYSTEM_SERVICE_ATT_SIZE 8 /**< Size of the system service attribute length including CRC-16 at the end. */
Vincent Coubard 640:c90ae1400bf2 65
Vincent Coubard 640:c90ae1400bf2 66 /**@brief The SVC numbers used by the SVC functions in the SoC library. */
Vincent Coubard 640:c90ae1400bf2 67 enum BOOTLOADER_SVCS
Vincent Coubard 640:c90ae1400bf2 68 {
Vincent Coubard 640:c90ae1400bf2 69 DFU_BLE_SVC_PEER_DATA_SET = BOOTLOADER_SVC_BASE, /**< SVC number for the setting of peer data call. */
Vincent Coubard 640:c90ae1400bf2 70 BOOTLOADER_SVC_LAST
Vincent Coubard 640:c90ae1400bf2 71 };
Vincent Coubard 640:c90ae1400bf2 72
Vincent Coubard 640:c90ae1400bf2 73 /**@brief DFU Peer data structure.
Vincent Coubard 640:c90ae1400bf2 74 *
Vincent Coubard 640:c90ae1400bf2 75 * @details This structure contains peer data needed for connection to a bonded device during DFU.
Vincent Coubard 640:c90ae1400bf2 76 * The peer data must be provided by the application to the bootloader during buttonless
Vincent Coubard 640:c90ae1400bf2 77 * update. See @ref dfu_ble_svc_peer_data_set. It contains bond information about the
Vincent Coubard 640:c90ae1400bf2 78 * desired DFU peer.
Vincent Coubard 640:c90ae1400bf2 79 */
Vincent Coubard 640:c90ae1400bf2 80 typedef struct
Vincent Coubard 640:c90ae1400bf2 81 {
Vincent Coubard 640:c90ae1400bf2 82 ble_gap_addr_t addr; /**< BLE GAP address of the device that initiated the DFU process. */
Vincent Coubard 640:c90ae1400bf2 83 ble_gap_irk_t irk; /**< IRK of the device that initiated the DFU process if this device uses Private Resolvable Addresses. */
Vincent Coubard 640:c90ae1400bf2 84 ble_gap_enc_key_t enc_key; /**< Encryption key structure containing encrypted diversifier and LTK for re-establishing the bond. */
Vincent Coubard 640:c90ae1400bf2 85 uint8_t sys_serv_attr[SYSTEM_SERVICE_ATT_SIZE]; /**< System service attributes for restoring of Service Changed Indication setting in DFU mode. */
Vincent Coubard 640:c90ae1400bf2 86 } dfu_ble_peer_data_t;
Vincent Coubard 640:c90ae1400bf2 87
Vincent Coubard 640:c90ae1400bf2 88 /**@brief SVC Function for setting peer data containing address, IRK, and LTK to establish bonded
Vincent Coubard 640:c90ae1400bf2 89 * connection in DFU mode.
Vincent Coubard 640:c90ae1400bf2 90 *
Vincent Coubard 640:c90ae1400bf2 91 * @param[in] p_peer_data Pointer to the peer data containing keys for the connection.
Vincent Coubard 640:c90ae1400bf2 92 *
Vincent Coubard 640:c90ae1400bf2 93 * @retval NRF_ERROR_NULL If a NULL pointer was provided as argument.
Vincent Coubard 640:c90ae1400bf2 94 * @retval NRF_SUCCESS If the function completed successfully.
Vincent Coubard 640:c90ae1400bf2 95 */
Vincent Coubard 640:c90ae1400bf2 96 SVCALL(DFU_BLE_SVC_PEER_DATA_SET, uint32_t, dfu_ble_svc_peer_data_set(dfu_ble_peer_data_t * p_peer_data));
Vincent Coubard 640:c90ae1400bf2 97
Vincent Coubard 640:c90ae1400bf2 98 #endif // DFU_BLE_SVC_H__
Vincent Coubard 640:c90ae1400bf2 99
Vincent Coubard 640:c90ae1400bf2 100 /** @} */