Pull the files we need directly out of the nordic-sdk

without modifications preserving the folder structure in
the sdk. nRF51_SDK_8.1.0_b6ed55f.zip from:
https://developer.nordicsemi.com/nRF51_SDK/nRF51_SDK_v8.x.x/
This commit is contained in:
Liyou Zhou 2015-11-16 16:31:32 +00:00
parent f006fc3304
commit d1170b61be
105 changed files with 29420 additions and 31310 deletions

View file

@ -22,24 +22,27 @@
}
},
"extraIncludes": [
"source/nordic_sdk/components",
"source/nordic_sdk/components/libraries/util",
"source/nordic_sdk/components/libraries/hci",
"source/nordic_sdk/components/libraries/bootloader_dfu",
"source/nordic_sdk/components/libraries/bootloader_dfu/hci_transport",
"source/nordic_sdk/components/libraries/bootloader_dfu/experimental",
"source/nordic_sdk/components/libraries/scheduler",
"source/nordic_sdk/components/libraries/crc16",
"source/nordic_sdk/components/softdevice/s130/include",
"source/nordic_sdk/components/softdevice/common/softdevice_handler",
"source/nordic_sdk/components/drivers_nrf/hal",
"source/nordic_sdk/components/drivers_nrf/ble_flash",
"source/nordic_sdk/components/drivers_nrf/pstorage",
"source/nordic_sdk/components/drivers_nrf/pstorage/config",
"source/nordic_sdk/components/ble/ble_radio_notification",
"source/nordic_sdk/components/ble/ble_services/ble_dfu",
"source/nordic_sdk/components/ble/common",
"source/nordic_sdk/components/ble/device_manager",
"source/nordic_sdk/components/ble/device_manager/config"
"source/nordic_sdk/components/ble/device_manager/config",
"source/nordic_sdk/components/device",
"source/nordic_sdk/components/drivers_nrf/ble_flash",
"source/nordic_sdk/components/drivers_nrf/hal",
"source/nordic_sdk/components/drivers_nrf/pstorage",
"source/nordic_sdk/components/drivers_nrf/pstorage/config",
"source/nordic_sdk/components/libraries/bootloader_dfu",
"source/nordic_sdk/components/libraries/bootloader_dfu/hci_transport",
"source/nordic_sdk/components/libraries/crc16",
"source/nordic_sdk/components/libraries/hci",
"source/nordic_sdk/components/libraries/scheduler",
"source/nordic_sdk/components/libraries/timer",
"source/nordic_sdk/components/libraries/trace",
"source/nordic_sdk/components/libraries/util",
"source/nordic_sdk/components/softdevice/common/softdevice_handler",
"source/nordic_sdk/components/softdevice/s130/headers",
"source/nordic_sdk/components/toolchain",
"source/nordic_sdk/components/toolchain/gcc"
]
}

View file

@ -1,80 +1,59 @@
/*
* Copyright (c) Nordic Semiconductor ASA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ble_radio_notification.h"
#include <stdlib.h>
static bool m_radio_active = false; /**< Current radio state. */
static ble_radio_notification_evt_handler_t m_evt_handler = NULL; /**< Application event handler for handling Radio Notification events. */
void SWI1_IRQHandler(void)
{
m_radio_active = !m_radio_active;
if (m_evt_handler != NULL)
{
m_evt_handler(m_radio_active);
}
}
uint32_t ble_radio_notification_init(nrf_app_irq_priority_t irq_priority,
nrf_radio_notification_distance_t distance,
ble_radio_notification_evt_handler_t evt_handler)
{
uint32_t err_code;
m_evt_handler = evt_handler;
// Initialize Radio Notification software interrupt
err_code = sd_nvic_ClearPendingIRQ(SWI1_IRQn);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
err_code = sd_nvic_SetPriority(SWI1_IRQn, irq_priority);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
err_code = sd_nvic_EnableIRQ(SWI1_IRQn);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
// Configure the event
return sd_radio_notification_cfg_set(NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH, distance);
}
/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is property of Nordic Semiconductor ASA.
* Terms and conditions of usage are described in detail in NORDIC
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
*
* Licensees are granted free, non-transferable use of the information. NO
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* the file.
*/
#include "ble_radio_notification.h"
#include <stdlib.h>
static bool m_radio_active = false; /**< Current radio state. */
static ble_radio_notification_evt_handler_t m_evt_handler = NULL; /**< Application event handler for handling Radio Notification events. */
void SWI1_IRQHandler(void)
{
m_radio_active = !m_radio_active;
if (m_evt_handler != NULL)
{
m_evt_handler(m_radio_active);
}
}
uint32_t ble_radio_notification_init(nrf_app_irq_priority_t irq_priority,
nrf_radio_notification_distance_t distance,
ble_radio_notification_evt_handler_t evt_handler)
{
uint32_t err_code;
m_evt_handler = evt_handler;
// Initialize Radio Notification software interrupt
err_code = sd_nvic_ClearPendingIRQ(SWI1_IRQn);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
err_code = sd_nvic_SetPriority(SWI1_IRQn, irq_priority);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
err_code = sd_nvic_EnableIRQ(SWI1_IRQn);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
// Configure the event
return sd_radio_notification_cfg_set(NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH, distance);
}

View file

@ -1,74 +1,45 @@
/*
* Copyright (c) Nordic Semiconductor ASA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/** @file
*
* @defgroup ble_radio_notification Radio Notification Event Handler
* @{
* @ingroup ble_sdk_lib
* @brief Module for propagating Radio Notification events to the application.
*/
#ifndef BLE_RADIO_NOTIFICATION_H__
#define BLE_RADIO_NOTIFICATION_H__
#include <stdint.h>
#include <stdbool.h>
#include "nrf_soc.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Application radio notification event handler type. */
typedef void (*ble_radio_notification_evt_handler_t) (bool radio_active);
/**@brief Function for initializing the Radio Notification module.
*
* @param[in] irq_priority Interrupt priority for the Radio Notification interrupt handler.
* @param[in] distance The time from an Active event until the radio is activated.
* @param[in] evt_handler Handler to be executed when a radio notification event has been
* received.
*
* @return NRF_SUCCESS on successful initialization, otherwise an error code.
*/
uint32_t ble_radio_notification_init(nrf_app_irq_priority_t irq_priority,
nrf_radio_notification_distance_t distance,
ble_radio_notification_evt_handler_t evt_handler);
#ifdef __cplusplus
}
#endif
#endif // BLE_RADIO_NOTIFICATION_H__
/** @} */
/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is property of Nordic Semiconductor ASA.
* Terms and conditions of usage are described in detail in NORDIC
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
*
* Licensees are granted free, non-transferable use of the information. NO
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* the file.
*/
/** @file
*
* @defgroup ble_radio_notification Radio Notification Event Handler
* @{
* @ingroup ble_sdk_lib
* @brief Module for propagating Radio Notification events to the application.
*/
#ifndef BLE_RADIO_NOTIFICATION_H__
#define BLE_RADIO_NOTIFICATION_H__
#include <stdint.h>
#include <stdbool.h>
#include "nrf_soc.h"
/**@brief Application radio notification event handler type. */
typedef void (*ble_radio_notification_evt_handler_t) (bool radio_active);
/**@brief Function for initializing the Radio Notification module.
*
* @param[in] irq_priority Interrupt priority for the Radio Notification interrupt handler.
* @param[in] distance The time from an Active event until the radio is activated.
* @param[in] evt_handler Handler to be executed when a radio notification event has been
* received.
*
* @return NRF_SUCCESS on successful initialization, otherwise an error code.
*/
uint32_t ble_radio_notification_init(nrf_app_irq_priority_t irq_priority,
nrf_radio_notification_distance_t distance,
ble_radio_notification_evt_handler_t evt_handler);
#endif // BLE_RADIO_NOTIFICATION_H__
/** @} */

File diff suppressed because it is too large Load diff

View file

@ -1,259 +1,239 @@
/*
* Copyright (c) Nordic Semiconductor ASA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/**@file
*
* @defgroup ble_sdk_srv_dfu Device Firmware Update Service
* @{
* @ingroup ble_sdk_srv
* @brief Device Firmware Update Service
*
* @details The Device Firmware Update (DFU) service is a GATT based service that can be used for
* performing firmware updates over BLE. Note that this implementation uses vendor
* specific UUIDs for service and characteristics and is intended to demonstrate the
* firmware updates over BLE. Refer @ref ota_spec_sec and @ref
* ota_profile_section for more information on the service and profile respectively.
*/
#ifndef BLE_DFU_H__
#define BLE_DFU_H__
#include <stdint.h>
#include "ble_gatts.h"
#include "ble_gap.h"
#include "ble.h"
#include "ble_srv_common.h"
#define BLE_DFU_SERVICE_UUID 0x1530 /**< The UUID of the DFU Service. */
#define BLE_DFU_PKT_CHAR_UUID 0x1532 /**< The UUID of the DFU Packet Characteristic. */
#define BLE_DFU_CTRL_PT_UUID 0x1531 /**< The UUID of the DFU Control Point. */
#define BLE_DFU_STATUS_REP_UUID 0x1533 /**< The UUID of the DFU Status Report Characteristic. */
#define BLE_DFU_REV_CHAR_UUID 0x1534 /**< The UUID of the DFU Revision Characteristic. */
/**@brief DFU Event type.
*
* @details This enumeration contains the types of events that will be received from the DFU Service.
*/
typedef enum
{
BLE_DFU_START, /**< The event indicating that the peer wants the application to prepare for a new firmware update. */
BLE_DFU_RECEIVE_INIT_DATA, /**< The event indicating that the peer wants the application to prepare to receive init parameters. */
BLE_DFU_RECEIVE_APP_DATA, /**< The event indicating that the peer wants the application to prepare to receive the new firmware image. */
BLE_DFU_VALIDATE, /**< The event indicating that the peer wants the application to validate the newly received firmware image. */
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 */
BLE_DFU_SYS_RESET, /**< The event indicating that the peer wants the application to undergo a reset and start the currently valid application image.*/
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.*/
BLE_DFU_PKT_RCPT_NOTIF_DISABLED, /**< The event indicating that the peer has disabled the packet receipt notifications.*/
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.*/
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. */
} ble_dfu_evt_type_t;
/**@brief DFU Procedure type.
*
* @details This enumeration contains the types of DFU procedures.
*/
typedef enum
{
BLE_DFU_START_PROCEDURE = 1, /**< DFU Start procedure.*/
BLE_DFU_INIT_PROCEDURE = 2, /**< DFU Initialization procedure.*/
BLE_DFU_RECEIVE_APP_PROCEDURE = 3, /**< Firmware receiving procedure.*/
BLE_DFU_VALIDATE_PROCEDURE = 4, /**< Firmware image validation procedure .*/
BLE_DFU_PKT_RCPT_REQ_PROCEDURE = 8 /**< Packet receipt notification request procedure. */
} ble_dfu_procedure_t;
/**@brief DFU Response value type.
*/
typedef enum
{
BLE_DFU_RESP_VAL_SUCCESS = 1, /**< Success.*/
BLE_DFU_RESP_VAL_INVALID_STATE, /**< Invalid state.*/
BLE_DFU_RESP_VAL_NOT_SUPPORTED, /**< Operation not supported.*/
BLE_DFU_RESP_VAL_DATA_SIZE, /**< Data size exceeds limit.*/
BLE_DFU_RESP_VAL_CRC_ERROR, /**< CRC Error.*/
BLE_DFU_RESP_VAL_OPER_FAILED /**< Operation failed.*/
} ble_dfu_resp_val_t;
/**@brief DFU Packet structure.
*
* @details This structure contains the value of the DFU Packet characteristic as written by the
* peer and the length of the value written. It will be filled by the DFU Service when the
* peer writes to the DFU Packet characteristic.
*/
typedef struct
{
uint8_t len; /**< Length of the packet received. */
uint8_t * p_data; /**< Pointer to the received packet. This will point to a word aligned memory location.*/
} ble_dfu_pkt_write_t;
/**@brief Packet receipt notification request structure.
*
* @details This structure contains the contents of the packet receipt notification request
* sent by the DFU Controller.
*/
typedef struct
{
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. */
} ble_pkt_rcpt_notif_req_t;
/**@brief DFU Event structure.
*
* @details This structure contains the event generated by the DFU Service based on the data
* received from the peer.
*/
typedef struct
{
ble_dfu_evt_type_t ble_dfu_evt_type; /**< Type of the event.*/
union
{
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.*/
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.*/
} evt;
} ble_dfu_evt_t;
// Forward declaration of the ble_dfu_t type.
typedef struct ble_dfu_s ble_dfu_t;
/**@brief DFU Service event handler type. */
typedef void (*ble_dfu_evt_handler_t) (ble_dfu_t * p_dfu, ble_dfu_evt_t * p_evt);
/**@brief DFU service structure.
*
* @details This structure contains status information related to the service.
*/
struct ble_dfu_s
{
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. */
uint16_t revision; /**< Handle of DFU Service (as provided by the S110 SoftDevice). */
uint16_t service_handle; /**< Handle of DFU Service (as provided by the S110 SoftDevice). */
uint8_t uuid_type; /**< UUID type assigned for DFU Service by the S110 SoftDevice. */
ble_gatts_char_handles_t dfu_pkt_handles; /**< Handles related to the DFU Packet characteristic. */
ble_gatts_char_handles_t dfu_ctrl_pt_handles; /**< Handles related to the DFU Control Point characteristic. */
ble_gatts_char_handles_t dfu_status_rep_handles; /**< Handles related to the DFU Status Report characteristic. */
ble_gatts_char_handles_t dfu_rev_handles; /**< Handles related to the DFU Revision characteristic. */
ble_dfu_evt_handler_t evt_handler; /**< The event handler to be called when an event is to be sent to the application.*/
ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */
};
/**@brief DFU service initialization structure.
*
* @details This structure contains the initialization information for the DFU Service. The
* application needs to fill this structure and pass it to the DFU Service using the
* @ref ble_dfu_init function.
*/
typedef struct
{
uint16_t revision; /**< Revision number to be exposed by the DFU service. */
ble_dfu_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Device Firmware Update Service. */
ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */
} ble_dfu_init_t;
/**@brief Function for handling a BLE event.
*
* @details The DFU service expects the application to call this function each time an event
* is received from the S110 SoftDevice. This function processes the event, if it is
* relevant for the DFU service and calls the DFU event handler of the application if
* necessary.
*
* @param[in] p_dfu Pointer to the DFU service structure.
* @param[in] p_ble_evt Pointer to the event received from S110 SoftDevice.
*/
void ble_dfu_on_ble_evt(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt);
/**@brief Function for initializing the DFU service.
*
* @param[out] p_dfu Device Firmware Update service structure. This structure will have to be
* supplied by the application. It will be initialized by this function,
* and will later be used to identify the service instance.
* @param[in] p_dfu_init Information needed to initialize the service.
*
* @return NRF_SUCCESS if the DFU service and its characteristics were successfully added to the
* S110 SoftDevice. Otherwise an error code.
* This function returns NRF_ERROR_NULL if the value of evt_handler in p_dfu_init
* structure provided is NULL or if the pointers supplied as input are NULL.
*/
uint32_t ble_dfu_init(ble_dfu_t * p_dfu, ble_dfu_init_t * p_dfu_init);
/**@brief Function for sending response to a control point command.
*
* @details This function will encode a DFU Control Point response using the given input
* parameters and will send a notification of the same to the peer.
*
* @param[in] p_dfu Pointer to the DFU service structure.
* @param[in] dfu_proc Procedure for which this response is to be sent.
* @param[in] resp_val Response value.
*
* @return NRF_SUCCESS if the DFU Service has successfully requested the S110 SoftDevice to
* send the notification. Otherwise an error code.
* This function returns NRF_ERROR_INVALID_STATE if the device is not connected to a
* peer or if the DFU service is not initialized or if the notification of the DFU
* Status Report characteristic was not enabled by the peer. It returns NRF_ERROR_NULL
* if the pointer p_dfu is NULL.
*/
uint32_t ble_dfu_response_send(ble_dfu_t * p_dfu,
ble_dfu_procedure_t dfu_proc,
ble_dfu_resp_val_t resp_val);
/**@brief Function for notifying the peer about the number of bytes of firmware data received.
*
* @param[in] p_dfu Pointer to the DFU service structure.
* @param[in] num_of_firmware_bytes_rcvd Number of bytes.
*
* @return NRF_SUCCESS if the DFU Service has successfully requested the S110 SoftDevice to send
* the notification. Otherwise an error code.
* This function returns NRF_ERROR_INVALID_STATE if the device is not connected to a
* peer or if the DFU service is not initialized or if the notification of the DFU
* Status Report characteristic was not enabled by the peer. It returns NRF_ERROR_NULL
* if the pointer p_dfu is NULL.
*/
uint32_t ble_dfu_bytes_rcvd_report(ble_dfu_t * p_dfu, uint32_t num_of_firmware_bytes_rcvd);
/**@brief Function for sending Packet Receipt Notification to the peer.
*
* This function will encode the number of bytes received as input parameter into a
* notification of the control point characteristic and send it to the peer.
*
* @param[in] p_dfu Pointer to the DFU service structure.
* @param[in] num_of_firmware_bytes_rcvd Number of bytes of firmware image received.
*
* @return NRF_SUCCESS if the DFU Service has successfully requested the S110 SoftDevice to send
* the notification. Otherwise an error code.
* This function returns NRF_ERROR_INVALID_STATE if the device is not connected to a
* peer or if the DFU service is not initialized or if the notification of the DFU
* Status Report characteristic was not enabled by the peer. It returns NRF_ERROR_NULL
* if the pointer p_dfu is NULL.
*/
uint32_t ble_dfu_pkts_rcpt_notify(ble_dfu_t * p_dfu, uint32_t num_of_firmware_bytes_rcvd);
#endif // BLE_DFU_H__
/** @} */
/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is property of Nordic Semiconductor ASA.
* Terms and conditions of usage are described in detail in NORDIC
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
*
* Licensees are granted free, non-transferable use of the information. NO
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* the file.
*
*/
/**@file
*
* @defgroup ble_sdk_srv_dfu Device Firmware Update Service
* @{
* @ingroup ble_sdk_srv
* @brief Device Firmware Update Service
*
* @details The Device Firmware Update (DFU) service is a GATT based service that can be used for
* performing firmware updates over BLE. Note that this implementation uses vendor
* specific UUIDs for service and characteristics and is intended to demonstrate the
* firmware updates over BLE. Refer @ref bledfu_transport_bleservice and @ref
* bledfu_transport_bleprofile for more information on the service and profile respectively.
*/
#ifndef BLE_DFU_H__
#define BLE_DFU_H__
#include <stdint.h>
#include "ble_gatts.h"
#include "ble_gap.h"
#include "ble.h"
#include "ble_srv_common.h"
#define BLE_DFU_SERVICE_UUID 0x1530 /**< The UUID of the DFU Service. */
#define BLE_DFU_PKT_CHAR_UUID 0x1532 /**< The UUID of the DFU Packet Characteristic. */
#define BLE_DFU_CTRL_PT_UUID 0x1531 /**< The UUID of the DFU Control Point. */
#define BLE_DFU_STATUS_REP_UUID 0x1533 /**< The UUID of the DFU Status Report Characteristic. */
#define BLE_DFU_REV_CHAR_UUID 0x1534 /**< The UUID of the DFU Revision Characteristic. */
/**@brief DFU Event type.
*
* @details This enumeration contains the types of events that will be received from the DFU Service.
*/
typedef enum
{
BLE_DFU_START, /**< The event indicating that the peer wants the application to prepare for a new firmware update. */
BLE_DFU_RECEIVE_INIT_DATA, /**< The event indicating that the peer wants the application to prepare to receive init parameters. */
BLE_DFU_RECEIVE_APP_DATA, /**< The event indicating that the peer wants the application to prepare to receive the new firmware image. */
BLE_DFU_VALIDATE, /**< The event indicating that the peer wants the application to validate the newly received firmware image. */
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 */
BLE_DFU_SYS_RESET, /**< The event indicating that the peer wants the application to undergo a reset and start the currently valid application image.*/
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.*/
BLE_DFU_PKT_RCPT_NOTIF_DISABLED, /**< The event indicating that the peer has disabled the packet receipt notifications.*/
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.*/
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. */
} ble_dfu_evt_type_t;
/**@brief DFU Procedure type.
*
* @details This enumeration contains the types of DFU procedures.
*/
typedef enum
{
BLE_DFU_START_PROCEDURE = 1, /**< DFU Start procedure.*/
BLE_DFU_INIT_PROCEDURE = 2, /**< DFU Initialization procedure.*/
BLE_DFU_RECEIVE_APP_PROCEDURE = 3, /**< Firmware receiving procedure.*/
BLE_DFU_VALIDATE_PROCEDURE = 4, /**< Firmware image validation procedure .*/
BLE_DFU_PKT_RCPT_REQ_PROCEDURE = 8 /**< Packet receipt notification request procedure. */
} ble_dfu_procedure_t;
/**@brief DFU Response value type.
*/
typedef enum
{
BLE_DFU_RESP_VAL_SUCCESS = 1, /**< Success.*/
BLE_DFU_RESP_VAL_INVALID_STATE, /**< Invalid state.*/
BLE_DFU_RESP_VAL_NOT_SUPPORTED, /**< Operation not supported.*/
BLE_DFU_RESP_VAL_DATA_SIZE, /**< Data size exceeds limit.*/
BLE_DFU_RESP_VAL_CRC_ERROR, /**< CRC Error.*/
BLE_DFU_RESP_VAL_OPER_FAILED /**< Operation failed.*/
} ble_dfu_resp_val_t;
/**@brief DFU Packet structure.
*
* @details This structure contains the value of the DFU Packet characteristic as written by the
* peer and the length of the value written. It will be filled by the DFU Service when the
* peer writes to the DFU Packet characteristic.
*/
typedef struct
{
uint8_t len; /**< Length of the packet received. */
uint8_t * p_data; /**< Pointer to the received packet. This will point to a word aligned memory location.*/
} ble_dfu_pkt_write_t;
/**@brief Packet receipt notification request structure.
*
* @details This structure contains the contents of the packet receipt notification request
* sent by the DFU Controller.
*/
typedef struct
{
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. */
} ble_pkt_rcpt_notif_req_t;
/**@brief DFU Event structure.
*
* @details This structure contains the event generated by the DFU Service based on the data
* received from the peer.
*/
typedef struct
{
ble_dfu_evt_type_t ble_dfu_evt_type; /**< Type of the event.*/
union
{
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.*/
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.*/
} evt;
} ble_dfu_evt_t;
// Forward declaration of the ble_dfu_t type.
typedef struct ble_dfu_s ble_dfu_t;
/**@brief DFU Service event handler type. */
typedef void (*ble_dfu_evt_handler_t) (ble_dfu_t * p_dfu, ble_dfu_evt_t * p_evt);
/**@brief DFU service structure.
*
* @details This structure contains status information related to the service.
*/
struct ble_dfu_s
{
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. */
uint16_t revision; /**< Handle of DFU Service (as provided by the S110 SoftDevice). */
uint16_t service_handle; /**< Handle of DFU Service (as provided by the S110 SoftDevice). */
uint8_t uuid_type; /**< UUID type assigned for DFU Service by the S110 SoftDevice. */
ble_gatts_char_handles_t dfu_pkt_handles; /**< Handles related to the DFU Packet characteristic. */
ble_gatts_char_handles_t dfu_ctrl_pt_handles; /**< Handles related to the DFU Control Point characteristic. */
ble_gatts_char_handles_t dfu_status_rep_handles; /**< Handles related to the DFU Status Report characteristic. */
ble_gatts_char_handles_t dfu_rev_handles; /**< Handles related to the DFU Revision characteristic. */
ble_dfu_evt_handler_t evt_handler; /**< The event handler to be called when an event is to be sent to the application.*/
ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */
};
/**@brief DFU service initialization structure.
*
* @details This structure contains the initialization information for the DFU Service. The
* application needs to fill this structure and pass it to the DFU Service using the
* @ref ble_dfu_init function.
*/
typedef struct
{
uint16_t revision; /**< Revision number to be exposed by the DFU service. */
ble_dfu_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Device Firmware Update Service. */
ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */
} ble_dfu_init_t;
/**@brief Function for handling a BLE event.
*
* @details The DFU service expects the application to call this function each time an event
* is received from the S110 SoftDevice. This function processes the event, if it is
* relevant for the DFU service and calls the DFU event handler of the application if
* necessary.
*
* @param[in] p_dfu Pointer to the DFU service structure.
* @param[in] p_ble_evt Pointer to the event received from S110 SoftDevice.
*/
void ble_dfu_on_ble_evt(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt);
/**@brief Function for initializing the DFU service.
*
* @param[out] p_dfu Device Firmware Update service structure. This structure will have to be
* supplied by the application. It will be initialized by this function,
* and will later be used to identify the service instance.
* @param[in] p_dfu_init Information needed to initialize the service.
*
* @return NRF_SUCCESS if the DFU service and its characteristics were successfully added to the
* S110 SoftDevice. Otherwise an error code.
* This function returns NRF_ERROR_NULL if the value of evt_handler in p_dfu_init
* structure provided is NULL or if the pointers supplied as input are NULL.
*/
uint32_t ble_dfu_init(ble_dfu_t * p_dfu, ble_dfu_init_t * p_dfu_init);
/**@brief Function for sending response to a control point command.
*
* @details This function will encode a DFU Control Point response using the given input
* parameters and will send a notification of the same to the peer.
*
* @param[in] p_dfu Pointer to the DFU service structure.
* @param[in] dfu_proc Procedure for which this response is to be sent.
* @param[in] resp_val Response value.
*
* @return NRF_SUCCESS if the DFU Service has successfully requested the S110 SoftDevice to
* send the notification. Otherwise an error code.
* This function returns NRF_ERROR_INVALID_STATE if the device is not connected to a
* peer or if the DFU service is not initialized or if the notification of the DFU
* Status Report characteristic was not enabled by the peer. It returns NRF_ERROR_NULL
* if the pointer p_dfu is NULL.
*/
uint32_t ble_dfu_response_send(ble_dfu_t * p_dfu,
ble_dfu_procedure_t dfu_proc,
ble_dfu_resp_val_t resp_val);
/**@brief Function for notifying the peer about the number of bytes of firmware data received.
*
* @param[in] p_dfu Pointer to the DFU service structure.
* @param[in] num_of_firmware_bytes_rcvd Number of bytes.
*
* @return NRF_SUCCESS if the DFU Service has successfully requested the S110 SoftDevice to send
* the notification. Otherwise an error code.
* This function returns NRF_ERROR_INVALID_STATE if the device is not connected to a
* peer or if the DFU service is not initialized or if the notification of the DFU
* Status Report characteristic was not enabled by the peer. It returns NRF_ERROR_NULL
* if the pointer p_dfu is NULL.
*/
uint32_t ble_dfu_bytes_rcvd_report(ble_dfu_t * p_dfu, uint32_t num_of_firmware_bytes_rcvd);
/**@brief Function for sending Packet Receipt Notification to the peer.
*
* This function will encode the number of bytes received as input parameter into a
* notification of the control point characteristic and send it to the peer.
*
* @param[in] p_dfu Pointer to the DFU service structure.
* @param[in] num_of_firmware_bytes_rcvd Number of bytes of firmware image received.
*
* @return NRF_SUCCESS if the DFU Service has successfully requested the S110 SoftDevice to send
* the notification. Otherwise an error code.
* This function returns NRF_ERROR_INVALID_STATE if the device is not connected to a
* peer or if the DFU service is not initialized or if the notification of the DFU
* Status Report characteristic was not enabled by the peer. It returns NRF_ERROR_NULL
* if the pointer p_dfu is NULL.
*/
uint32_t ble_dfu_pkts_rcpt_notify(ble_dfu_t * p_dfu, uint32_t num_of_firmware_bytes_rcvd);
#endif // BLE_DFU_H__
/** @} */

File diff suppressed because it is too large Load diff

246
source/nordic_sdk/components/ble/common/ble_advdata.h Executable file → Normal file
View file

@ -1,133 +1,113 @@
/*
* Copyright (c) Nordic Semiconductor ASA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/** @file
*
* @defgroup ble_sdk_lib_advdata Advertising Data Encoder
* @{
* @ingroup ble_sdk_lib
* @brief Function for encoding the advertising data and/or scan response data, and passing them to
* the stack.
*/
#ifndef BLE_ADVDATA_H__
#define BLE_ADVDATA_H__
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "ble.h"
#include "app_util.h"
/**@brief Advertising data name type. This contains the options available for the device name inside
* the advertising data. */
typedef enum
{
BLE_ADVDATA_NO_NAME, /**< Include no device name in advertising data. */
BLE_ADVDATA_SHORT_NAME, /**< Include short device name in advertising data. */
BLE_ADVDATA_FULL_NAME /**< Include full device name in advertising data. */
} ble_advdata_name_type_t;
/**@brief UUID list type. */
typedef struct
{
uint16_t uuid_cnt; /**< Number of UUID entries. */
ble_uuid_t * p_uuids; /**< Pointer to UUID array entries. */
} ble_advdata_uuid_list_t;
/**@brief Connection interval range structure. */
typedef struct
{
uint16_t min_conn_interval; /**< Minimum Connection Interval, in units of 1.25ms, range 6 to 3200 (i.e. 7.5ms to 4s). */
uint16_t max_conn_interval; /**< Maximum Connection Interval, in units of 1.25ms, range 6 to 3200 (i.e. 7.5ms to 4s). Value of 0xFFFF indicates no specific maximum. */
} ble_advdata_conn_int_t;
/**@brief Manufacturer specific data structure. */
typedef struct
{
uint16_t company_identifier; /**< Company Identifier Code. */
uint8_array_t data; /**< Additional manufacturer specific data. */
} ble_advdata_manuf_data_t;
/**@brief Service data structure. */
typedef struct
{
uint16_t service_uuid; /**< Service UUID. */
uint8_array_t data; /**< Additional service data. */
} ble_advdata_service_data_t;
/**@brief Advertising data structure. This contains all options and data needed for encoding and
* setting the advertising data. */
typedef struct
{
ble_advdata_name_type_t name_type; /**< Type of device name. */
uint8_t short_name_len; /**< Length of short device name (if short type is specified). */
bool include_appearance; /**< Determines if Appearance shall be included. */
uint8_t flags; /**< Advertising data Flags field. */
int8_t * p_tx_power_level; /**< TX Power Level field. */
ble_advdata_uuid_list_t uuids_more_available; /**< List of UUIDs in the 'More Available' list. */
ble_advdata_uuid_list_t uuids_complete; /**< List of UUIDs in the 'Complete' list. */
ble_advdata_uuid_list_t uuids_solicited; /**< List of solcited UUIDs. */
ble_advdata_conn_int_t * p_slave_conn_int; /**< Slave Connection Interval Range. */
ble_advdata_manuf_data_t * p_manuf_specific_data; /**< Manufacturer specific data. */
ble_advdata_service_data_t * p_service_data_array; /**< Array of Service data structures. */
uint8_t service_data_count; /**< Number of Service data structures. */
} ble_advdata_t;
/**@brief Function for encoding and setting the advertising data and/or scan response data.
*
* @details This function encodes advertising data and/or scan response data based on the selections
* in the supplied structures, and passes the encoded data to the stack.
*
* @param[in] p_advdata Structure for specifying the content of the advertising data.
* Set to NULL if advertising data is not to be set.
* @param[in] p_srdata Structure for specifying the content of the scan response data.
* Set to NULL if scan response data is not to be set.
*
* @return NRF_SUCCESS on success, NRF_ERROR_DATA_SIZE if not all the requested data could fit
* into the advertising packet. The maximum size of the advertisement packet is @ref
* BLE_GAP_ADV_MAX_SIZE.
*
* @warning This API may override application's request to use the long name and use a short name
* instead. This truncation will occur in case the long name does not fit advertisement data size.
* Application is permitted to specify a preferred short name length in case truncation is required.
* For example, if the complete device name is ABCD_HRMonitor, application can specify short name
* length to 8 such that short device name appears as ABCD_HRM instead of ABCD_HRMo or ABCD_HRMoni
* etc if available size for short name is 9 or 12 respectively to have more apporpriate short name.
* However, it should be noted that this is just a preference that application can specify and
* if the preference too large to fit in Advertisement Data, this can be further truncated.
*/
uint32_t ble_advdata_set(const ble_advdata_t * p_advdata, const ble_advdata_t * p_srdata);
#endif // BLE_ADVDATA_H__
/** @} */
/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is property of Nordic Semiconductor ASA.
* Terms and conditions of usage are described in detail in NORDIC
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
*
* Licensees are granted free, non-transferable use of the information. NO
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* the file.
*
*/
/** @file
*
* @defgroup ble_sdk_lib_advdata Advertising Data Encoder
* @{
* @ingroup ble_sdk_lib
* @brief Function for encoding the advertising data and/or scan response data, and passing them to
* the stack.
*/
#ifndef BLE_ADVDATA_H__
#define BLE_ADVDATA_H__
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "ble.h"
#include "app_util.h"
/**@brief Advertising data name type. This contains the options available for the device name inside
* the advertising data. */
typedef enum
{
BLE_ADVDATA_NO_NAME, /**< Include no device name in advertising data. */
BLE_ADVDATA_SHORT_NAME, /**< Include short device name in advertising data. */
BLE_ADVDATA_FULL_NAME /**< Include full device name in advertising data. */
} ble_advdata_name_type_t;
/**@brief UUID list type. */
typedef struct
{
uint16_t uuid_cnt; /**< Number of UUID entries. */
ble_uuid_t * p_uuids; /**< Pointer to UUID array entries. */
} ble_advdata_uuid_list_t;
/**@brief Connection interval range structure. */
typedef struct
{
uint16_t min_conn_interval; /**< Minimum Connection Interval, in units of 1.25ms, range 6 to 3200 (i.e. 7.5ms to 4s). */
uint16_t max_conn_interval; /**< Maximum Connection Interval, in units of 1.25ms, range 6 to 3200 (i.e. 7.5ms to 4s). Value of 0xFFFF indicates no specific maximum. */
} ble_advdata_conn_int_t;
/**@brief Manufacturer specific data structure. */
typedef struct
{
uint16_t company_identifier; /**< Company Identifier Code. */
uint8_array_t data; /**< Additional manufacturer specific data. */
} ble_advdata_manuf_data_t;
/**@brief Service data structure. */
typedef struct
{
uint16_t service_uuid; /**< Service UUID. */
uint8_array_t data; /**< Additional service data. */
} ble_advdata_service_data_t;
/**@brief Advertising data structure. This contains all options and data needed for encoding and
* setting the advertising data. */
typedef struct
{
ble_advdata_name_type_t name_type; /**< Type of device name. */
uint8_t short_name_len; /**< Length of short device name (if short type is specified). */
bool include_appearance; /**< Determines if Appearance shall be included. */
uint8_t flags; /**< Advertising data Flags field. */
int8_t * p_tx_power_level; /**< TX Power Level field. */
ble_advdata_uuid_list_t uuids_more_available; /**< List of UUIDs in the 'More Available' list. */
ble_advdata_uuid_list_t uuids_complete; /**< List of UUIDs in the 'Complete' list. */
ble_advdata_uuid_list_t uuids_solicited; /**< List of solcited UUIDs. */
ble_advdata_conn_int_t * p_slave_conn_int; /**< Slave Connection Interval Range. */
ble_advdata_manuf_data_t * p_manuf_specific_data; /**< Manufacturer specific data. */
ble_advdata_service_data_t * p_service_data_array; /**< Array of Service data structures. */
uint8_t service_data_count; /**< Number of Service data structures. */
} ble_advdata_t;
/**@brief Function for encoding and setting the advertising data and/or scan response data.
*
* @details This function encodes advertising data and/or scan response data based on the selections
* in the supplied structures, and passes the encoded data to the stack.
*
* @param[in] p_advdata Structure for specifying the content of the advertising data.
* Set to NULL if advertising data is not to be set.
* @param[in] p_srdata Structure for specifying the content of the scan response data.
* Set to NULL if scan response data is not to be set.
*
* @return NRF_SUCCESS on success, NRF_ERROR_DATA_SIZE if not all the requested data could fit
* into the advertising packet. The maximum size of the advertisement packet is @ref
* BLE_GAP_ADV_MAX_SIZE.
*
* @warning This API may override application's request to use the long name and use a short name
* instead. This truncation will occur in case the long name does not fit advertisement data size.
* Application is permitted to specify a preferred short name length in case truncation is required.
* For example, if the complete device name is ABCD_HRMonitor, application can specify short name
* length to 8 such that short device name appears as ABCD_HRM instead of ABCD_HRMo or ABCD_HRMoni
* etc if available size for short name is 9 or 12 respectively to have more apporpriate short name.
* However, it should be noted that this is just a preference that application can specify and
* if the preference too large to fit in Advertisement Data, this can be further truncated.
*/
uint32_t ble_advdata_set(const ble_advdata_t * p_advdata, const ble_advdata_t * p_srdata);
#endif // BLE_ADVDATA_H__
/** @} */

View file

@ -1,56 +1,24 @@
/*
* Copyright (c) Nordic Semiconductor ASA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ble_advdata_parser.h"
uint32_t ble_advdata_parser_field_find(uint8_t type,
uint8_t * p_advdata,
uint8_t * len,
uint8_t ** pp_field_data)
{
uint32_t index = 0;
while (index < *len)
{
uint8_t field_length = p_advdata[index];
uint8_t field_type = p_advdata[index + 1];
if (field_type == type)
{
*pp_field_data = &p_advdata[index + 2];
*len = field_length - 1;
return NRF_SUCCESS;
}
index += field_length + 1;
}
return NRF_ERROR_NOT_FOUND;
}
#include "ble_advdata_parser.h"
uint32_t ble_advdata_parser_field_find(uint8_t type,
uint8_t * p_advdata,
uint8_t * len,
uint8_t ** pp_field_data)
{
uint32_t index = 0;
while (index < *len)
{
uint8_t field_length = p_advdata[index];
uint8_t field_type = p_advdata[index + 1];
if (field_type == type)
{
*pp_field_data = &p_advdata[index + 2];
*len = field_length - 1;
return NRF_SUCCESS;
}
index += field_length + 1;
}
return NRF_ERROR_NOT_FOUND;
}

View file

@ -1,41 +1,9 @@
/*
* Copyright (c) Nordic Semiconductor ASA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef BLE_ADVDATA_PARSER_H_
#define BLE_ADVDATA_PARSER_H_
#include "ble_advdata.h"
uint32_t ble_advdata_parse(uint8_t * p_data, uint8_t len, ble_advdata_t * advdata);
uint32_t ble_advdata_parser_field_find(uint8_t type, uint8_t * p_advdata, uint8_t * len, uint8_t ** pp_field_data);
#endif
#ifndef BLE_ADVDATA_PARSER_H_
#define BLE_ADVDATA_PARSER_H_
#include "ble_advdata.h"
uint32_t ble_advdata_parse(uint8_t * p_data, uint8_t len, ble_advdata_t * advdata);
uint32_t ble_advdata_parser_field_find(uint8_t type, uint8_t * p_advdata, uint8_t * len, uint8_t ** pp_field_data);
#endif

View file

@ -1,381 +1,323 @@
/*
* Copyright (c) Nordic Semiconductor ASA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ble_conn_params.h"
#include <stdlib.h>
#include "nordic_common.h"
#include "ble_hci.h"
#include "ble_srv_common.h"
#include "app_util.h"
#ifdef USE_APP_TIMER
#include "app_timer.h"
#else
#include "mbed.h"
#endif
static ble_conn_params_init_t m_conn_params_config; /**< Configuration as specified by the application. */
static ble_gap_conn_params_t m_preferred_conn_params; /**< Connection parameters preferred by the application. */
static uint8_t m_update_count; /**< Number of Connection Parameter Update messages that has currently been sent. */
static uint16_t m_conn_handle; /**< Current connection handle. */
static ble_gap_conn_params_t m_current_conn_params; /**< Connection parameters received in the most recent Connect event. */
#ifdef USE_APP_TIMER
static app_timer_id_t m_conn_params_timer_id; /**< Connection parameters timer. */
#else
static Ticker m_conn_params_timer;
#endif
static bool m_change_param = false;
static bool is_conn_params_ok(ble_gap_conn_params_t * p_conn_params)
{
// Check if interval is within the acceptable range.
// NOTE: Using max_conn_interval in the received event data because this contains
// the client's connection interval.
if (
(p_conn_params->max_conn_interval >= m_preferred_conn_params.min_conn_interval)
&&
(p_conn_params->max_conn_interval <= m_preferred_conn_params.max_conn_interval)
)
{
return true;
}
else
{
return false;
}
}
#ifdef USE_APP_TIMER
static void update_timeout_handler(void * p_context)
{
UNUSED_PARAMETER(p_context);
#else /* #if !USE_APP_TIMER */
static void update_timeout_handler(void)
{
m_conn_params_timer.detach(); /* this is supposed to be a single-shot timer callback */
#endif /* #if !USE_APP_TIMER */
if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
{
// Check if we have reached the maximum number of attempts
m_update_count++;
if (m_update_count <= m_conn_params_config.max_conn_params_update_count)
{
uint32_t err_code;
// Parameters are not ok, send connection parameters update request.
err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_preferred_conn_params);
if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
{
m_conn_params_config.error_handler(err_code);
}
}
else
{
m_update_count = 0;
// Negotiation failed, disconnect automatically if this has been configured
if (m_conn_params_config.disconnect_on_fail)
{
uint32_t err_code;
err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE);
if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
{
m_conn_params_config.error_handler(err_code);
}
}
// Notify the application that the procedure has failed
if (m_conn_params_config.evt_handler != NULL)
{
ble_conn_params_evt_t evt;
evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED;
m_conn_params_config.evt_handler(&evt);
}
}
}
}
uint32_t ble_conn_params_init(const ble_conn_params_init_t * p_init)
{
uint32_t err_code;
m_conn_params_config = *p_init;
m_change_param = false;
if (p_init->p_conn_params != NULL)
{
m_preferred_conn_params = *p_init->p_conn_params;
// Set the connection params in stack
err_code = sd_ble_gap_ppcp_set(&m_preferred_conn_params);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
}
else
{
// Fetch the connection params from stack
err_code = sd_ble_gap_ppcp_get(&m_preferred_conn_params);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
}
m_conn_handle = BLE_CONN_HANDLE_INVALID;
m_update_count = 0;
#ifdef USE_APP_TIMER
return app_timer_create(&m_conn_params_timer_id,
APP_TIMER_MODE_SINGLE_SHOT,
update_timeout_handler);
#else
return NRF_SUCCESS;
#endif
}
uint32_t ble_conn_params_stop(void)
{
#ifdef USE_APP_TIMER
return app_timer_stop(m_conn_params_timer_id);
#else /* #if !USE_APP_TIMER */
m_conn_params_timer.detach();
return NRF_SUCCESS;
#endif /* #if !USE_APP_TIMER */
}
static void conn_params_negotiation(void)
{
// Start negotiation if the received connection parameters are not acceptable
if (!is_conn_params_ok(&m_current_conn_params))
{
#ifdef USE_APP_TIMER
uint32_t err_code;
#endif
uint32_t timeout_ticks;
if (m_change_param)
{
// Notify the application that the procedure has failed
if (m_conn_params_config.evt_handler != NULL)
{
ble_conn_params_evt_t evt;
evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED;
m_conn_params_config.evt_handler(&evt);
}
}
else
{
if (m_update_count == 0)
{
// First connection parameter update
timeout_ticks = m_conn_params_config.first_conn_params_update_delay;
}
else
{
timeout_ticks = m_conn_params_config.next_conn_params_update_delay;
}
#ifdef USE_APP_TIMER
err_code = app_timer_start(m_conn_params_timer_id, timeout_ticks, NULL);
if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
{
m_conn_params_config.error_handler(err_code);
}
#else
m_conn_params_timer.attach(update_timeout_handler, timeout_ticks / 32768);
#endif
}