Merge pull request #185 from tkuyucu/master

nrf-mbed merge
pull/188/head mbed_lib_rev80
Emilio Monti 2014-02-21 12:01:25 +00:00
commit 195a50befc
43 changed files with 10399 additions and 57 deletions

View File

@ -1,5 +1,5 @@
; mbed Microcontroller Library
; Copyright (c) 2006-2013 ARM Limited
; Copyright (c) 2013 Nordic Semiconductor.
;Licensed under the Apache License, Version 2.0 (the "License");
;you may not use this file except in compliance with the License.
;You may obtain a copy of the License at

View File

@ -52,7 +52,7 @@ uint32_t NVIC_GetVector(IRQn_Type IRQn) {
}*/
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
int i;
// int i;
// Space for dynamic vectors, initialised to allocate in R/W
static volatile uint32_t* vectors = (uint32_t*)NVIC_RAM_VECTOR_ADDRESS;
/*

View File

@ -0,0 +1,17 @@
#ifndef _NORDIC_GLOBAL_H_
#define _NORDIC_GLOBAL_H_
/* There are no global defines in mbed, so we need to define */
/* mandatory conditional compilation flags here */
//#define NRF51
#ifndef DEBUG_NRF_USER
#define DEBUG_NRF_USER
#endif
#ifndef BLE_STACK_SUPPORT_REQD
#define BLE_STACK_SUPPORT_REQD
#endif
#ifndef BOARD_PCA10001
#define BOARD_PCA10001
#endif
#endif

View File

@ -1,18 +1,13 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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.
*
* http://www.apache.org/licenses/LICENSE-2.0
* 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.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

View File

@ -1,6 +1,6 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2013 Nordic Semiconductor.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,7 +19,7 @@
#ifndef NRF_H
#define NRF_H
#include "nordic_global.h"
#include "compiler_abstraction.h"
#include "nrf51.h"
#include "nrf51_bitfields.h"

View File

@ -1,6 +1,6 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2013 Nordic Semiconductor.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -43,33 +43,19 @@ void SystemCoreClockUpdate(void)
}
void SystemInit(void)
{
//Write the necessary UICR and FWID values if needed
if (NRF_UICR->CLENR0 == 0xFFFFFFFF){
NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos);
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){
}
NRF_UICR->CLENR0 = 0x14000;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){
}
//write FWID (NRF_UICR->FWID is readonly)
*(uint32_t *)0x10001010 = 0xFFFF0049;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){
}
NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){
}
NVIC_SystemReset();
while (true){
}
{
NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos);
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){
}
//write FWID (NRF_UICR->FWID is readonly)
*(uint32_t *)0x10001010 = 0xFFFF0049;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){
}
NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){
}
// Prepare the peripherals for use as indicated by the PAN 26 "System: Manual setup is required
// to enable the use of peripherals" found at Product Anomaly document for your device found at
// https://www.nordicsemi.com/. The side effect of executing these instructions in the devices

View File

@ -1,6 +1,6 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2013 Nordic Semiconductor.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -0,0 +1,174 @@
NORDIC SEMICONDUCTOR ASA SOFTDEVICE LICENSE AGREEMENT
License Agreement for the Nordic Semiconductor ASA ("Nordic")
S110 Bluetooth SoftDevice software package ("SoftDevice").
You ("You" "Licensee") must carefully and thoroughly read this License
Agreement ("Agreement"), and accept to adhere to this Agreement before
downloading, installing and/or using any software or content in the
SoftDevice provided herewith.
YOU ACCEPT THIS LICENSE AGREEMENT BY (A) CLICKING ACCEPT OR AGREE TO
THIS LICENSE AGREEMENT, WHERE THIS OPTION IS MADE AVAILABLE TO YOU; OR
(B) BY ACTUALLY USING THE SOFTDEVICE, IN THIS CASE YOU AGREE THAT THE
USE OF THE SOFTDEVICE CONSTITUTES ACCEPTANCE OF THE LICENSING
AGREEMENT FROM THAT POINT ONWARDS.
IF YOU DO NOT AGREE TO BE BOUND BY THE TERMS OF THIS AGREEMENT, THEN
DO NOT DOWNLOAD, INSTALL/COMPLETE INSTALLATION OF, OR IN ANY OTHER WAY
MAKE USE OF THE SOFTDEVICE.
1. Grant of License
Subject to the terms in this Agreement Nordic grants Licensee a
limited, non-exclusive, non-transferable, non-sub licensable,
revocable license ("License"): (a) to use the SoftDevice solely in
connection with a Nordic integrated circuit, and (b) to distribute the
SoftDevice solely as integrated in Licensee Product. Licensee shall
not use the SoftDevice for any purpose other than specifically
authorized herein. It is a material breach of this agreement to use or
modify the SoftDevice for use on any wireless connectivity integrated
circuit other than a Nordic integrated circuit.
2. Title
Nordic retains full rights, title, and ownership to the SoftDevice and
any and all patents, copyrights, trade secrets, trade names,
trademarks, and other intellectual property rights in and to the
SoftDevice.
3. No Modifications or Reverse Engineering
Licensee shall not, modify, reverse engineer, disassemble, decompile
or otherwise attempt to discover the source code of any non-source
code parts of the SoftDevice including, but not limited to
pre-compiled hex files, binaries and object code.
4. Distribution Restrictions
Except as set forward in Section 1 above, the Licensee may not
disclose or distribute any or all parts of the SoftDevice to any third
party. Licensee agrees to provide reasonable security precautions to
prevent unauthorized access to or use of the SoftDevice as proscribed
herein. Licensee also agrees that use of and access to the SoftDevice
will be strictly limited to the employees and subcontractors of the
Licensee necessary for the performance of development, verification
and production tasks under this Agreement. The Licensee is responsible
for making such employees and subcontractors comply with the
obligations concerning use and non-disclosure of the SoftDevice.
6. No Other Rights
Licensee shall use the SoftDevice only in compliance with this
Agreement and shall refrain from using the SoftDevice in any way that
may be contrary to this Agreement.
7. Fees
Nordic grants the License to the Licensee free of charge provided that
the Licensee undertakes the obligations in the Agreement and warrants
to comply with the Agreement.
8. DISCLAIMER OF WARRANTY
THE SOFTDEVICE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND
EXPRESS OR IMPLIED AND NEITHER NORDIC, ITS LICENSORS OR AFFILIATES NOR
THE COPYRIGHT HOLDERS MAKE ANY REPRESENTATIONS OR WARRANTIES, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR THAT THE
SOFTDEVICE WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
TRADEMARKS OR OTHER RIGHTS. THERE IS NO WARRANTY BY NORDIC OR BY ANY
OTHER PARTY THAT THE FUNCTIONS CONTAINED IN THE SOFTDEVICE WILL MEET
THE REQUIREMENTS OF LICENSEE OR THAT THE OPERATION OF THE SOFTDEVICE
WILL BE UNINTERRUPTED OR ERROR-FREE. LICENSEE ASSUMES ALL
RESPONSIBILITY AND RISK FOR THE SELECTION OF THE SOFTDEVICE TO ACHIEVE
LICENSEES INTENDED RESULTS AND FOR THE INSTALLATION, USE AND RESULTS
OBTAINED FROM IT.
9. No Support
Nordic is not obligated to furnish or make available to Licensee any
further information, software, technical information, know-how,
show-how, bug-fixes or support. Nordic reserves the right to make
changes to the SoftDevice without further notice.
10. Limitation of Liability
In no event shall Nordic, its employees or suppliers, licensors or
affiliates be liable for any lost profits, revenue, sales, data or
costs of procurement of substitute goods or services, property damage,
personal injury, interruption of business, loss of business
information or for any special, direct, indirect, incidental,
economic, punitive, special or consequential damages, however caused
and whether arising under contract, tort, negligence, or other theory
of liability arising out of the use of or inability to use the
SoftDevice, even if Nordic or its employees or suppliers, licensors or
affiliates are advised of the possibility of such damages. Because
some countries/states/jurisdictions do not allow the exclusion or
limitation of liability, but may allow liability to be limited, in
such cases, Nordic, its employees or licensors or affiliates
liability shall be limited to USD 50.
11. Breach of Contract
Upon a breach of contract by the Licensee, Nordic and its licensor are
entitled to damages in respect of any direct loss which can be
reasonably attributed to the breach by the Licensee. If the Licensee
has acted with gross negligence or willful misconduct, the Licensee
shall cover both direct and indirect costs for Nordic and its
licensors.
12. Indemnity
Licensee undertakes to indemnify, hold harmless and defend Nordic and
its directors, officers, affiliates, shareholders, licensors,
employees and agents from and against any claims or lawsuits,
including attorney's fees, that arise or result of the Licensees
execution of the License and which is not due to causes for which
Nordic is responsible.
13. Governing Law
This Agreement shall be construed according to the laws of Norway, and
hereby submits to the exclusive jurisdiction of the Oslo tingrett.
14. Assignment
Licensee shall not assign this Agreement or any rights or obligations
hereunder without the prior written consent of Nordic.
15. Termination
Without prejudice to any other rights, Nordic may cancel this
Agreement if Licensee does not abide by the terms and conditions of
this Agreement. Upon termination Licensee must promptly cease the use
of the License and destroy all copies of the Licensed Technology and
any other material provided by Nordic or its affiliate, or produced by
the Licensee in connection with the Agreement or the Licensed
Technology.
16. Third party beneficiaries
Nordics licensors are intended third party beneficiaries under this
Agreement.

View File

@ -0,0 +1,302 @@
/* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is confidential property of Nordic Semiconductor. The use,
* copying, transfer or disclosure of such information is prohibited except by express written
* agreement with Nordic Semiconductor.
*
*/
/**
@addtogroup BLE_COMMON BLE SoftDevice Common
@{
@defgroup ble_api Events, type definitions and API calls
@{
@brief Module independent events, type definitions and API calls for the S110 SoftDevice.
*/
#ifndef BLE_H__
#define BLE_H__
#include "ble_ranges.h"
#include "ble_types.h"
#include "ble_gap.h"
#include "ble_l2cap.h"
#include "ble_gatt.h"
#include "ble_gattc.h"
#include "ble_gatts.h"
/**
* @brief Common API SVC numbers.
*/
enum BLE_COMMON_SVCS
{
SD_BLE_EVT_GET = BLE_SVC_BASE, /**< Get an event from the pending events queue. */
SD_BLE_TX_BUFFER_COUNT_GET, /**< Get the total number of available application transmission buffers from the stack. */
SD_BLE_UUID_VS_ADD, /**< Add a Vendor Specific UUID. */
SD_BLE_UUID_DECODE, /**< Decode UUID bytes. */
SD_BLE_UUID_ENCODE, /**< Encode UUID bytes. */
SD_BLE_VERSION_GET, /**< Get the local version information (company id, LMP Version, LMP Subversion). */
SD_BLE_USER_MEM_REPLY, /**< User Memory Reply. */
};
/** @brief Required pointer alignment for BLE Events.
*/
#define BLE_EVTS_PTR_ALIGNMENT 4
/** @defgroup BLE_USER_MEM_TYPES User Memory Types
* @{ */
#define BLE_USER_MEM_TYPE_INVALID 0x00 /**< Invalid User Memory Types. */
#define BLE_USER_MEM_TYPE_GATTS_QUEUED_WRITES 0x01 /**< User Memory for GATTS queued writes. */
/** @} */
/** @brief Maximum number of Vendor Specific UUIDs.
*/
#define BLE_UUID_VS_MAX_COUNT 10
/**
* @brief BLE Module Independent Event IDs.
*/
enum BLE_COMMON_EVTS
{
BLE_EVT_TX_COMPLETE = BLE_EVT_BASE, /**< Transmission Complete. */
BLE_EVT_USER_MEM_REQUEST, /**< User Memory request. */
BLE_EVT_USER_MEM_RELEASE /**< User Memory release. */
};
/**@brief User Memory Block. */
typedef struct
{
uint8_t* p_mem; /**< Pointer to the start of the user memory block. */
uint16_t len; /**< Length in bytes of the user memory block. */
} ble_user_mem_block_t;
/**
* @brief TX complete event.
*/
typedef struct
{
uint8_t count; /**< Number of packets transmitted. */
} ble_evt_tx_complete_t;
/**@brief Event structure for BLE_EVT_USER_MEM_REQUEST. */
typedef struct
{
uint8_t type; /**< User memory type, see @ref BLE_USER_MEM_TYPES. */
} ble_evt_user_mem_request_t;
/**@brief Event structure for BLE_EVT_USER_MEM_RELEASE. */
typedef struct
{
uint8_t type; /**< User memory type, see @ref BLE_USER_MEM_TYPES. */
ble_user_mem_block_t mem_block; /**< User memory block */
} ble_evt_user_mem_release_t;
/**@brief Event structure for events not associated with a specific function module. */
typedef struct
{
uint16_t conn_handle; /**< Connection Handle on which this event occured. */
union
{
ble_evt_tx_complete_t tx_complete; /**< Transmission Complete. */
ble_evt_user_mem_request_t user_mem_request; /**< User Memory Request Event Parameters. */
ble_evt_user_mem_release_t user_mem_release; /**< User Memory Release Event Parameters. */
} params;
} ble_common_evt_t;
/**@brief BLE Event header. */
typedef struct
{
uint16_t evt_id; /**< Value from a BLE_<module>_EVT series. */
uint16_t evt_len; /**< Length in octets excluding this header. */
} ble_evt_hdr_t;
/**@brief Common BLE Event type, wrapping the module specific event reports. */
typedef struct
{
ble_evt_hdr_t header; /**< Event header. */
union
{
ble_common_evt_t common_evt; /**< Common Event, evt_id in BLE_EVT_* series. */
ble_gap_evt_t gap_evt; /**< GAP originated event, evt_id in BLE_GAP_EVT_* series. */
ble_l2cap_evt_t l2cap_evt; /**< L2CAP originated event, evt_id in BLE_L2CAP_EVT* series. */
ble_gattc_evt_t gattc_evt; /**< GATT client originated event, evt_id in BLE_GATTC_EVT* series. */
ble_gatts_evt_t gatts_evt; /**< GATT server originated event, evt_id in BLE_GATTS_EVT* series. */
} evt;
} ble_evt_t;
/**
* @brief Version Information.
*/
typedef struct
{
uint8_t version_number; /**< LMP Version number for BT 4.0 spec is 6 (https://www.bluetooth.org/technical/assignednumbers/link_layer.htm). */
uint16_t company_id; /**< Company ID, Nordic Semiconductor's company ID is 89 (0x0059) (https://www.bluetooth.org/apps/content/Default.aspx?doc_id=49708). */
uint16_t subversion_number; /**< LMP Sub Version number corresponds to the SoftDevice Config ID. */
} ble_version_t;
/**@brief Get an event from the pending events queue.
*
* @param[in] p_dest Pointer to buffer to be filled in with an event, or NULL to retrieve the event length. This buffer <b>must be 4-byte aligned in memory</b>.
* @param[in, out] p_len Pointer the length of the buffer, on return it is filled with the event length.
*
* @details This call allows the application to pull a BLE event from the BLE stack. The application is signalled that an event is
* available from the BLE Stack by the triggering of the SD_EVT_IRQn interrupt (mapped to IRQ 22).
* The application is free to choose whether to call this function from thread mode (main context) or directly from the Interrupt Service Routine
* that maps to SD_EVT_IRQn. In any case however, and because the BLE stack runs at a higher priority than the application, this function should be called
* in a loop (until @ref NRF_ERROR_NOT_FOUND is returned) every time SD_EVT_IRQn is raised to ensure that all available events are pulled from the stack.
* Failure to do so could potentially leave events in the internal queue without the application being aware of this fact.
* Sizing the p_dest buffer is equally important, since the application needs to provide all the memory necessary for the event to be copied into
* application memory. If the buffer provided is not large enough to fit the entire contents of the event, @ref NRF_ERROR_DATA_SIZE will be returned
* and the application can then call again with a larger buffer size.
* Please note that because of the variable length nature of some events, sizeof(ble_evt_t) will not always be large enough to fit certain events,
* and so it is the application's responsability to provide an amount of memory large enough so that the relevant event is copied in full.
* The application may "peek" the event length by providing p_dest as a NULL pointer and inspecting the value of *p_len upon return.
*
* @note The pointer supplied must be aligned to the extend defined by @ref BLE_EVTS_PTR_ALIGNMENT
*
* @return @ref NRF_SUCCESS Event pulled and stored into the supplied buffer.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid or not sufficiently aligned pointer supplied.
* @return @ref NRF_ERROR_NOT_FOUND No events ready to be pulled.
* @return @ref NRF_ERROR_DATA_SIZE Event ready but could not fit into the supplied buffer.
*/
SVCALL(SD_BLE_EVT_GET, uint32_t, sd_ble_evt_get(uint8_t* p_dest, uint16_t *p_len));
/**@brief Get the total number of available application transmission buffers in the BLE stack.
*
* @details This call allows the application to obtain the total number of
* transmission buffers available for application data. Please note that
* this does not give the number of free buffers, but rather the total amount of them.
* The application has two options to handle its own application transmission buffers:
* - Use a simple arithmetic calculation: at boot time the application should use this function
* to find out the total amount of buffers available to it and store it in a variable.
* Every time a packet that consumes an application buffer is sent using any of the
* exposed functions in this BLE API, the application should decrement that variable.
* Conversely, whenever a @ref BLE_EVT_TX_COMPLETE event is received by the application
* it should retrieve the count field in such event and add that number to the same
* variable storing the number of available packets.
* This mechanism allows the application to be aware at any time of the number of
* application packets available in the BLE stack's internal buffers, and therefore
* it can know with certainty whether it is possible to send more data or it has to
* wait for a @ref BLE_EVT_TX_COMPLETE event before it proceeds.
* - Choose to simply not keep track of available buffers at all, and instead handle the
* @ref BLE_ERROR_NO_TX_BUFFERS error by queueing the packet to be transmitted and
* try again as soon as a @ref BLE_EVT_TX_COMPLETE event arrives.
*
* The API functions that <b>may</b> consume an application buffer depending on
* the parameters supplied to them can be found below:
*
* - @ref sd_ble_gattc_write (write witout response only)
* - @ref sd_ble_gatts_hvx (notifications only)
* - @ref sd_ble_l2cap_tx (all packets)
*
* @param[out] p_count Pointer to a uint8_t which will contain the number of application transmission buffers upon
* successful return.
*
* @return @ref NRF_SUCCESS Number of application transmission buffers retrieved successfully.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
*/
SVCALL(SD_BLE_TX_BUFFER_COUNT_GET, uint32_t, sd_ble_tx_buffer_count_get(uint8_t* p_count));
/**@brief Add a Vendor Specific UUID.
*
* @details This call enables the application to add a vendor specific UUID to the BLE stack's table,
* for later use all other modules and APIs. This then allows the application to use the shorter,
* 24-bit @ref ble_uuid_t format when dealing with both 16-bit and 128-bit UUIDs without having to
* check for lengths and having split code paths. The way that this is accomplished is by extending the
* grouping mechanism that the Bluetooth SIG standard base UUID uses for all other 128-bit UUIDs. The
* type field in the @ref ble_uuid_t structure is an index (relative to @ref BLE_UUID_TYPE_VENDOR_BEGIN)
* to the table populated by multiple calls to this function, and the uuid field in the same structure
* contains the 2 bytes at indices 12 and 13. The number of possible 128-bit UUIDs available to the
* application is therefore the number of Vendor Specific UUIDs added with the help of this function times 65536,
* although restricted to modifying bytes 12 and 13 for each of the entries in the supplied array.
*
* @note Bytes 12 and 13 of the provided UUID will not be used internally, since those are always replaced by
* the 16-bit uuid field in @ref ble_uuid_t.
*
*
* @param[in] p_vs_uuid Pointer to a 16-octet (128-bit) little endian Vendor Specific UUID disregarding
* bytes 12 and 13.
* @param[out] p_uuid_type Pointer where the type field in @ref ble_uuid_t corresponding to this UUID will be stored.
*
* @return @ref NRF_SUCCESS Successfully added the Vendor Specific UUID.
* @return @ref NRF_ERROR_INVALID_ADDR If p_vs_uuid or p_uuid_type is NULL or invalid.
* @return @ref NRF_ERROR_NO_MEM If there are no more free slots for VS UUIDs.
* @return @ref NRF_ERROR_FORBIDDEN If p_vs_uuid has already been added to the VS UUID table.
*/
SVCALL(SD_BLE_UUID_VS_ADD, uint32_t, sd_ble_uuid_vs_add(ble_uuid128_t const * const p_vs_uuid, uint8_t * const p_uuid_type));
/** @brief Decode little endian raw UUID bytes (16-bit or 128-bit) into a 24 bit @ref ble_uuid_t structure.
*
* @details The raw UUID bytes excluding bytes 12 and 13 (i.e. bytes 0-11 and 14-15) of p_uuid_le are compared
* to the corresponding ones in each entry of the table of vendor specific UUIDs pouplated with @ref sd_ble_uuid_vs_add
* to look for a match. If there is such a match, bytes 12 and 13 are returned as p_uuid->uuid and the index
* relative to @ref BLE_UUID_TYPE_VENDOR_BEGIN as p_uuid->type.
*
* @note If the UUID length supplied is 2, then the type set by this call will always be @ref BLE_UUID_TYPE_BLE.
*
* @param[in] uuid_le_len Length in bytes of the buffer pointed to by p_uuid_le (must be 2 or 16 bytes).
* @param[in] p_uuid_le Pointer pointing to little endian raw UUID bytes.
* @param[in,out] p_uuid Pointer to a @ref ble_uuid_t structure to be filled in.
*
* @return @ref NRF_SUCCESS Successfully decoded into the @ref ble_uuid_t structure.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_INVALID_LENGTH Invalid UUID length.
* @return @ref NRF_ERROR_NOT_FOUND For a 128-bit UUID, no match in the populated table of UUIDs.
*/
SVCALL(SD_BLE_UUID_DECODE, uint32_t, sd_ble_uuid_decode(uint8_t uuid_le_len, uint8_t const * const p_uuid_le, ble_uuid_t * const p_uuid));
/** @brief Encode a @ref ble_uuid_t structure into little endian raw UUID bytes (16-bit or 128-bit).
*
* @note The pointer to the destination buffer p_uuid_le may be NULL, in which case only the validitiy and size of p_uuid is computed.
*
* @param[in] p_uuid Pointer to a @ref ble_uuid_t structure that will be encoded into bytes.
* @param[out] p_uuid_le_len Pointer to a uint8_t that will be filled with the encoded length (2 or 16 bytes).
* @param[out] p_uuid_le Pointer to a buffer where the little endian raw UUID bytes (2 or 16) will be stored.
*
* @return @ref NRF_SUCCESS Successfully encoded into the buffer.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid UUID type.
*/
SVCALL(SD_BLE_UUID_ENCODE, uint32_t, sd_ble_uuid_encode(ble_uuid_t const * const p_uuid, uint8_t * const p_uuid_le_len, uint8_t * const p_uuid_le));
/**@brief Get Version Information.
*
* @details This call allows the application to get the BLE stack version information.
*
* @param[in] p_version Pointer to ble_version_t structure to be filled in.
*
* @return @ref NRF_SUCCESS Version information stored successfully.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_BUSY The stack is busy (typically doing a locally-initiated disconnection procedure).
*/
SVCALL(SD_BLE_VERSION_GET, uint32_t, sd_ble_version_get(ble_version_t * p_version));
/**@brief Provide a user memory block.
*
* @note This call can only be used as a response to a @ref BLE_EVT_USER_MEM_REQUEST event issued to the application.
*
* @param[in] conn_handle Connection handle.
* @param[in] p_block Pointer to a user memory block structure.
*
* @return @ref NRF_SUCCESS Successfully queued a response to the peer.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
* @return @ref NRF_ERROR_INVALID_STATE No execute write request pending.
*/
SVCALL(SD_BLE_USER_MEM_REPLY, uint32_t, sd_ble_user_mem_reply(uint16_t conn_handle, ble_user_mem_block_t *p_block));
#endif /* BLE_H__ */
/**
@}
@}
*/

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is confidential property of Nordic Semiconductor. The use,
* copying, transfer or disclosure of such information is prohibited except by express written
* agreement with Nordic Semiconductor.
*
*/
/**
@addtogroup BLE_COMMON
@{
@addtogroup nrf_error
@{
@ingroup BLE_COMMON
@}
@defgroup ble_err General error codes
@{
@brief General error code definitions for the BLE API.
@ingroup BLE_COMMON
*/
#ifndef NRF_BLE_ERR_H__
#define NRF_BLE_ERR_H__
#include "nrf_error.h"
/* @defgroup BLE_ERRORS Error Codes
* @{ */
#define BLE_ERROR_INVALID_CONN_HANDLE (NRF_ERROR_STK_BASE_NUM+0x001) /**< Invalid connection handle. */
#define BLE_ERROR_INVALID_ATTR_HANDLE (NRF_ERROR_STK_BASE_NUM+0x002) /**< Invalid attribute handle. */
#define BLE_ERROR_NO_TX_BUFFERS (NRF_ERROR_STK_BASE_NUM+0x003) /**< Buffer capacity exceeded. */
/** @} */
/** @defgroup BLE_ERROR_SUBRANGES Module specific error code subranges
* @brief Assignment of subranges for module specific error codes.
* @note For specific error codes, see ble_<module>.h or ble_error_<module>.h.
* @{ */
#define NRF_L2CAP_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x100) /**< L2CAP specific errors. */
#define NRF_GAP_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x200) /**< GAP specific errors. */
#define NRF_GATTC_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x300) /**< GATT client specific errors. */
#define NRF_GATTS_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x400) /**< GATT server specific errors. */
/** @} */
#endif
/**
@}
@}
*/

View File

@ -0,0 +1,895 @@
/* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is confidential property of Nordic Semiconductor. The use,
* copying, transfer or disclosure of such information is prohibited except by express written
* agreement with Nordic Semiconductor.
*
*/
/**
@addtogroup BLE_GAP Generic Access Profile (GAP)
@{
@brief Definitions and prototypes for the GAP interface.
*/
#ifndef BLE_GAP_H__
#define BLE_GAP_H__
#include "ble_types.h"
#include "ble_ranges.h"
#include "nrf_svc.h"
/**
* @brief GAP API SVC numbers.
*/
enum BLE_GAP_SVCS
{
SD_BLE_GAP_ADDRESS_SET = BLE_GAP_SVC_BASE, /**< Set own Bluetooth Address. */
SD_BLE_GAP_ADDRESS_GET, /**< Get own Bluetooth Address. */
SD_BLE_GAP_ADV_DATA_SET, /**< Set Advertisement Data. */
SD_BLE_GAP_ADV_START, /**< Start Advertising. */
SD_BLE_GAP_ADV_STOP, /**< Stop Advertising. */
SD_BLE_GAP_CONN_PARAM_UPDATE, /**< Connection Parameter Update. */
SD_BLE_GAP_DISCONNECT, /**< Disconnect. */
SD_BLE_GAP_TX_POWER_SET, /**< Set TX Power. */
SD_BLE_GAP_APPEARANCE_SET, /**< Set Appearance. */
SD_BLE_GAP_APPEARANCE_GET, /**< Get Appearance. */
SD_BLE_GAP_PPCP_SET, /**< Set PPCP. */
SD_BLE_GAP_PPCP_GET, /**< Get PPCP. */
SD_BLE_GAP_DEVICE_NAME_SET, /**< Set Device Name. */
SD_BLE_GAP_DEVICE_NAME_GET, /**< Get Device Name. */
SD_BLE_GAP_AUTHENTICATE, /**< Initiate Pairing/Bonding. */
SD_BLE_GAP_SEC_PARAMS_REPLY, /**< Reply with Security Parameters. */
SD_BLE_GAP_AUTH_KEY_REPLY, /**< Reply with an authentication key. */
SD_BLE_GAP_SEC_INFO_REPLY, /**< Reply with Security Information. */
SD_BLE_GAP_CONN_SEC_GET, /**< Obtain connection security level. */
SD_BLE_GAP_RSSI_START, /**< Start reporting of changes in RSSI. */
SD_BLE_GAP_RSSI_STOP, /**< Stop reporting of changes in RSSI. */
};
/** @addtogroup BLE_GAP_DEFINES Defines
* @{ */
/** @defgroup BLE_ERRORS_GAP SVC return values specific to GAP
* @{ */
#define BLE_ERROR_GAP_UUID_LIST_MISMATCH (NRF_GAP_ERR_BASE + 0x000) /**< UUID list does not contain an integral number of UUIDs. */
#define BLE_ERROR_GAP_DISCOVERABLE_WITH_WHITELIST (NRF_GAP_ERR_BASE + 0x001) /**< Use of Whitelist not permitted with discoverable advertising. */
#define BLE_ERROR_GAP_INVALID_BLE_ADDR (NRF_GAP_ERR_BASE + 0x002) /**< The upper two bits of the address do not correspond to the specified address type. */
/** @} */
/** @defgroup BLE_GAP_ROLES GAP Roles
* @note Not explicitly used in peripheral API, but will be relevant for central API.
* @{ */
#define BLE_GAP_ROLE_INVALID 0x0 /**< Invalid Role. */
#define BLE_GAP_ROLE_PERIPH 0x1 /**< Peripheral Role. */
#define BLE_GAP_ROLE_CENTRAL 0x2 /**< Central Role. */
/** @} */
/** @defgroup BLE_GAP_TIMEOUT_SOURCES GAP Timeout sources
* @{ */
#define BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT 0x00 /**< Advertisement timeout. */
#define BLE_GAP_TIMEOUT_SRC_SECURITY_REQUEST 0x01 /**< Security request timeout. */
/** @} */
/** @defgroup BLE_GAP_ADDR_TYPES GAP Address types
* @{ */
#define BLE_GAP_ADDR_TYPE_PUBLIC 0x00 /**< Public address. */
#define BLE_GAP_ADDR_TYPE_RANDOM_STATIC 0x01 /**< Random Static address. */
#define BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE 0x02 /**< Private Resolvable address. */
#define BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE 0x03 /**< Private Non-Resolvable address. */
/** @} */
/** @brief BLE address length. */
#define BLE_GAP_ADDR_LEN 6
/** @defgroup BLE_GAP_AD_TYPE_DEFINITIONS GAP Advertising and Scan Response Data format
* @note Found at https://www.bluetooth.org/Technical/AssignedNumbers/generic_access_profile.htm
* @{ */
#define BLE_GAP_AD_TYPE_FLAGS 0x01 /**< Flags for discoverability. */
#define BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE 0x02 /**< Partial list of 16 bit service UUIDs. */
#define BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE 0x03 /**< Complete list of 16 bit service UUIDs. */
#define BLE_GAP_AD_TYPE_32BIT_SERVICE_UUID_MORE_AVAILABLE 0x04 /**< Partial list of 32 bit service UUIDs. */
#define BLE_GAP_AD_TYPE_32BIT_SERVICE_UUID_COMPLETE 0x05 /**< Complete list of 32 bit service UUIDs. */
#define BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_MORE_AVAILABLE 0x06 /**< Partial list of 128 bit service UUIDs. */
#define BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE 0x07 /**< Complete list of 128 bit service UUIDs. */
#define BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME 0x08 /**< Short local device name. */
#define BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME 0x09 /**< Complete local device name. */
#define BLE_GAP_AD_TYPE_TX_POWER_LEVEL 0x0A /**< Transmit power level. */
#define BLE_GAP_AD_TYPE_CLASS_OF_DEVICE 0x0D /**< Class of device. */
#define BLE_GAP_AD_TYPE_SIMPLE_PAIRING_HASH_C 0x0E /**< Simple Pairing Hash C. */
#define BLE_GAP_AD_TYPE_SIMPLE_PAIRING_RANDOMIZER_R 0x0F /**< Simple Pairing Randomizer R. */
#define BLE_GAP_AD_TYPE_SECURITY_MANAGER_TK_VALUE 0x10 /**< Security Manager TK Value. */
#define BLE_GAP_AD_TYPE_SECURITY_MANAGER_OOB_FLAGS 0x11 /**< Security Manager Out Of Band Flags. */
#define BLE_GAP_AD_TYPE_SLAVE_CONNECTION_INTERVAL_RANGE 0x12 /**< Slave Connection Interval Range. */
#define BLE_GAP_AD_TYPE_SOLICITED_SERVICE_UUIDS_16BIT 0x14 /**< List of 16-bit Service Solicitation UUIDs. */
#define BLE_GAP_AD_TYPE_SOLICITED_SERVICE_UUIDS_128BIT 0x15 /**< List of 128-bit Service Solicitation UUIDs. */
#define BLE_GAP_AD_TYPE_SERVICE_DATA 0x16 /**< Service Data. */
#define BLE_GAP_AD_TYPE_PUBLIC_TARGET_ADDRESS 0x17 /**< Public Target Address. */
#define BLE_GAP_AD_TYPE_RANDOM_TARGET_ADDRESS 0x18 /**< Random Target Address. */
#define BLE_GAP_AD_TYPE_APPEARANCE 0x19 /**< Appearance. */
#define BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA 0xFF /**< Manufacturer Specific Data. */
/** @} */
/** @defgroup BLE_GAP_ADV_FLAGS GAP Advertisement Flags
* @{ */
#define BLE_GAP_ADV_FLAG_LE_LIMITED_DISC_MODE (0x01) /**< LE Limited Discoverable Mode. */
#define BLE_GAP_ADV_FLAG_LE_GENERAL_DISC_MODE (0x02) /**< LE General Discoverable Mode. */
#define BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED (0x04) /**< BR/EDR not supported. */
#define BLE_GAP_ADV_FLAG_LE_BR_EDR_CONTROLLER (0x08) /**< Simultaneous LE and BR/EDR, Controller. */
#define BLE_GAP_ADV_FLAG_LE_BR_EDR_HOST (0x10) /**< Simultaneous LE and BR/EDR, Host. */
#define BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE (BLE_GAP_ADV_FLAG_LE_LIMITED_DISC_MODE | BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED) /**< LE Limited Discoverable Mode, BR/EDR not supported. */
#define BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE (BLE_GAP_ADV_FLAG_LE_GENERAL_DISC_MODE | BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED) /**< LE General Discoverable Mode, BR/EDR not supported. */
/** @} */
/** @defgroup BLE_GAP_ADV_INTERVALS GAP Advertising interval max and min
* @{ */
#define BLE_GAP_ADV_INTERVAL_MIN 0x0020 /**< Minimum Advertising interval in 625 us units, i.e. 20 ms. */
#define BLE_GAP_ADV_NONCON_INTERVAL_MIN 0x00A0 /**< Minimum Advertising interval in 625 us units for non connectable mode, i.e. 100 ms. */
#define BLE_GAP_ADV_INTERVAL_MAX 0x4000 /**< Maximum Advertising interval in 625 us units, i.e. 10.24 s. */
/** @} */
/** @brief Maximum size of advertising data in octets. */
#define BLE_GAP_ADV_MAX_SIZE 31
/** @defgroup BLE_GAP_ADV_TYPES GAP Advertising types
* @{ */
#define BLE_GAP_ADV_TYPE_ADV_IND 0x00 /**< Connectable undirected. */
#define BLE_GAP_ADV_TYPE_ADV_DIRECT_IND 0x01 /**< Connectable directed. */
#define BLE_GAP_ADV_TYPE_ADV_SCAN_IND 0x02 /**< Scannable undirected. */
#define BLE_GAP_ADV_TYPE_ADV_NONCONN_IND 0x03 /**< Non connectable undirected. */
/** @} */
/** @defgroup BLE_GAP_ADV_FILTER_POLICIES GAP Advertising filter policies
* @{ */
#define BLE_GAP_ADV_FP_ANY 0x00 /**< Allow scan requests and connect requests from any device. */
#define BLE_GAP_ADV_FP_FILTER_SCANREQ 0x01 /**< Filter scan requests with whitelist. */
#define BLE_GAP_ADV_FP_FILTER_CONNREQ 0x02 /**< Filter connect requests with whitelist. */
#define BLE_GAP_ADV_FP_FILTER_BOTH 0x03 /**< Filter both scan and connect requests with whitelist. */
/** @} */
/** @defgroup BLE_GAP_ADV_TIMEOUT_VALUES GAP Advertising timeout values
* @{ */
#define BLE_GAP_ADV_TIMEOUT_LIMITED_MAX 180 /**< Maximum advertising time in limited discoverable mode (TGAP(lim_adv_timeout) = 180s in spec (Addendum 2)). */
#define BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED 0 /**< Unlimited advertising in general discoverable mode. */
/** @} */
/** @defgroup BLE_GAP_DISC_MODES GAP Discovery modes
* @{ */
#define BLE_GAP_DISC_MODE_NOT_DISCOVERABLE 0x00 /**< Not discoverable discovery Mode. */
#define BLE_GAP_DISC_MODE_LIMITED 0x01 /**< Limited Discovery Mode. */
#define BLE_GAP_DISC_MODE_GENERAL 0x02 /**< General Discovery Mode. */
/** @} */
/** @defgroup BLE_GAP_IO_CAPS GAP IO Capabilities
* @{ */
#define BLE_GAP_IO_CAPS_DISPLAY_ONLY 0x00 /**< Display Only. */
#define BLE_GAP_IO_CAPS_DISPLAY_YESNO 0x01 /**< Display and Yes/No entry. */
#define BLE_GAP_IO_CAPS_KEYBOARD_ONLY 0x02 /**< Keyboard Only. */
#define BLE_GAP_IO_CAPS_NONE 0x03 /**< No I/O capabilities. */
#define BLE_GAP_IO_CAPS_KEYBOARD_DISPLAY 0x04 /**< Keyboard and Display. */
/** @} */
/** @defgroup BLE_GAP_AUTH_KEY_TYPES GAP Authentication Key Types
* @{ */
#define BLE_GAP_AUTH_KEY_TYPE_NONE 0x00 /**< No key (may be used to reject). */
#define BLE_GAP_AUTH_KEY_TYPE_PASSKEY 0x01 /**< 6-digit Passkey. */
#define BLE_GAP_AUTH_KEY_TYPE_OOB 0x02 /**< Out Of Band data. */
/** @} */
/** @defgroup BLE_GAP_SEC_STATUS GAP Security status
* @{ */
#define BLE_GAP_SEC_STATUS_SUCCESS 0x00 /**< Successful parameters. */
#define BLE_GAP_SEC_STATUS_TIMEOUT 0x01 /**< Procedure timed out. */
#define BLE_GAP_SEC_STATUS_PDU_INVALID 0x02 /**< Invalid PDU received. */
#define BLE_GAP_SEC_STATUS_PASSKEY_ENTRY_FAILED 0x81 /**< Passkey entry failed (user cancelled or other). */
#define BLE_GAP_SEC_STATUS_OOB_NOT_AVAILABLE 0x82 /**< Out of Band Key not available. */
#define BLE_GAP_SEC_STATUS_AUTH_REQ 0x83 /**< Authentication requirements not met. */
#define BLE_GAP_SEC_STATUS_CONFIRM_VALUE 0x84 /**< Confirm value failed. */
#define BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP 0x85 /**< Pairing not supported. */
#define BLE_GAP_SEC_STATUS_ENC_KEY_SIZE 0x86 /**< Encryption key size. */
#define BLE_GAP_SEC_STATUS_SMP_CMD_UNSUPPORTED 0x87 /**< Unsupported SMP command. */
#define BLE_GAP_SEC_STATUS_UNSPECIFIED 0x88 /**< Unspecified reason. */
#define BLE_GAP_SEC_STATUS_REPEATED_ATTEMPTS 0x89 /**< Too little time elapsed since last attempt. */
#define BLE_GAP_SEC_STATUS_INVALID_PARAMS 0x8A /**< Invalid parameters. */
/** @} */
/** @defgroup BLE_GAP_SEC_STATUS_SOURCES GAP Security status sources
* @{ */
#define BLE_GAP_SEC_STATUS_SOURCE_LOCAL 0x00 /**< Local failure. */
#define BLE_GAP_SEC_STATUS_SOURCE_REMOTE 0x01 /**< Remote failure. */
/** @} */
/** @defgroup BLE_GAP_CP_LIMITS GAP Connection Parameters Limits
* @{ */
#define BLE_GAP_CP_MIN_CONN_INTVL_NONE 0xFFFF /**< No new minimum connction interval specified in connect parameters. */
#define BLE_GAP_CP_MIN_CONN_INTVL_MIN 0x0006 /**< Lowest mimimum connection interval permitted, in units of 1.25 ms, i.e. 7.5 ms. */
#define BLE_GAP_CP_MIN_CONN_INTVL_MAX 0x0C80 /**< Highest minimum connection interval permitted, in units of 1.25 ms, i.e. 4 s. */
#define BLE_GAP_CP_MAX_CONN_INTVL_NONE 0xFFFF /**< No new maximum connction interval specified in connect parameters. */
#define BLE_GAP_CP_MAX_CONN_INTVL_MIN 0x0006 /**< Lowest maximum connection interval permitted, in units of 1.25 ms, i.e. 7.5 ms. */
#define BLE_GAP_CP_MAX_CONN_INTVL_MAX 0x0C80 /**< Highest maximum connection interval permitted, in units of 1.25 ms, i.e. 4 s. */
#define BLE_GAP_CP_SLAVE_LATENCY_MAX 0x03E8 /**< Highest slave latency permitted, in connection events. */
#define BLE_GAP_CP_CONN_SUP_TIMEOUT_NONE 0xFFFF /**< No new supervision timeout specified in connect parameters. */
#define BLE_GAP_CP_CONN_SUP_TIMEOUT_MIN 0x000A /**< Lowest supervision timeout permitted, in units of 10 ms, i.e. 100 ms. */
#define BLE_GAP_CP_CONN_SUP_TIMEOUT_MAX 0x0C80 /**< Highest supervision timeout permitted, in units of 10 ms, i.e. 32 s. */
/** @} */
/**@brief GAP device name maximum length. */
#define BLE_GAP_DEVNAME_MAX_LEN 31
/** @defgroup BLE_GAP_CONN_SEC_MODE_SET_MACROS GAP attribute security requirement setters
*
* See @ref ble_gap_conn_sec_mode_t.
* @{ */
/** @brief Set sec_mode pointed to by ptr to have no access rights.*/
#define BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(ptr) do {(ptr)->sm = 0; (ptr)->lv = 0;} while(0)
/** @brief Set sec_mode pointed to by ptr to require no protection, open link.*/
#define BLE_GAP_CONN_SEC_MODE_SET_OPEN(ptr) do {(ptr)->sm = 1; (ptr)->lv = 1;} while(0)
/** @brief Set sec_mode pointed to by ptr to require encryption, but no MITM protection.*/
#define BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(ptr) do {(ptr)->sm = 1; (ptr)->lv = 2;} while(0)
/** @brief Set sec_mode pointed to by ptr to require encryption and MITM protection.*/
#define BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(ptr) do {(ptr)->sm = 1; (ptr)->lv = 3;} while(0)
/** @brief Set sec_mode pointed to by ptr to require signing or encryption, no MITM protection needed.*/
#define BLE_GAP_CONN_SEC_MODE_SET_SIGNED_NO_MITM(ptr) do {(ptr)->sm = 2; (ptr)->lv = 1;} while(0)
/** @brief Set sec_mode pointed to by ptr to require signing or encryption with MITM protection.*/
#define BLE_GAP_CONN_SEC_MODE_SET_SIGNED_WITH_MITM(ptr) do {(ptr)->sm = 2; (ptr)->lv = 2;} while(0)
/** @} */
/**@brief GAP Security Key Length. */
#define BLE_GAP_SEC_KEY_LEN 16
/**@brief Maximum amount of addresses in a whitelist. */
#define BLE_GAP_WHITELIST_ADDR_MAX_COUNT (8)
/**@brief Maximum amount of IRKs in a whitelist.
* @note The number of IRKs is limited to 8, even if the hardware supports more.
*/
#define BLE_GAP_WHITELIST_IRK_MAX_COUNT (8)
/** @defgroup GAP_SEC_MODES GAP Security Modes
* @{ */
#define BLE_GAP_SEC_MODE 0x00 /**< No key (may be used to reject). */
/** @} */
/** @} */
/**@brief Bluetooth Low Energy address. */
typedef struct
{
uint8_t addr_type; /**< See @ref BLE_GAP_ADDR_TYPES. */
uint8_t addr[BLE_GAP_ADDR_LEN]; /**< 48-bit address, LSB format. */
} ble_gap_addr_t;
/**@brief GAP connection parameters.
*
* @note When ble_conn_params_t is received in an event, both min_conn_interval and
* max_conn_interval will be equal to the connection interval set by the central.
*/
typedef struct
{
uint16_t min_conn_interval; /**< Minimum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/
uint16_t max_conn_interval; /**< Maximum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/
uint16_t slave_latency; /**< Slave Latency in number of connection events, see @ref BLE_GAP_CP_LIMITS.*/
uint16_t conn_sup_timeout; /**< Connection Supervision Timeout in 10 ms units, see @ref BLE_GAP_CP_LIMITS.*/
} ble_gap_conn_params_t;
/**@brief GAP link requirements.
*
* See Bluetooth Core specification, Volume 3 Part C 10.2 for details.
*
* Security Mode 0 Level 0: No access permissions at all (this level is not defined by the Bluetooth Core specification).\n
* Security Mode 1 Level 1: No security is needed (aka open link).\n
* Security Mode 1 Level 2: Encrypted link required, MITM protection not necessary.\n
* Security Mode 1 Level 3: MITM protected encrypted link required.\n
* Security Mode 2 Level 1: Signing or encryption required, MITM protection not necessary.\n
* Security Mode 2 Level 2: MITM protected signing required, unless link is MITM protected encrypted.\n
*/
typedef struct
{
uint8_t sm : 4; /**< Security Mode (1 or 2), 0 for no permissions at all. */
uint8_t lv : 4; /**< Level (1, 2 or 3), 0 for no permissions at all. */
} ble_gap_conn_sec_mode_t;
/**@brief GAP connection security status.*/
typedef struct
{
ble_gap_conn_sec_mode_t sec_mode; /**< Currently active security mode for this connection.*/
uint8_t encr_key_size; /**< Length of currently active encryption key, 7 to 16 octets.*/
} ble_gap_conn_sec_t;
/**@brief Identity Resolving Key. */
typedef struct
{
uint8_t irk[BLE_GAP_SEC_KEY_LEN]; /**< Array containing IRK. */
} ble_gap_irk_t;
/**@brief Whitelist structure. */
typedef struct
{
ble_gap_addr_t ** pp_addrs; /**< Pointer to array of device address pointers, pointing to addresses to be used in whitelist. NULL if none are given. */
uint8_t addr_count; /**< Count of device addresses in array, up to @ref BLE_GAP_WHITELIST_ADDR_MAX_COUNT. */
ble_gap_irk_t ** pp_irks; /**< Pointer to array of Identity Resolving Key (IRK) pointers, each pointing to an IRK in the whitelist. NULL if none are given. */
uint8_t irk_count; /**< Count of IRKs in array, up to @ref BLE_GAP_WHITELIST_IRK_MAX_COUNT. */
} ble_gap_whitelist_t;
/**@brief GAP advertising parameters.*/
typedef struct
{
uint8_t type; /**< See @ref BLE_GAP_ADV_TYPES. */
ble_gap_addr_t* p_peer_addr; /**< For BLE_GAP_CONN_MODE_DIRECTED mode only, known peer address. */
uint8_t fp; /**< Filter Policy, see @ref BLE_GAP_ADV_FILTER_POLICIES. */
ble_gap_whitelist_t * p_whitelist; /**< Pointer to whitelist, NULL if none is given. */
uint16_t interval; /**< Advertising interval between 0x0020 and 0x4000 in 0.625 ms units (20ms to 10.24s), see @ref BLE_GAP_ADV_INTERVALS. This parameter must be set to 0 if type equals @ref BLE_GAP_ADV_TYPE_ADV_DIRECT_IND. */
uint16_t timeout; /**< Advertising timeout between 0x0001 and 0x3FFF in seconds, 0x0000 disables timeout. See also @ref BLE_GAP_ADV_TIMEOUT_VALUES. This parameter must be set to 0 if type equals @ref BLE_GAP_ADV_TYPE_ADV_DIRECT_IND. */
} ble_gap_adv_params_t;
/**@brief GAP scanning parameters. */
typedef struct
{
uint8_t filter; /**< Filter based on discovery mode, see @ref BLE_GAP_DISC_MODES. */
uint8_t active : 1; /**< If 1, perform active scanning (scan requests). */
uint8_t selective : 1; /**< If 1, ignore unknown devices (non whitelisted). */
uint16_t interval; /**< Scan interval between 0x0020 and 0x4000 in 0.625ms units (20ms to 10.24s). */
uint16_t window; /**< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
uint16_t timeout; /**< Scan timeout between 0x0001 and 0x3FFF in seconds, 0x0000 disables timeout. */
} ble_gap_scan_params_t;
/**@brief GAP security parameters. */
typedef struct
{
uint16_t timeout; /**< Timeout for SMP transactions or Security Request in seconds, see @ref sd_ble_gap_authenticate and @ref sd_ble_gap_sec_params_reply for more information. */
uint8_t bond : 1; /**< Perform bonding. */
uint8_t mitm : 1; /**< Man In The Middle protection required. */
uint8_t io_caps : 3; /**< IO capabilities, see @ref BLE_GAP_IO_CAPS. */
uint8_t oob : 1; /**< Out Of Band data available. */
uint8_t min_key_size; /**< Minimum encryption key size in octets between 7 and 16. */
uint8_t max_key_size; /**< Maximum encryption key size in octets between min_key_size and 16. */
} ble_gap_sec_params_t;
/**@brief GAP Encryption Information. */
typedef struct
{
uint16_t div; /**< Encryption Diversifier. */
uint8_t ltk[BLE_GAP_SEC_KEY_LEN]; /**< Long Term Key. */
uint8_t auth : 1; /**< Authenticated Key. */
uint8_t ltk_len : 7; /**< LTK length in octets. */
} ble_gap_enc_info_t;
/**@brief GAP Master Identification. */
typedef struct
{
uint16_t ediv; /**< Encrypted Diversifier. */
uint8_t rand[8]; /**< Random Number. */
} ble_gap_master_id_t;
/**@brief GAP Identity Information. */
typedef struct
{
ble_gap_addr_t addr; /**< Bluetooth address to which this key applies. */
uint8_t irk[BLE_GAP_SEC_KEY_LEN]; /**< Identity Resolution Key. */
} ble_gap_id_info_t;
/**@brief GAP Signing Information. */
typedef struct
{
uint8_t csrk[BLE_GAP_SEC_KEY_LEN]; /* Connection Signature Resolving Key. */
} ble_gap_sign_info_t;
/**
* @brief GAP Event IDs.
* Those IDs uniquely identify an event coming from the stack to the application.
*/
enum BLE_GAP_EVTS
{
BLE_GAP_EVT_CONNECTED = BLE_GAP_EVT_BASE, /**< Connection established. */
BLE_GAP_EVT_DISCONNECTED, /**< Disconnected from peer. */
BLE_GAP_EVT_CONN_PARAM_UPDATE, /**< Connection Parameters updated. */
BLE_GAP_EVT_SEC_PARAMS_REQUEST, /**< Request to provide security parameters. */
BLE_GAP_EVT_SEC_INFO_REQUEST, /**< Request to provide security information. */
BLE_GAP_EVT_PASSKEY_DISPLAY, /**< Request to display a passkey to the user. */
BLE_GAP_EVT_AUTH_KEY_REQUEST, /**< Request to provide an authentication key. */
BLE_GAP_EVT_AUTH_STATUS, /**< Authentication procedure completed with status. */
BLE_GAP_EVT_CONN_SEC_UPDATE, /**< Connection security updated. */
BLE_GAP_EVT_TIMEOUT, /**< Timeout expired. */
BLE_GAP_EVT_RSSI_CHANGED, /**< Signal strength measurement report. */
};
/** @brief Event data for connected event. */
typedef struct
{
ble_gap_addr_t peer_addr; /**< Bluetooth address of the peer device. */
uint8_t irk_match :1; /**< If 1, peer device's address resolved using an IRK. */
uint8_t irk_match_idx :7; /**< Index in IRK list where the address was matched. */
ble_gap_conn_params_t conn_params; /**< GAP Connection Parameters. */
} ble_gap_evt_connected_t;
/** @brief Event data for disconnected event. */
typedef struct
{
uint8_t reason; /**< HCI error code. */
} ble_gap_evt_disconnected_t;
/** @brief Event data for connection parameter update event. */
typedef struct
{
ble_gap_conn_params_t conn_params; /**< GAP Connection Parameters. */
} ble_gap_evt_conn_param_update_t;
/** @brief Event data for security parameters request event. */
typedef struct
{
ble_gap_sec_params_t peer_params; /**< Initiator Security Parameters. */
} ble_gap_evt_sec_params_request_t;
/** @brief Event data for securito info request event. */
typedef struct
{
ble_gap_addr_t peer_addr; /**< Bluetooth address of the peer device. */
uint16_t div; /**< Encryption diversifier for LTK lookup. */
uint8_t enc_info : 1; /**< If 1, Encryption Information required. */
uint8_t id_info : 1; /**< If 1, Identity Information required. */
uint8_t sign_info : 1; /**< If 1, Signing Information required. */
} ble_gap_evt_sec_info_request_t;
/** @brief Event data for passkey display event. */
typedef struct
{
uint8_t passkey[6]; /**< 6-digit passkey in ASCII ('0'-'9' digits only). */
} ble_gap_evt_passkey_display_t;
/** @brief Event data for authentication key request event. */
typedef struct
{
uint8_t key_type; /**< See @ref BLE_GAP_AUTH_KEY_TYPES. */
} ble_gap_evt_auth_key_request_t;
/** @brief Security levels supported.
* @note See Bluetooth Specification Version 4.0 Volume 3, Chapter 10.
*/
typedef struct
{
uint8_t lv1 : 1; /**< If 1: Level 1 is supported. */
uint8_t lv2 : 1; /**< If 1: Level 2 is supported. */
uint8_t lv3 : 1; /**< If 1: Level 3 is supported. */
} ble_gap_sec_levels_t;
/** @brief Keys that have been exchanged. */
typedef struct
{
uint8_t ltk : 1; /**< Long Term Key. */
uint8_t ediv_rand : 1; /**< Encrypted Diversifier and Random value. */
uint8_t irk : 1; /**< Identity Resolving Key. */
uint8_t address : 1; /**< Public or static random address. */
uint8_t csrk : 1; /**< Connection Signature Resolving Key. */
} ble_gap_sec_keys_t;
/** @brief Event data for authentication status event. */
typedef struct
{
uint8_t auth_status; /**< Authentication status, see @ref BLE_GAP_SEC_STATUS. */
uint8_t error_src; /**< On error, source that caused the failure, see @ref BLE_GAP_SEC_STATUS_SOURCES. */
ble_gap_sec_levels_t sm1_levels; /**< Levels supported in Security Mode 1. */
ble_gap_sec_levels_t sm2_levels; /**< Levels supported in Security Mode 2. */
ble_gap_sec_keys_t periph_kex; /**< Bitmap stating which keys were exchanged (distributed) by the peripheral. */
ble_gap_sec_keys_t central_kex; /**< Bitmap stating which keys were exchanged (distributed) by the central. */
struct periph_keys_t
{
ble_gap_enc_info_t enc_info; /**< Peripheral's Encryption information. */
} periph_keys; /**< Actual keys distributed from the Peripheral to the Central. */
struct central_keys_t
{
ble_gap_irk_t irk; /**< Central's IRK. */
ble_gap_addr_t id_info; /**< Central's Identity Info. */
} central_keys; /**< Actual keys distributed from the Central to the Peripheral. */
} ble_gap_evt_auth_status_t;
/** @brief Event data for connection security update event. */
typedef struct
{
ble_gap_conn_sec_t conn_sec; /**< Connection security level. */
} ble_gap_evt_conn_sec_update_t;
/** @brief Event data for timeout event. */
typedef struct
{
uint8_t src; /**< Source of timeout event, see @ref BLE_GAP_TIMEOUT_SOURCES. */
} ble_gap_evt_timeout_t;
/** @brief Event data for advertisement report event. */
typedef struct
{
int8_t rssi; /**< Received Signal Strength Indication in dBm. */
} ble_gap_evt_rssi_changed_t;
/**@brief GAP event callback event structure. */
typedef struct
{
uint16_t conn_handle; /**< Connection Handle on which event occured. */
union /**< union alternative identified by evt_id in enclosing struct. */
{
ble_gap_evt_connected_t connected; /**< Connected Event Parameters. */
ble_gap_evt_disconnected_t disconnected; /**< Disconnected Event Parameters. */
ble_gap_evt_conn_param_update_t conn_param_update; /**< Connection Parameter Update Parameters. */
ble_gap_evt_sec_params_request_t sec_params_request; /**< Security Parameters Request Event Parameters. */
ble_gap_evt_sec_info_request_t sec_info_request; /**< Security Information Request Event Parameters. */
ble_gap_evt_passkey_display_t passkey_display; /**< Passkey Display Event Parameters. */
ble_gap_evt_auth_key_request_t auth_key_request; /**< Authentication Key Request Event Parameters. */
ble_gap_evt_auth_status_t auth_status; /**< Authentication Status Event Parameters. */
ble_gap_evt_conn_sec_update_t conn_sec_update; /**< Connection Security Update Event Parameters. */
ble_gap_evt_timeout_t timeout; /**< Timeout Event Parameters. */
ble_gap_evt_rssi_changed_t rssi_changed; /**< RSSI Event parameters. */
} params;
} ble_gap_evt_t;
/**@brief Set local Bluetooth address.
*
* @param[in] p_addr Pointer to address structure.
*
* @return @ref NRF_SUCCESS Address successfully set.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref BLE_ERROR_GAP_INVALID_BLE_ADDR Invalid address.
* @return @ref NRF_ERROR_BUSY The stack is busy, process pending events and retry.
*/
SVCALL(SD_BLE_GAP_ADDRESS_SET, uint32_t, sd_ble_gap_address_set(ble_gap_addr_t const * const p_addr));
/**@brief Get local Bluetooth address.
*
* @param[out] p_addr Pointer to address structure.
*
* @return @ref NRF_SUCCESS Address successfully retrieved.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
*/
SVCALL(SD_BLE_GAP_ADDRESS_GET, uint32_t, sd_ble_gap_address_get(ble_gap_addr_t * const p_addr));
/**@brief Set, clear or update advertisement and scan response data.
*
* @note The format of the advertisement data will be checked by this call to ensure interoperability.
* Limitations imposed by this API call to the data provided include having a flags data type in the scan response data and
* duplicating the local name in the advertisement data and scan response data.
*
* @note: To clear the advertisement data and set it to a 0-length packet, simply provide a valid pointer (p_data/p_sr_data) with its corresponding
* length (dlen/srdlen) set to 0.
*
* @note: The call will fail if p_data and p_sr_data are both NULL since this would have no effect.
*
* @param[in] p_data Raw data to be placed in advertisement packet. If NULL, no changes are made to the current advertisement packet data.
* @param[in] dlen Data length for p_data. Max size: @ref BLE_GAP_ADV_MAX_SIZE octets. Should be 0 if p_data is NULL, can be 0 if p_data is not NULL.
* @param[in] p_sr_data Raw data to be placed in scan response packet. If NULL, no changes are made to the current scan response packet data.
* @param[in] srdlen Data length for p_sr_data. Max size: @ref BLE_GAP_ADV_MAX_SIZE octets. Should be 0 if p_sr_data is NULL, can be 0 if p_data is not NULL.
*
* @return @ref NRF_SUCCESS Advertisement data successfully updated or cleared.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_INVALID_FLAGS Invalid combination of advertising flags supplied.
* @return @ref NRF_ERROR_INVALID_DATA Invalid data type(s) supplied, check the advertising data format specification.
* @return @ref NRF_ERROR_INVALID_LENGTH Invalid data length(s) supplied.
* @return @ref BLE_ERROR_GAP_UUID_LIST_MISMATCH Invalid UUID list supplied.
* @return @ref NRF_ERROR_BUSY The stack is busy, process pending events and retry.
*/
SVCALL(SD_BLE_GAP_ADV_DATA_SET, uint32_t, sd_ble_gap_adv_data_set(uint8_t const * const p_data, uint8_t dlen, uint8_t const * const p_sr_data, uint8_t srdlen));
/**@brief Start advertising (GAP Discoverable, Connectable modes, Broadcast Procedure).
*
* @param[in] p_adv_params Pointer to advertising parameters structure.
*
* @return @ref NRF_SUCCESS The BLE stack has started advertising.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, check the accepted ranges and limits.
* @return @ref BLE_ERROR_GAP_INVALID_BLE_ADDR Invalid Bluetooth address supplied.
* @return @ref BLE_ERROR_GAP_DISCOVERABLE_WITH_WHITELIST Discoverable mode and whitelist incompatible.
*/
SVCALL(SD_BLE_GAP_ADV_START, uint32_t, sd_ble_gap_adv_start(ble_gap_adv_params_t const * const p_adv_params));
/**@brief Stop advertising (GAP Discoverable, Connectable modes, Broadcast Procedure).
*
* @return @ref NRF_SUCCESS The BLE stack has stopped advertising.
* @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation (most probably not in advertising state).
*/
SVCALL(SD_BLE_GAP_ADV_STOP, uint32_t, sd_ble_gap_adv_stop(void));
/**@brief Update connection parameters.
*
* @details In the central role this will initiate a Link Layer connection parameter update procedure,
* otherwise in the peripheral role, this will send the corresponding L2CAP request and wait for
* the central to perform the procedure. In both cases, and regardless of success or failure, the application
* will be informed of the result with a @ref BLE_GAP_EVT_CONN_PARAM_UPDATE event.
*
* @note If both a connection supervision timeout and a maximum connection interval are specified, then the following constraint
* applies: (conn_sup_timeout * 8) >= (max_conn_interval * (slave_latency + 1))
*
* @param[in] conn_handle Connection handle.
* @param[in] p_conn_params Pointer to desired connection parameters. If NULL is provided on a peripheral role,
* the parameters in the PPCP characteristic of the GAP service will be used instead.
*
* @return @ref NRF_SUCCESS The Connection Update procedure has been started successfully.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, check parameter limits and constraints.
* @return @ref NRF_ERROR_BUSY Procedure already in progress or not allowed at this time, process pending events and retry.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
* @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
*/
SVCALL(SD_BLE_GAP_CONN_PARAM_UPDATE, uint32_t, sd_ble_gap_conn_param_update(uint16_t conn_handle, ble_gap_conn_params_t const * const p_conn_params));
/**@brief Disconnect (GAP Link Termination).
*
* @details This call initiates the disconnection procedure, and its completion will be communicated to the application
* with a BLE_GAP_EVT_DISCONNECTED event.
*
* @param[in] conn_handle Connection handle.
* @param[in] hci_status_code HCI status code, see @ref BLE_HCI_STATUS_CODES (accepted values are BTLE_REMOTE_USER_TERMINATED_CONNECTION and BTLE_CONN_INTERVAL_UNACCEPTABLE).
*
* @return @ref NRF_SUCCESS The disconnection procedure has been started successfully.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
* @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation (disconnection is already in progress or not connected at all).
*/
SVCALL(SD_BLE_GAP_DISCONNECT, uint32_t, sd_ble_gap_disconnect(uint16_t conn_handle, uint8_t hci_status_code));
/**@brief Set the radio's transmit power.
*
* @param[in] tx_power Radio transmit power in dBm (accepted values are -40, -30, -20, -16, -12, -8, -4, 0, and 4 dBm).
*
* @note -40 dBm will not actually give -40 dBm, but will instead be remapped to -30 dBm.
*
* @return @ref NRF_SUCCESS Successfully changed the transmit power.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
* @return @ref NRF_ERROR_BUSY The stack is busy, process pending events and retry.
*/
SVCALL(SD_BLE_GAP_TX_POWER_SET, uint32_t, sd_ble_gap_tx_power_set(int8_t tx_power));
/**@brief Set GAP Appearance value.
*
* @param[in] appearance Appearance (16-bit), see @ref BLE_APPEARANCES.
*
* @return @ref NRF_SUCCESS Appearance value set successfully.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
*/
SVCALL(SD_BLE_GAP_APPEARANCE_SET, uint32_t, sd_ble_gap_appearance_set(uint16_t appearance));
/**@brief Get GAP Appearance value.
*
* @param[out] p_appearance Appearance (16-bit), see @ref BLE_APPEARANCES.
*
* @return @ref NRF_SUCCESS Appearance value retrieved successfully.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
*/
SVCALL(SD_BLE_GAP_APPEARANCE_GET, uint32_t, sd_ble_gap_appearance_get(uint16_t * const p_appearance));
/**@brief Set GAP Peripheral Preferred Connection Parameters.
*
* @param[in] p_conn_params Pointer to a @ref ble_gap_conn_params_t structure with the desired parameters.
*
* @return @ref NRF_SUCCESS Peripheral Preferred Connection Parameters set successfully.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
*/
SVCALL(SD_BLE_GAP_PPCP_SET, uint32_t, sd_ble_gap_ppcp_set(ble_gap_conn_params_t const * const p_conn_params));
/**@brief Get GAP Peripheral Preferred Connection Parameters.
*
* @param[out] p_conn_params Pointer to a @ref ble_gap_conn_params_t structure where the parameters will be stored.
*
* @return @ref NRF_SUCCESS Peripheral Preferred Connection Parameters retrieved successfully.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
*/
SVCALL(SD_BLE_GAP_PPCP_GET, uint32_t, sd_ble_gap_ppcp_get(ble_gap_conn_params_t * const p_conn_params));
/**@brief Set GAP device name.
*
* @param[in] p_write_perm Write permissions for the Device Name characteristic see @ref ble_gap_conn_sec_mode_t.
* @param[in] p_dev_name Pointer to a UTF-8 encoded, <b>non NULL-terminated</b> string.
* @param[in] len Length of the UTF-8, <b>non NULL-terminated</b> string pointed to by p_dev_name in octets (must be smaller or equal than @ref BLE_GAP_DEVNAME_MAX_LEN).
*
* @return @ref NRF_SUCCESS GAP device name and permissions set successfully.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
* @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
*/
SVCALL(SD_BLE_GAP_DEVICE_NAME_SET, uint32_t, sd_ble_gap_device_name_set(ble_gap_conn_sec_mode_t const * const p_write_perm, uint8_t const * const p_dev_name, uint16_t len));
/**@brief Get GAP device name.
*
* @param[in] p_dev_name Pointer to an empty buffer where the UTF-8 <b>non NULL-terminated</b> string will be placed. Set to NULL to obtain the complete device name length.
* @param[in,out] p_len Length of the buffer pointed by p_dev_name, complete device name length on output.
*
* @note If the device name is longer than the size of the supplied buffer,
* p_len will return the complete device name length,
* and not the number of bytes actually returned in p_dev_name.
* The application may use this information to allocate a suitable buffer size.
*
* @return @ref NRF_SUCCESS GAP device name retrieved successfully.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
*/
SVCALL(SD_BLE_GAP_DEVICE_NAME_GET, uint32_t, sd_ble_gap_device_name_get(uint8_t * const p_dev_name, uint16_t * const p_len));
/**@brief Initiate GAP Authentication procedure.
*
* @param[in] conn_handle Connection handle.
* @param[in] p_sec_params Pointer to the @ref ble_gap_sec_params_t structure with the security parameters to be used during the pairing procedure.
*
* @details In the central role, this function will send an SMP Pairing Request, otherwise in the peripheral role, an SMP Security Request will be sent.
* In the peripheral role, only the timeout, bond and mitm fields of @ref ble_gap_sec_params_t are used.
*
* @note The GAP Authentication procedure may be triggered by the central without calling this function when accessing a secure service.
* @note Calling this function may result in the following events depending on the outcome and parameters: @ref BLE_GAP_EVT_SEC_PARAMS_REQUEST,
* @ref BLE_GAP_EVT_SEC_INFO_REQUEST, @ref BLE_GAP_EVT_AUTH_KEY_REQUEST, @ref BLE_GAP_EVT_AUTH_STATUS.
* @note The timeout parameter in @ref ble_gap_sec_params_t is interpreted here as the Security Request timeout
*
*
* @return @ref NRF_SUCCESS Successfully initiated authentication procedure.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
* @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
*/
SVCALL(SD_BLE_GAP_AUTHENTICATE, uint32_t, sd_ble_gap_authenticate(uint16_t conn_handle, ble_gap_sec_params_t const * const p_sec_params));
/**@brief Reply with GAP security parameters.
*
* @param[in] conn_handle Connection handle.
* @param[in] sec_status Security status, see @ref BLE_GAP_SEC_STATUS.
* @param[in] p_sec_params Pointer to a @ref ble_gap_sec_params_t security parameters structure.
*
* @details This function is only used to reply to a @ref BLE_GAP_EVT_SEC_PARAMS_REQUEST, calling it at other times will result in an NRF_ERROR_INVALID_STATE.
* @note If the call returns an error code, the request is still pending, and the reply call may be repeated with corrected parameters.
* @note The timeout parameter in @ref ble_gap_sec_params_t is interpreted here as the SMP procedure timeout, and must be 30 seconds. The function will fail
* if the application supplies a different value.
*
* @return @ref NRF_SUCCESS Successfully accepted security parameter from the application.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
* @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
*/
SVCALL(SD_BLE_GAP_SEC_PARAMS_REPLY, uint32_t, sd_ble_gap_sec_params_reply(uint16_t conn_handle, uint8_t sec_status, ble_gap_sec_params_t const * const p_sec_params));
/**@brief Reply with an authentication key.
*
* @param[in] conn_handle Connection handle.
* @param[in] key_type See @ref BLE_GAP_AUTH_KEY_TYPES.
* @param[in] key If key type is BLE_GAP_AUTH_KEY_TYPE_NONE, then NULL.
* If key type is BLE_GAP_AUTH_KEY_TYPE_PASSKEY, then a 6-byte ASCII string (digit 0..9 only, no NULL termination).
* If key type is BLE_GAP_AUTH_KEY_TYPE_OOB, then a 16-byte OOB key value in Little Endian format.
*
* @details This function is only used to reply to a @ref BLE_GAP_EVT_AUTH_KEY_REQUEST, calling it at other times will result in an NRF_ERROR_INVALID_STATE.
* @note If the call returns an error code, the request is still pending, and the reply call may be repeated with corrected parameters.
*
* @return @ref NRF_SUCCESS Authentication key successfully set.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
* @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
*/
SVCALL(SD_BLE_GAP_AUTH_KEY_REPLY, uint32_t, sd_ble_gap_auth_key_reply(uint16_t conn_handle, uint8_t key_type, uint8_t const * const key));
/**@brief Reply with GAP security information.
*
* @param[in] conn_handle Connection handle.
* @param[in] p_enc_info Pointer to a @ref ble_gap_enc_info_t encryption information structure. May be NULL to signal none is available.
* @param[in] p_sign_info Pointer to a @ref ble_gap_sign_info_t signing information structure. May be NULL to signal none is available.
*
* @details This function is only used to reply to a @ref BLE_GAP_EVT_SEC_INFO_REQUEST, calling it at other times will result in NRF_ERROR_INVALID_STATE.
* @note If the call returns an error code, the request is still pending, and the reply call may be repeated with corrected parameters.
* @note Data signing is not implemented yet. p_sign_info must therefore be NULL.
*
* @return @ref NRF_SUCCESS Successfully accepted security information.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
* @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
* @return @ref NRF_ERROR_BUSY The stack is busy, process pending events and retry.
*/
SVCALL(SD_BLE_GAP_SEC_INFO_REPLY, uint32_t, sd_ble_gap_sec_info_reply(uint16_t conn_handle, ble_gap_enc_info_t const * const p_enc_info, ble_gap_sign_info_t const * const p_sign_info));
/**@brief Get the current connection security.
*
* @param[in] conn_handle Connection handle.
* @param[out] p_conn_sec Pointer to a @ref ble_gap_conn_sec_t structure to be filled in.
*
* @return @ref NRF_SUCCESS Current connection security successfully retrieved.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
*/
SVCALL(SD_BLE_GAP_CONN_SEC_GET, uint32_t, sd_ble_gap_conn_sec_get(uint16_t conn_handle, ble_gap_conn_sec_t * const p_conn_sec));
/**@brief Start reporting the received signal strength to the application.
*
* A new event is reported whenever the RSSI value changes, until @ref sd_ble_gap_rssi_stop is called.
*
* @param[in] conn_handle Connection handle.
*
* @return @ref NRF_SUCCESS Successfully activated RSSI reporting.
* @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
*/
SVCALL(SD_BLE_GAP_RSSI_START, uint32_t, sd_ble_gap_rssi_start(uint16_t conn_handle));
/**@brief Stop reporting the received singnal strength.
*
* An RSSI change detected before the call but not yet received by the application
* may be reported after @ref sd_ble_gap_rssi_stop has been called.
*
* @param[in] conn_handle Connection handle.
*
* @return @ref NRF_SUCCESS Successfully deactivated RSSI reporting.
* @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
*/
SVCALL(SD_BLE_GAP_RSSI_STOP, uint32_t, sd_ble_gap_rssi_stop(uint16_t conn_handle));
#endif // BLE_GAP_H__
/**
@}
*/

View File

@ -0,0 +1,166 @@
/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is confidential property of Nordic Semiconductor. The use,
* copying, transfer or disclosure of such information is prohibited except by express written
* agreement with Nordic Semiconductor.
*
*/
/**
@addtogroup BLE_GATT Generic Attribute Profile (GATT) Common
@{
@brief Common definitions and prototypes for the GATT interfaces.
*/
#ifndef BLE_GATT_H__
#define BLE_GATT_H__
#include "ble_types.h"
#include "ble_ranges.h"
/** @addtogroup BLE_GATT_DEFINES Defines
* @{ */
/** @brief Default MTU size. */
#define GATT_MTU_SIZE_DEFAULT 23
/** @brief Only the default MTU size of 23 is currently supported. */
#define GATT_RX_MTU 23
/**@brief Invalid Attribute Handle. */
#define BLE_GATT_HANDLE_INVALID 0x0000
/** @defgroup BLE_GATT_TIMEOUT_SOURCES GATT Timeout sources
* @{ */
#define BLE_GATT_TIMEOUT_SRC_PROTOCOL 0x00 /**< ATT Protocol timeout. */
/** @} */
/** @defgroup BLE_GATT_WRITE_OPS GATT Write operations
* @{ */
#define BLE_GATT_OP_INVALID 0x00 /**< Invalid Operation. */
#define BLE_GATT_OP_WRITE_REQ 0x01 /**< Write Request. */
#define BLE_GATT_OP_WRITE_CMD 0x02 /**< Write Command. */
#define BLE_GATT_OP_SIGN_WRITE_CMD 0x03 /**< Signed Write Command. */
#define BLE_GATT_OP_PREP_WRITE_REQ 0x04 /**< Prepare Write Request. */
#define BLE_GATT_OP_EXEC_WRITE_REQ 0x05 /**< Execute Write Request. */
/** @} */
/** @defgroup BLE_GATT_EXEC_WRITE_FLAGS GATT Execute Write flags
* @{ */
#define BLE_GATT_EXEC_WRITE_FLAG_PREPARED_CANCEL 0x00
#define BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE 0x01
/** @} */
/** @defgroup BLE_GATT_HVX_TYPES GATT Handle Value operations
* @{ */
#define BLE_GATT_HVX_INVALID 0x00 /**< Invalid Operation. */
#define BLE_GATT_HVX_NOTIFICATION 0x01 /**< Handle Value Notification. */
#define BLE_GATT_HVX_INDICATION 0x02 /**< Handle Value Indication. */
/** @} */
/** @defgroup BLE_GATT_STATUS_CODES GATT Status Codes
* @{ */
#define BLE_GATT_STATUS_SUCCESS 0x0000 /**< Success. */
#define BLE_GATT_STATUS_UNKNOWN 0x0001 /**< Unknown or not applicable status. */
#define BLE_GATT_STATUS_ATTERR_INVALID 0x0100 /**< ATT Error: Invalid Error Code. */
#define BLE_GATT_STATUS_ATTERR_INVALID_HANDLE 0x0101 /**< ATT Error: Invalid Attribute Handle. */
#define BLE_GATT_STATUS_ATTERR_READ_NOT_PERMITTED 0x0102 /**< ATT Error: Read not permitted. */
#define BLE_GATT_STATUS_ATTERR_WRITE_NOT_PERMITTED 0x0103 /**< ATT Error: Write not permitted. */
#define BLE_GATT_STATUS_ATTERR_INVALID_PDU 0x0104 /**< ATT Error: Used in ATT as Invalid PDU. */
#define BLE_GATT_STATUS_ATTERR_INSUF_AUTHENTICATION 0x0105 /**< ATT Error: Authenticated link required. */
#define BLE_GATT_STATUS_ATTERR_REQUEST_NOT_SUPPORTED 0x0106 /**< ATT Error: Used in ATT as Request Not Supported. */
#define BLE_GATT_STATUS_ATTERR_INVALID_OFFSET 0x0107 /**< ATT Error: Offset specified was past the end of the attribute. */
#define BLE_GATT_STATUS_ATTERR_INSUF_AUTHORIZATION 0x0108 /**< ATT Error: Used in ATT as Insufficient Authorisation. */
#define BLE_GATT_STATUS_ATTERR_PREPARE_QUEUE_FULL 0x0109 /**< ATT Error: Used in ATT as Prepare Queue Full. */
#define BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND 0x010A /**< ATT Error: Used in ATT as Attribute not found. */
#define BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_LONG 0x010B /**< ATT Error: Attribute cannot be read or written using read/write blob requests. */
#define BLE_GATT_STATUS_ATTERR_INSUF_ENC_KEY_SIZE 0x010C /**< ATT Error: Encryption key size used is insufficient. */
#define BLE_GATT_STATUS_ATTERR_INVALID_ATT_VAL_LENGTH 0x010D /**< ATT Error: Invalid value size. */
#define BLE_GATT_STATUS_ATTERR_UNLIKELY_ERROR 0x010E /**< ATT Error: Very unlikely error. */
#define BLE_GATT_STATUS_ATTERR_INSUF_ENCRYPTION 0x010F /**< ATT Error: Encrypted link required. */
#define BLE_GATT_STATUS_ATTERR_UNSUPPORTED_GROUP_TYPE 0x0110 /**< ATT Error: Attribute type is not a supported grouping attribute. */
#define BLE_GATT_STATUS_ATTERR_INSUF_RESOURCES 0x0111 /**< ATT Error: Encrypted link required. */
#define BLE_GATT_STATUS_ATTERR_RFU_RANGE1_BEGIN 0x0112 /**< ATT Error: Reserved for Future Use range #1 begin. */
#define BLE_GATT_STATUS_ATTERR_RFU_RANGE1_END 0x017F /**< ATT Error: Reserved for Future Use range #1 end. */
#define BLE_GATT_STATUS_ATTERR_APP_BEGIN 0x0180 /**< ATT Error: Application range begin. */
#define BLE_GATT_STATUS_ATTERR_APP_END 0x019F /**< ATT Error: Application range end. */
#define BLE_GATT_STATUS_ATTERR_RFU_RANGE2_BEGIN 0x01A0 /**< ATT Error: Reserved for Future Use range #2 begin. */
#define BLE_GATT_STATUS_ATTERR_RFU_RANGE2_END 0x01DF /**< ATT Error: Reserved for Future Use range #2 end. */
#define BLE_GATT_STATUS_ATTERR_RFU_RANGE3_BEGIN 0x01E0 /**< ATT Error: Reserved for Future Use range #3 begin. */
#define BLE_GATT_STATUS_ATTERR_RFU_RANGE3_END 0x01FC /**< ATT Error: Reserved for Future Use range #3 end. */
#define BLE_GATT_STATUS_ATTERR_CPS_CCCD_CONFIG_ERROR 0x01FD /**< ATT Common Profile and Service Error: Client Characteristic Configuration Descriptor improperly configured. */
#define BLE_GATT_STATUS_ATTERR_CPS_PROC_ALR_IN_PROG 0x01FE /**< ATT Common Profile and Service Error: Procedure Already in Progress. */
#define BLE_GATT_STATUS_ATTERR_CPS_OUT_OF_RANGE 0x01FF /**< ATT Common Profile and Service Error: Out Of Range. */
/** @} */
/** @defgroup BLE_GATT_CPF_FORMATS Characteristic Presentation Formats
* @note Found at http://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml
* @{ */
#define BLE_GATT_CPF_FORMAT_RFU 0x00 /**< Reserved For Future Use. */
#define BLE_GATT_CPF_FORMAT_BOOLEAN 0x01 /**< Boolean. */
#define BLE_GATT_CPF_FORMAT_2BIT 0x02 /**< Unsigned 2-bit integer. */
#define BLE_GATT_CPF_FORMAT_NIBBLE 0x03 /**< Unsigned 4-bit integer. */
#define BLE_GATT_CPF_FORMAT_UINT8 0x04 /**< Unsigned 8-bit integer. */
#define BLE_GATT_CPF_FORMAT_UINT12 0x05 /**< Unsigned 12-bit integer. */
#define BLE_GATT_CPF_FORMAT_UINT16 0x06 /**< Unsigned 16-bit integer. */
#define BLE_GATT_CPF_FORMAT_UINT24 0x07 /**< Unsigned 24-bit integer. */
#define BLE_GATT_CPF_FORMAT_UINT32 0x08 /**< Unsigned 32-bit integer. */
#define BLE_GATT_CPF_FORMAT_UINT48 0x09 /**< Unsigned 48-bit integer. */
#define BLE_GATT_CPF_FORMAT_UINT64 0x0A /**< Unsigned 64-bit integer. */
#define BLE_GATT_CPF_FORMAT_UINT128 0x0B /**< Unsigned 128-bit integer. */
#define BLE_GATT_CPF_FORMAT_SINT8 0x0C /**< Signed 2-bit integer. */
#define BLE_GATT_CPF_FORMAT_SINT12 0x0D /**< Signed 12-bit integer. */
#define BLE_GATT_CPF_FORMAT_SINT16 0x0E /**< Signed 16-bit integer. */
#define BLE_GATT_CPF_FORMAT_SINT24 0x0F /**< Signed 24-bit integer. */
#define BLE_GATT_CPF_FORMAT_SINT32 0x10 /**< Signed 32-bit integer. */
#define BLE_GATT_CPF_FORMAT_SINT48 0x11 /**< Signed 48-bit integer. */
#define BLE_GATT_CPF_FORMAT_SINT64 0x12 /**< Signed 64-bit integer. */
#define BLE_GATT_CPF_FORMAT_SINT128 0x13 /**< Signed 128-bit integer. */
#define BLE_GATT_CPF_FORMAT_FLOAT32 0x14 /**< IEEE-754 32-bit floating point. */
#define BLE_GATT_CPF_FORMAT_FLOAT64 0x15 /**< IEEE-754 64-bit floating point. */
#define BLE_GATT_CPF_FORMAT_SFLOAT 0x16 /**< IEEE-11073 16-bit SFLOAT. */
#define BLE_GATT_CPF_FORMAT_FLOAT 0x17 /**< IEEE-11073 32-bit FLOAT. */
#define BLE_GATT_CPF_FORMAT_DUINT16 0x18 /**< IEEE-20601 format. */
#define BLE_GATT_CPF_FORMAT_UTF8S 0x19 /**< UTF-8 string. */
#define BLE_GATT_CPF_FORMAT_UTF16S 0x1A /**< UTF-16 string. */
#define BLE_GATT_CPF_FORMAT_STRUCT 0x1B /**< Opaque Structure. */
/** @} */
/** @defgroup BLE_GATT_CPF_NAMESPACES GATT Bluetooth Namespaces
* @{
*/
#define BLE_GATT_CPF_NAMESPACE_BTSIG 0x01
#define BLE_GATT_CPF_NAMESPACE_DESCRIPTION_UNKNOWN 0x0000
/** @} */
/** @} */
/**@brief GATT Characteristic Properties. */
typedef struct
{
/* Standard properties */
uint8_t broadcast :1; /**< Broadcasting of value permitted. */
uint8_t read :1; /**< Reading value permitted. */
uint8_t write_wo_resp :1; /**< Writing value with Write Command permitted. */
uint8_t write :1; /**< Writing value with Write Request permitted. */
uint8_t notify :1; /**< Notications of value permitted. */
uint8_t indicate :1; /**< Indications of value permitted. */
uint8_t auth_signed_wr :1; /**< Writing value with Signed Write Command permitted. */
} ble_gatt_char_props_t;
/**@brief GATT Characteristic Extended Properties. */
typedef struct
{
/* Extended properties */
uint8_t reliable_wr :1; /**< Writing value with Queued Write Request permitted. */
uint8_t wr_aux :1; /**< Writing the Characteristic User Description permitted. */
} ble_gatt_char_ext_props_t;
#endif // BLE_GATT_H__
/**
@}
@}
*/

View File

@ -0,0 +1,395 @@
/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is confidential property of Nordic Semiconductor. The use,
* copying, transfer or disclosure of such information is prohibited except by express written
* agreement with Nordic Semiconductor.
*
*/
/**
@addtogroup BLE_GATTC Generic Attribute Profile (GATT) Client
@{
@brief Definitions and prototypes for the GATT Client interface.
*/
#ifndef BLE_GATTC_H__
#define BLE_GATTC_H__
#include "ble_gatt.h"
#include "ble_types.h"
#include "ble_ranges.h"
#include "nrf_svc.h"
/**@brief GATTC API SVC numbers. */
enum BLE_GATTC_SVCS
{
SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER = BLE_GATTC_SVC_BASE, /**< Primary Service Discovery. */
SD_BLE_GATTC_RELATIONSHIPS_DISCOVER, /**< Relationship Discovery. */
SD_BLE_GATTC_CHARACTERISTICS_DISCOVER, /**< Characteristic Discovery. */
SD_BLE_GATTC_DESCRIPTORS_DISCOVER, /**< Characteristic Descriptor Discovery. */
SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ, /**< Read Characteristic Value by UUID. */
SD_BLE_GATTC_READ, /**< Generic read. */
SD_BLE_GATTC_CHAR_VALUES_READ, /**< Read multiple Characteristic Values. */
SD_BLE_GATTC_WRITE, /**< Generic write. */
SD_BLE_GATTC_HV_CONFIRM /**< Handle Value Confirmation. */
};
/** @addtogroup BLE_GATTC_DEFINES Defines
* @{ */
/** @defgroup BLE_ERRORS_GATTC SVC return values specific to GATTC
* @{ */
#define BLE_ERROR_GATTC_PROC_NOT_PERMITTED (NRF_GATTC_ERR_BASE + 0x000)
/** @} */
/**@brief Last Attribute Handle. */
#define BLE_GATTC_HANDLE_END 0xFFFF
/** @} */
/**@brief Operation Handle Range. */
typedef struct
{
uint16_t start_handle; /**< Start Handle. */
uint16_t end_handle; /**< End Handle. */
} ble_gattc_handle_range_t;
/**@brief GATT service. */
typedef struct
{
ble_uuid_t uuid; /**< Service UUID. */
ble_gattc_handle_range_t handle_range; /**< Service Handle Range. */
} ble_gattc_service_t;
/**@brief GATT include. */
typedef struct
{
uint16_t handle; /**< Include Handle. */
ble_gattc_service_t included_srvc; /**< Handle of the included service. */
} ble_gattc_include_t;
/**@brief GATT characteristic. */
typedef struct
{
ble_uuid_t uuid; /**< Characteristic UUID. */
ble_gatt_char_props_t char_props; /**< Characteristic Properties. */
uint8_t char_ext_props : 1; /**< Extended properties present. */
uint16_t handle_decl; /**< Handle of the Characteristic Declaration. */
uint16_t handle_value; /**< Handle of the Characteristic Value. */
} ble_gattc_char_t;
/**@brief GATT descriptor. */
typedef struct
{
uint16_t handle; /**< Descriptor Handle. */
ble_uuid_t uuid; /**< Descriptor UUID. */
} ble_gattc_desc_t;
/**@brief Write Parameters. */
typedef struct
{
uint8_t write_op; /**< Write Operation to be performed, see BLE_GATT_WRITE_OPS. */
uint16_t handle; /**< Handle to the attribute to be written. */
uint16_t offset; /**< Offset in bytes. */
uint16_t len; /**< Length of data in bytes. */
uint8_t* p_value; /**< Pointer to the value data. */
uint8_t flags; /**< Flags, see @ref BLE_GATT_EXEC_WRITE_FLAGS. */
} ble_gattc_write_params_t;
/**
* @brief GATT Client Event IDs.
*/
enum BLE_GATTC_EVTS
{
BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP = BLE_GATTC_EVT_BASE, /**< Primary Service Discovery Response event. */
BLE_GATTC_EVT_REL_DISC_RSP, /**< Relationship Discovery Response event. */
BLE_GATTC_EVT_CHAR_DISC_RSP, /**< Characteristic Discovery Response event. */
BLE_GATTC_EVT_DESC_DISC_RSP, /**< Descriptor Discovery Response event. */
BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP, /**< Read By UUID Response event. */
BLE_GATTC_EVT_READ_RSP, /**< Read Response event. */
BLE_GATTC_EVT_CHAR_VALS_READ_RSP, /**< Read multiple Response event. */
BLE_GATTC_EVT_WRITE_RSP, /**< Write Response event. */
BLE_GATTC_EVT_HVX, /**< Handle Value Notification or Indication event. */
BLE_GATTC_EVT_TIMEOUT /**< Timeout event. */
};
/**@brief Event structure for BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP. */
typedef struct
{
uint16_t count; /**< Service count. */
ble_gattc_service_t services[1]; /**< Service data, variable length. */
} ble_gattc_evt_prim_srvc_disc_rsp_t;
/**@brief Event structure for BLE_GATTC_EVT_REL_DISC_RSP. */
typedef struct
{
uint16_t count; /**< Include count. */
ble_gattc_include_t includes[1]; /**< Include data, variable length. */
} ble_gattc_evt_rel_disc_rsp_t;
/**@brief Event structure for BLE_GATTC_EVT_CHAR_DISC_RSP. */
typedef struct
{
uint16_t count; /**< Characteristic count. */
ble_gattc_char_t chars[1]; /**< Characteristic data, variable length. */
} ble_gattc_evt_char_disc_rsp_t;
/**@brief Event structure for BLE_GATTC_EVT_DESC_DISC_RSP. */
typedef struct
{
uint16_t count; /**< Descriptor count. */
ble_gattc_desc_t descs[1]; /**< Descriptor data, variable length. */
} ble_gattc_evt_desc_disc_rsp_t;
/**@brief GATT read by UUID handle value pair. */
typedef struct
{
uint16_t handle; /**< Attribute Handle. */
uint8_t *p_value; /**< Pointer to value, variable length (length available as value_len in ble_gattc_evt_read_by_uuid_rsp_t).
Please note that this pointer is absolute to the memory provided by the user when retrieving the event,
so it will effectively point to a location inside the handle_value array. */
} ble_gattc_handle_value_t;
/**@brief Event structure for BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP. */
typedef struct
{
uint16_t count; /**< Handle-Value Pair Count. */
uint16_t value_len; /**< Length of the value in Handle-Value(s) list. */
ble_gattc_handle_value_t handle_value[1]; /**< Handle-Value(s) list, variable length. */
} ble_gattc_evt_char_val_by_uuid_read_rsp_t;
/**@brief Event structure for BLE_GATTC_EVT_READ_RSP. */
typedef struct
{
uint16_t handle; /**< Attribute Handle. */
uint16_t offset; /**< Offset of the attribute data. */
uint16_t len; /**< Attribute data length. */
uint8_t data[1]; /**< Attribute data, variable length. */
} ble_gattc_evt_read_rsp_t;
/**@brief Event structure for BLE_GATTC_EVT_CHAR_VALS_READ_RSP. */
typedef struct
{
uint16_t len; /**< Concatenated Attribute values length. */
uint8_t values[1]; /**< Attribute values, variable length. */
} ble_gattc_evt_char_vals_read_rsp_t;
/**@brief Event structure for BLE_GATTC_EVT_WRITE_RSP. */
typedef struct
{
uint16_t handle; /**< Attribute Handle. */
uint8_t write_op; /**< Type of write operation, see @ref BLE_GATT_WRITE_OPS. */
uint16_t offset; /**< Data Offset. */
uint16_t len; /**< Data length. */
uint8_t data[1]; /**< Data, variable length. */
} ble_gattc_evt_write_rsp_t;
/**@brief Event structure for BLE_GATTC_EVT_HVX. */
typedef struct
{
uint16_t handle; /**< Handle to which the HVx operation applies. */
uint8_t type; /**< Indication or Notification, see @ref BLE_GATT_HVX_TYPES. */
uint16_t len; /**< Attribute data length. */
uint8_t data[1]; /**< Attribute data, variable length. */
} ble_gattc_evt_hvx_t;
/**@brief Event structure for BLE_GATTC_EVT_TIMEOUT. */
typedef struct
{
uint8_t src; /**< Timeout source, see @ref BLE_GATT_TIMEOUT_SOURCES. */
} ble_gattc_evt_timeout_t;
/**@brief GATTC event type. */
typedef struct
{
uint16_t conn_handle; /**< Connection Handle on which event occured. */
uint16_t gatt_status; /**< GATT status code for the operation, see @ref BLE_GATT_STATUS_CODES. */
uint16_t error_handle; /**< In case of error: The handle causing the error. In all other cases BLE_GATT_HANDLE_INVALID. */
union
{
ble_gattc_evt_prim_srvc_disc_rsp_t prim_srvc_disc_rsp; /**< Primary Service Discovery Response Event Parameters. */
ble_gattc_evt_rel_disc_rsp_t rel_disc_rsp; /**< Relationship Discovery Response Event Parameters. */
ble_gattc_evt_char_disc_rsp_t char_disc_rsp; /**< Characteristic Discovery Response Event Parameters. */
ble_gattc_evt_desc_disc_rsp_t desc_disc_rsp; /**< Descriptor Discovery Response Event Parameters. */
ble_gattc_evt_char_val_by_uuid_read_rsp_t char_val_by_uuid_read_rsp; /**< Characteristic Value Read by UUID Response Event Parameters. */
ble_gattc_evt_read_rsp_t read_rsp; /**< Read Response Event Parameters. */
ble_gattc_evt_char_vals_read_rsp_t char_vals_read_rsp; /**< Characteristic Values Read Response Event Parameters. */
ble_gattc_evt_write_rsp_t write_rsp; /**< Write Response Event Parameters. */
ble_gattc_evt_hvx_t hvx; /**< Handle Value Notification/Indication Event Parameters. */
ble_gattc_evt_timeout_t timeout; /**< Timeout Event Parameters. */
} params; /**< Event Parameters. @note Only valid if @ref gatt_status == BLE_GATT_STATUS_SUCCESS. */
} ble_gattc_evt_t;
/**@brief Initiate or continue a GATT Primary Service Discovery procedure.
*
* @details This function initiates a Primary Service discovery, starting from the supplied handle.
* If the last service has not been reached, this must be called again with an updated start handle value to continue the search.
*
* @note If any of the discovered services have 128-bit UUIDs which are not present in the table provided to ble_vs_uuids_assign, a UUID structure with
* type BLE_UUID_TYPE_UNKNOWN will be received in the corresponding event.
*
* @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
* @param[in] start_handle Handle to start searching from.
* @param[in] p_srvc_uuid Pointer to the service UUID to be found. If it is NULL, all primary services will be returned.
*
* @return @ref NRF_SUCCESS Successfully started or resumed the Primary Service Discovery procedure.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
* @return @ref NRF_ERROR_BUSY Client procedure already in progress.
*/
SVCALL(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER, uint32_t, sd_ble_gattc_primary_services_discover(uint16_t conn_handle, uint16_t start_handle, ble_uuid_t const * const p_srvc_uuid));
/**@brief Initiate or continue a GATT Relationship Discovery procedure.
*
* @details This function initiates the Find Included Services sub-procedure. If the last included service has not been reached,
* this must be called again with an updated handle range to continue the search.
*
* @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
* @param[in] p_handle_range A pointer to the range of handles of the Service to perform this procedure on.
*
* @return @ref NRF_SUCCESS Successfully started or resumed the Relationship Discovery procedure.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
* @return @ref NRF_ERROR_BUSY Client procedure already in progress.
*/
SVCALL(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER, uint32_t, sd_ble_gattc_relationships_discover(uint16_t conn_handle, ble_gattc_handle_range_t const * const p_handle_range));
/**@brief Initiate or continue a GATT Characteristic Discovery procedure.
*
* @details This function initiates a Characteristic discovery procedure. If the last Characteristic has not been reached,
* this must be called again with an updated handle range to continue the discovery.
*
* @note If any of the discovered characteristics have 128-bit UUIDs which are not present in the table provided to ble_vs_uuids_assign, a UUID structure with
* type BLE_UUID_TYPE_UNKNOWN will be received in the corresponding event.
*
* @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
* @param[in] p_handle_range A pointer to the range of handles of the Service to perform this procedure on.
*
* @return @ref NRF_SUCCESS Successfully started or resumed the Characteristic Discovery procedure.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_BUSY Client procedure already in progress.
*/
SVCALL(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER, uint32_t, sd_ble_gattc_characteristics_discover(uint16_t conn_handle, ble_gattc_handle_range_t const * const p_handle_range));
/**@brief Initiate or continue a GATT Characteristic Descriptor Discovery procedure.
*
* @details This function initiates the Characteristic Descriptor discovery procedure. If the last Descriptor has not been reached,
* this must be called again with an updated handle range to continue the discovery.
*
* @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
* @param[in] p_handle_range A pointer to the range of handles of the Characteristic to perform this procedure on.
*
* @return @ref NRF_SUCCESS Successfully started or resumed the Descriptor Discovery procedure.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_BUSY Client procedure already in progress.
*/
SVCALL(SD_BLE_GATTC_DESCRIPTORS_DISCOVER, uint32_t, sd_ble_gattc_descriptors_discover(uint16_t conn_handle, ble_gattc_handle_range_t const * const p_handle_range));
/**@brief Initiate or continue a GATT Read using Characteristic UUID procedure.
*
* @details This function initiates the Read using Characteristic UUID procedure. If the last Characteristic has not been reached,
* this must be called again with an updated handle range to continue the discovery.
*
* @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
* @param[in] p_uuid Pointer to a Characteristic value UUID to read.
* @param[in] p_handle_range A pointer to the range of handles to perform this procedure on.
*
* @return @ref NRF_SUCCESS Successfully started or resumed the Read using Characteristic UUID procedure.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_BUSY Client procedure already in progress.
*/
SVCALL(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ, uint32_t, sd_ble_gattc_char_value_by_uuid_read(uint16_t conn_handle, ble_uuid_t const * const p_uuid, ble_gattc_handle_range_t const * const p_handle_range));
/**@brief Initiate or continue a GATT Read (Long) Characteristic or Descriptor procedure.
*
* @details This function initiates a GATT Read (Long) Characteristic or Descriptor procedure. If the Characteristic or Descriptor
* to be read is longer than GATT_MTU - 1, this function must be called multiple times with appropriate offset to read the
* complete value.
*
* @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
* @param[in] handle The handle of the attribute to be read.
* @param[in] offset Offset into the attribute value to be read.
*
* @return @ref NRF_SUCCESS Successfully started or resumed the Read (Long) procedure.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_BUSY Client procedure already in progress.
*/
SVCALL(SD_BLE_GATTC_READ, uint32_t, sd_ble_gattc_read(uint16_t conn_handle, uint16_t handle, uint16_t offset));
/**@brief Initiate a GATT Read Multiple Characteristic Values procedure.
*
* @details This function initiates a GATT Read Multiple Characteristic Values procedure.
*
* @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
* @param[in] p_handles A pointer to the handle(s) of the attribute(s) to be read.
* @param[in] handle_count The number of handles in p_handles.
*
* @return @ref NRF_SUCCESS Successfully started the Read Multiple Characteristic Values procedure.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_BUSY Client procedure already in progress.
*/
SVCALL(SD_BLE_GATTC_CHAR_VALUES_READ, uint32_t, sd_ble_gattc_char_values_read(uint16_t conn_handle, uint16_t const * const p_handles, uint16_t handle_count));
/**@brief Perform a Write (Characteristic Value or Descriptor, with or without response, signed or not, long or reliable) procedure.
*
* @details This function can perform all write procedures described in GATT.
*
* @note It is important to note that a write without response will <b>consume an application buffer</b>, and will therefore
* generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted. A write on the other hand will use the
* standard client internal buffer and thus will only generate a @ref BLE_GATTC_EVT_WRITE_RSP event as soon as the write response
* has been received from the peer. Please see the documentation of @ref sd_ble_tx_buffer_count_get for more details.
*
* @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
* @param[in] p_write_params A pointer to a write parameters structure.
*
* @return @ref NRF_SUCCESS Successfully started the Write procedure.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
* @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
* @return @ref NRF_ERROR_BUSY Procedure already in progress.
* @return @ref BLE_ERROR_NO_TX_BUFFERS There are no available buffers left.
*/
SVCALL(SD_BLE_GATTC_WRITE, uint32_t, sd_ble_gattc_write(uint16_t conn_handle, ble_gattc_write_params_t const * const p_write_params));
/**@brief Send a Handle Value Confirmation to the GATT Server.
*
* @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
* @param[in] handle The handle of the attribute in the indication.
*
* @return @ref NRF_SUCCESS Successfully queued the Handle Value Confirmation for transmission.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
* @return @ref NRF_ERROR_INVALID_STATE No Indication pending to be confirmed.
* @return @ref BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle.
* @return @ref BLE_ERROR_NO_TX_BUFFERS There are no available buffers left.
*/
SVCALL(SD_BLE_GATTC_HV_CONFIRM, uint32_t, sd_ble_gattc_hv_confirm(uint16_t conn_handle, uint16_t handle));
#endif /* BLE_GATTC_H__ */
/**
@}
@}
*/

View File

@ -0,0 +1,547 @@
/* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is confidential property of Nordic Semiconductor. The use,
* copying, transfer or disclosure of such information is prohibited except by express written
* agreement with Nordic Semiconductor.
*
*/
/**
@addtogroup BLE_GATTS Generic Attribute Profile (GATT) Server
@{
@brief Definitions and prototypes for the GATTS interface.
*/
#ifndef BLE_GATTS_H__
#define BLE_GATTS_H__
#include "ble_types.h"
#include "ble_ranges.h"
#include "ble_l2cap.h"
#include "ble_gap.h"
#include "ble_gatt.h"
#include "nrf_svc.h"
/**
* @brief GATTS API SVC numbers.
*/
enum BLE_GATTS_SVCS
{
SD_BLE_GATTS_SERVICE_ADD = BLE_GATTS_SVC_BASE, /**< Add a service. */
SD_BLE_GATTS_INCLUDE_ADD, /**< Add an included service. */
SD_BLE_GATTS_CHARACTERISTIC_ADD, /**< Add a characteristic. */
SD_BLE_GATTS_DESCRIPTOR_ADD, /**< Add a generic attribute. */
SD_BLE_GATTS_VALUE_SET, /**< Set an attribute value. */
SD_BLE_GATTS_VALUE_GET, /**< Get an attribute value. */
SD_BLE_GATTS_HVX, /**< Handle Value Notification or Indication. */
SD_BLE_GATTS_SERVICE_CHANGED, /**< Perform a Service Changed Indication to one or more peers. */
SD_BLE_GATTS_RW_AUTHORIZE_REPLY, /**< Reply to an authorization request for a read or write operation on one or more attributes. */
SD_BLE_GATTS_SYS_ATTR_SET, /**< Set the persistent system attributes for a connection. */
SD_BLE_GATTS_SYS_ATTR_GET, /**< Get updated persistent system attributes after terminating a connection. */
};
/** @addtogroup BLE_GATTS_DEFINES Defines
* @{ */
/** @brief Only the default MTU size of 23 is currently supported. */
#define GATT_RX_MTU 23
/** @defgroup BLE_ERRORS_GATTS SVC return values specific to GATTS
* @{ */
#define BLE_ERROR_GATTS_INVALID_ATTR_TYPE (NRF_GATTS_ERR_BASE + 0x000) /**< Invalid attribute type. */
#define BLE_ERROR_GATTS_SYS_ATTR_MISSING (NRF_GATTS_ERR_BASE + 0x001) /**< System Attributes missing. */
/** @} */
/** @defgroup BLE_GATTS_ATTR_LENS_MAX Maximum attribute lengths
* @{ */
#define BLE_GATTS_FIX_ATTR_LEN_MAX (510) /**< Maximum length for fixed length Attribute Values. */
#define BLE_GATTS_VAR_ATTR_LEN_MAX (512) /**< Maximum length for variable length Attribute Values. */
/** @} */
/** @defgroup BLE_GATTS_SRVC_TYPES GATT Server Service Types
* @{ */
#define BLE_GATTS_SRVC_TYPE_INVALID 0x00 /**< Invalid Service Type. */
#define BLE_GATTS_SRVC_TYPE_PRIMARY 0x01 /**< Primary Service. */
#define BLE_GATTS_SRVC_TYPE_SECONDARY 0x02 /**< Secondary Type. */
/** @} */
/** @defgroup BLE_GATTS_ATTR_TYPES GATT Server Attribute Types
* @{ */
#define BLE_GATTS_ATTR_TYPE_INVALID 0x00 /**< Invalid Attribute Type. */
#define BLE_GATTS_ATTR_TYPE_PRIM_SRVC_DECL 0x01 /**< Primary Service Declaration. */
#define BLE_GATTS_ATTR_TYPE_SEC_SRVC_DECL 0x02 /**< Secondary Service Declaration. */
#define BLE_GATTS_ATTR_TYPE_INC_DECL 0x03 /**< Include Declaration. */
#define BLE_GATTS_ATTR_TYPE_CHAR_DECL 0x04 /**< Characteristic Declaration. */
#define BLE_GATTS_ATTR_TYPE_CHAR_VAL 0x05 /**< Characteristic Value. */
#define BLE_GATTS_ATTR_TYPE_DESC 0x06 /**< Descriptor. */
#define BLE_GATTS_ATTR_TYPE_OTHER 0x07 /**< Other, non-GATT specific type. */
/** @} */
/** @defgroup BLE_GATTS_OPS GATT Server Operations
* @{ */
#define BLE_GATTS_OP_INVALID 0x00 /**< Invalid Operation. */
#define BLE_GATTS_OP_WRITE_REQ 0x01 /**< Write Request. */
#define BLE_GATTS_OP_WRITE_CMD 0x02 /**< Write Command. */
#define BLE_GATTS_OP_SIGN_WRITE_CMD 0x03 /**< Signed Write Command. */
#define BLE_GATTS_OP_PREP_WRITE_REQ 0x04 /**< Prepare Write Request. */
#define BLE_GATTS_OP_EXEC_WRITE_REQ_CANCEL 0x05 /**< Execute Write Request: Cancel all prepared writes. */
#define BLE_GATTS_OP_EXEC_WRITE_REQ_NOW 0x06 /**< Execute Write Request: Immediately execute all prepared writes. */
/** @} */
/** @defgroup BLE_GATTS_VLOCS GATT Value Locations
* @{ */
#define BLE_GATTS_VLOC_INVALID 0x00 /**< Invalid Location. */
#define BLE_GATTS_VLOC_STACK 0x01 /**< Attribute Value is located in stack memory, no user memory is required. */
#define BLE_GATTS_VLOC_USER 0x02 /**< Attribute Value is located in user memory. This requires the user to maintain a valid buffer through the lifetime of the attribute, since the stack
will read and write directly to the memory using the pointer provided in the APIs. There are no alignment requirements for the buffer. */
/** @} */
/** @defgroup BLE_GATTS_AUTHORIZE_TYPES GATT Server Authorization Types
* @{ */
#define BLE_GATTS_AUTHORIZE_TYPE_INVALID 0x00 /**< Invalid Type. */
#define BLE_GATTS_AUTHORIZE_TYPE_READ 0x01 /**< Authorize a Read Operation. */
#define BLE_GATTS_AUTHORIZE_TYPE_WRITE 0x02 /**< Authorize a Write Request Operation. */
/** @} */
/** @} */
/**@brief Attribute metadata. */
typedef struct
{
ble_gap_conn_sec_mode_t read_perm; /**< Read permissions. */
ble_gap_conn_sec_mode_t write_perm; /**< Write permissions. */
uint8_t vlen :1; /**< Variable length attribute. */
uint8_t vloc :2; /**< Value location, see @ref BLE_GATTS_VLOCS.*/
uint8_t rd_auth :1; /**< Read Authorization and value will be requested from the application on every read operation. */
uint8_t wr_auth :1; /**< Write Authorization will be requested from the application on every Write Request operation (but not Write Command). */
} ble_gatts_attr_md_t;
/**@brief GATT Attribute. */
typedef struct
{
ble_uuid_t* p_uuid; /**< Pointer to the attribute UUID. */
ble_gatts_attr_md_t* p_attr_md; /**< Pointer to the attribute metadata structure. */
uint16_t init_len; /**< Initial attribute value length in bytes. */
uint16_t init_offs; /**< Initial attribute value offset in bytes. If different from zero, the first init_offs bytes of the attribute value will be left uninitialized. */
uint16_t max_len; /**< Maximum attribute value length in bytes, see @ref BLE_GATTS_ATTR_LENS_MAX for maximum values. */
uint8_t* p_value; /**< Pointer to the attribute data. Please note that if the @ref BLE_GATTS_VLOC_USER value location is selected in the attribute metadata, this will have to point to a buffer
that remains valid through the lifetime of the attribute. This excludes usage of automatic variables that may go out of scope or any other temporary location.
The stack may access that memory directly without the application's knowledge. */
} ble_gatts_attr_t;
/**@brief GATT Attribute Context. */
typedef struct
{
ble_uuid_t srvc_uuid; /**< Service UUID. */
ble_uuid_t char_uuid; /**< Characteristic UUID if applicable (BLE_UUID_TYPE_UNKNOWN if N/A). */
ble_uuid_t desc_uuid; /**< Descriptor UUID if applicable (BLE_UUID_TYPE_UNKNOWN if N/A). */
uint16_t srvc_handle; /**< Service Handle. */
uint16_t value_handle; /**< Characteristic Handle if applicable (BLE_GATT_HANDLE_INVALID if N/A). */
uint8_t type; /**< Attribute Type, see @ref BLE_GATTS_ATTR_TYPES. */
} ble_gatts_attr_context_t;
/**@brief GATT Characteristic Presentation Format. */
typedef struct
{
uint8_t format; /**< Format of the value, see @ref BLE_GATT_CPF_FORMATS. */
int8_t exponent; /**< Exponent for integer data types. */
uint16_t unit; /**< UUID from Bluetooth Assigned Numbers. */
uint8_t name_space; /**< Namespace from Bluetooth Assigned Numbers, see @ref BLE_GATT_CPF_NAMESPACES. */
uint16_t desc; /**< Namespace description from Bluetooth Assigned Numbers, see @ref BLE_GATT_CPF_NAMESPACES. */
} ble_gatts_char_pf_t;
/**@brief GATT Characteristic metadata. */
typedef struct
{
ble_gatt_char_props_t char_props; /**< Characteristic Properties. */
ble_gatt_char_ext_props_t char_ext_props; /**< Characteristic Extended Properties. */
uint8_t* p_char_user_desc; /**< Pointer to a UTF-8, NULL if the descriptor is not required. */
uint16_t char_user_desc_max_size; /**< The maximum size in bytes of the user description descriptor. */
uint16_t char_user_desc_size; /**< The size of the user description, must be smaller or equal to char_user_desc_max_size. */
ble_gatts_char_pf_t* p_char_pf; /**< Pointer to a presentation format structure or NULL if the descriptor is not required. */
ble_gatts_attr_md_t* p_user_desc_md; /**< Attribute metadata for the User Description descriptor, or NULL for default values. */
ble_gatts_attr_md_t* p_cccd_md; /**< Attribute metadata for the Client Characteristic Configuration Descriptor, or NULL for default values. */
ble_gatts_attr_md_t* p_sccd_md; /**< Attribute metadata for the Server Characteristic Configuration Descriptor, or NULL for default values. */
} ble_gatts_char_md_t;
/**@brief GATT Characteristic Definition Handles. */
typedef struct
{
uint16_t value_handle; /**< Handle to the characteristic value. */
uint16_t user_desc_handle; /**< Handle to the User Description descriptor, or BLE_GATT_HANDLE_INVALID if not present. */
uint16_t cccd_handle; /**< Handle to the Client Characteristic Configuration Descriptor, or BLE_GATT_HANDLE_INVALID if not present. */
uint16_t sccd_handle; /**< Handle to the Server Characteristic Configuration Descriptor, or BLE_GATT_HANDLE_INVALID if not present. */
} ble_gatts_char_handles_t;
/**@brief GATT HVx parameters. */
typedef struct
{
uint16_t handle; /**< Characteristic Value Handle. */
uint8_t type; /**< Indication or Notification, see @ref BLE_GATT_HVX_TYPES. */
uint16_t offset; /**< Offset within the attribute value. */
uint16_t* p_len; /**< Length in bytes to be written, length in bytes written after successful return. */
uint8_t* p_data; /**< Actual data content, use NULL to use the current attribute value. */
} ble_gatts_hvx_params_t;
/**@brief GATT Read Authorization parameters. */
typedef struct
{
uint16_t gatt_status; /**< GATT status code for the operation, see @ref BLE_GATT_STATUS_CODES. */
uint8_t update : 1; /**< If set, data supplied in p_data will be used in the ATT response. */
uint16_t offset; /**< Offset of the attribute value being updated. */
uint16_t len; /**< Length in bytes of the value in p_data pointer, see @ref BLE_GATTS_ATTR_LENS_MAX. */
uint8_t* p_data; /**< Pointer to new value used to update the attribute value. */
} ble_gatts_read_authorize_params_t;
/**@brief GATT Write Authorisation parameters. */
typedef struct
{
uint16_t gatt_status; /**< GATT status code for the operation, see @ref BLE_GATT_STATUS_CODES. */
} ble_gatts_write_authorize_params_t;
/**@brief GATT Read or Write Authorize Reply parameters. */
typedef struct
{
uint8_t type; /**< Type of authorize operation, see @ref BLE_GATTS_AUTHORIZE_TYPES. */
union {
ble_gatts_read_authorize_params_t read; /**< Read authorization parameters. */
ble_gatts_write_authorize_params_t write; /**< Write authorization parameters. */
} params;
} ble_gatts_rw_authorize_reply_params_t;
/**
* @brief GATT Server Event IDs.
*/
enum BLE_GATTS_EVTS
{
BLE_GATTS_EVT_WRITE = BLE_GATTS_EVT_BASE, /**< Write operation performed. */
BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST, /**< Read/Write Authorization request. */
BLE_GATTS_EVT_SYS_ATTR_MISSING, /**< A persistent system attribute access is pending, awaiting a sd_ble_gatts_sys_attr_set(). */
BLE_GATTS_EVT_HVC, /**< Handle Value Confirmation. */
BLE_GATTS_EVT_SC_CONFIRM, /**< Service Changed Confirmation. */
BLE_GATTS_EVT_TIMEOUT /**< Timeout. */
};
/**@brief Event structure for BLE_GATTS_EVT_WRITE. */
typedef struct
{
uint16_t handle; /**< Attribute Handle. */
uint8_t op; /**< Type of write operation, see @ref BLE_GATTS_OPS. */
ble_gatts_attr_context_t context; /**< Attribute Context. */
uint16_t offset; /**< Offset for the write operation. */
uint16_t len; /**< Length of the incoming data. */
uint8_t data[1]; /**< Incoming data, variable length. */
} ble_gatts_evt_write_t;
/**@brief Event structure for authorize read request. */
typedef struct
{
uint16_t handle; /**< Attribute Handle. */
ble_gatts_attr_context_t context; /**< Attribute Context. */
uint16_t offset; /**< Offset for the read operation. */
} ble_gatts_evt_read_t;
/**@brief Event structure for BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST. */
typedef struct
{
uint8_t type; /**< Type of authorize operation, see @ref BLE_GATTS_AUTHORIZE_TYPES. */
union {
ble_gatts_evt_read_t read; /**< Attribute Read Parameters. */
ble_gatts_evt_write_t write; /**< Attribute Write Parameters. */
} request;
} ble_gatts_evt_rw_authorize_request_t;
/**@brief Event structure for BLE_GATTS_EVT_SYS_ATTR_MISSING. */
typedef struct
{
uint8_t hint;
} ble_gatts_evt_sys_attr_missing_t;
/**@brief Event structure for BLE_GATTS_EVT_HVC. */
typedef struct
{
uint16_t handle; /**< Attribute Handle. */
} ble_gatts_evt_hvc_t;
/**@brief Event structure for BLE_GATTS_EVT_TIMEOUT. */
typedef struct
{
uint8_t src; /**< Timeout source, see @ref BLE_GATT_TIMEOUT_SOURCES. */
} ble_gatts_evt_timeout_t;
/**@brief GATT Server event callback event structure. */
typedef struct
{
uint16_t conn_handle; /**< Connection Handle on which event occurred. */
union
{
ble_gatts_evt_write_t write; /**< Write Event Parameters. */
ble_gatts_evt_rw_authorize_request_t authorize_request; /**< Read or Write Authorize Request Parameters. */
ble_gatts_evt_sys_attr_missing_t sys_attr_missing; /**< System attributes missing. */
ble_gatts_evt_hvc_t hvc; /**< Handle Value Confirmation Event Parameters. */
ble_gatts_evt_timeout_t timeout; /**< Timeout Event. */
} params;
} ble_gatts_evt_t;
/**@brief Add a service declaration to the local server ATT table.
*
* @param[in] type Toggles between primary and secondary services, see @ref BLE_GATTS_SRVC_TYPES.
* @param[in] p_uuid Pointer to service UUID.
* @param[out] p_handle Pointer to a 16-bit word where the assigned handle will be stored.
*
* @note Secondary Services are only relevant in the context of the entity that references them, it is therefore forbidden to
* add a secondary service declaration that is not referenced by another service later in the ATT table.
*
* @return @ref NRF_SUCCESS Successfully added a service declaration.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, Vendor Specific UUIDs need to be present in the table.
* @return @ref NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack.
* @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
*/
SVCALL(SD_BLE_GATTS_SERVICE_ADD, uint32_t, sd_ble_gatts_service_add(uint8_t type, ble_uuid_t const*const p_uuid, uint16_t *const p_handle));
/**@brief Add an include declaration to the local server ATT table.
*
* @note It is currently only possible to add an include declaration to the last added service (i.e. only sequential addition is supported at this time).
*
* @note The included service must already be present in the ATT table prior to this call.
*
* @param[in] service_handle Handle of the service where the included service is to be placed, if BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.
* @param[in] inc_srvc_handle Handle of the included service.
* @param[out] p_include_handle Pointer to a 16-bit word where the assigned handle will be stored.
*
* @return @ref NRF_SUCCESS Successfully added an include declaration.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, handle values need to match previously added services.
* @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
* @return @ref NRF_ERROR_FORBIDDEN Forbidden value supplied, self inclusions are not allowed.
* @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
* @return @ref NRF_ERROR_NOT_FOUND Attribute not found.
*/
SVCALL(SD_BLE_GATTS_INCLUDE_ADD, uint32_t, sd_ble_gatts_include_add(uint16_t service_handle, uint16_t inc_srvc_handle, uint16_t *const p_include_handle));
/**@brief Add a characteristic declaration, a characteristic value declaration and optional characteristic descriptor declarations to the local server ATT table.
*
* @note It is currently only possible to add a characteristic to the last added service (i.e. only sequential addition is supported at this time).
*
* @note Several restrictions apply to the parameters, such as matching permissions between the user description descriptor and the writeable auxiliaries bits,
* readable (no security) and writeable (selectable) CCCDs and SCCDs and valid presentation format values.
*
* @note If no metadata is provided for the optional descriptors, their permissions will be derived from the characteristic permissions.
*
* @param[in] service_handle Handle of the service where the characteristic is to be placed, if BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.
* @param[in] p_char_md Characteristic metadata.
* @param[in] p_attr_char_value Pointer to the attribute structure corresponding to the characteristic value.
* @param[out] p_handles Pointer to the structure where the assigned handles will be stored.
*
* @return @ref NRF_SUCCESS Successfully added a characteristic.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, service handle, Vendor Specific UUIDs, lengths, and permissions need to adhere to the constraints.
* @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation, a service context is required.
* @return @ref NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack.
* @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
* @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX.
*/
SVCALL(SD_BLE_GATTS_CHARACTERISTIC_ADD, uint32_t, sd_ble_gatts_characteristic_add(uint16_t service_handle, ble_gatts_char_md_t const*const p_char_md, ble_gatts_attr_t const*const p_attr_char_value, ble_gatts_char_handles_t *const p_handles));
/**@brief Add a descriptor to the local server ATT table.
*
* @note It is currently only possible to add a descriptor to the last added characteristic (i.e. only sequential addition is supported at this time).
*
* @param[in] char_handle Handle of the characteristic where the descriptor is to be placed, if BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.
* @param[in] p_attr Pointer to the attribute structure.
* @param[out] p_handle Pointer to a 16-bit word where the assigned handle will be stored.
*
* @return @ref NRF_SUCCESS Successfully added a descriptor.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, characteristic handle, Vendor Specific UUIDs, lengths, and permissions need to adhere to the constraints.
* @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation, a characteristic context is required.
* @return @ref NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack.
* @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
* @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX.
*/
SVCALL(SD_BLE_GATTS_DESCRIPTOR_ADD, uint32_t, sd_ble_gatts_descriptor_add(uint16_t char_handle, ble_gatts_attr_t const * const p_attr, uint16_t* const p_handle));
/**@brief Set the value of a given attribute.
*
* @param[in] handle Attribute handle.
* @param[in] offset Offset in bytes to write from.
* @param[in,out] p_len Length in bytes to be written, length in bytes written after successful return.
* @param[in] p_value Pointer to a buffer (at least len bytes long) containing the desired attribute value.
*
* @return @ref NRF_SUCCESS Successfully set the value of the attribute.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
* @return @ref NRF_ERROR_NOT_FOUND Attribute not found.
* @return @ref NRF_ERROR_FORBIDDEN Forbidden handle supplied, certain attributes are not modifiable by the application.
* @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX.
*/
SVCALL(SD_BLE_GATTS_VALUE_SET, uint32_t, sd_ble_gatts_value_set(uint16_t handle, uint16_t offset, uint16_t* const p_len, uint8_t const * const p_value));
/**@brief Get the value of a given attribute.
*
* @param[in] handle Attribute handle.
* @param[in] offset Offset in bytes to read from.
* @param[in,out] p_len Length in bytes to be read, total length of attribute value (in bytes, starting from offset) after successful return.
* @param[in,out] p_data Pointer to a buffer (at least len bytes long) where to store the attribute value. Set to NULL to obtain the complete length of attribute value.
*
* @note If the attribute value is longer than the size of the supplied buffer,
* p_len will return the total attribute value length (excluding offset),
* and not the number of bytes actually returned in p_data.
* The application may use this information to allocate a suitable buffer size.
*
* @return @ref NRF_SUCCESS Successfully retrieved the value of the attribute.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_NOT_FOUND Attribute not found.
*/
SVCALL(SD_BLE_GATTS_VALUE_GET, uint32_t, sd_ble_gatts_value_get(uint16_t handle, uint16_t offset, uint16_t *const p_len, uint8_t* const p_data));
/**@brief Notify or Indicate an attribute value.
*
* @details This function checks for the relevant Client Characteristic Configuration descriptor value to verify that the relevant operation
* (notification or indication) has been enabled by the client. It is also able to update the attribute value before issuing the PDU, so that
* the application can atomically perform a value update and a server initiated transaction with a single API call.
* If the application chooses to indicate an attribute value, a @ref BLE_GATTS_EVT_HVC will be sent up as soon as the confirmation arrives from
* the peer.
*
* @note The local attribute value may be updated even if an outgoing packet is not sent to the peer due to an error during execution.
* When receiveing the error codes @ref NRF_ERROR_INVALID_STATE, @ref NRF_ERROR_BUSY, @ref BLE_ERROR_GATTS_SYS_ATTR_MISSING and
* @ref BLE_ERROR_NO_TX_BUFFERS the ATT table has been updated.
* The caller can check whether the value has been updated by looking at the contents of *(p_hvx_params->p_len).
*
* @note It is important to note that a notification will <b>consume an application buffer</b>, and will therefore
* generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted. An indication on the other hand will use the
* standard server internal buffer and thus will only generate a @ref BLE_GATTS_EVT_HVC event as soon as the confirmation
* has been received from the peer. Please see the documentation of @ref sd_ble_tx_buffer_count_get for more details.
*
* @param[in] conn_handle Connection handle.
* @param[in] p_hvx_params Pointer to an HVx parameters structure. If the p_data member contains a non-NULL pointer the attribute value will be updated with
* the contents pointed by it before sending the notification or indication.
*
* @return @ref NRF_SUCCESS Successfully queued a notification or indication for transmission, and optionally updated the attribute value.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
* @return @ref BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle(s) supplied. Only attributes added directly by the application are available to notify and indicate.
* @return @ref BLE_ERROR_GATTS_INVALID_ATTR_TYPE Invalid attribute type(s) supplied, only characteristic values may be notified and indicated.
* @return @ref NRF_ERROR_NOT_FOUND Attribute not found.
* @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
* @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation, notifications or indications must be enabled in the CCCD.
* @return @ref NRF_ERROR_BUSY Procedure already in progress.
* @return @ref BLE_ERROR_GATTS_SYS_ATTR_MISSING System attributes missing, use @ref sd_ble_gatts_sys_attr_set to set them to a known value.
* @return @ref BLE_ERROR_NO_TX_BUFFERS There are no available buffers to send the data, applies only to notifications.
*/
SVCALL(SD_BLE_GATTS_HVX, uint32_t, sd_ble_gatts_hvx(uint16_t conn_handle, ble_gatts_hvx_params_t const*const p_hvx_params));
/**@brief Indicate the Service Changed attribute value.
*
* @details This call will send a Handle Value Indication to one or more peers connected to inform them that the attribute
* table layout has changed. As soon as the peer has confirmed the indication, a @ref BLE_GATTS_EVT_SC_CONFIRM event will
* be issued.
*
* @note Some of the restrictions and limitations that apply to @ref sd_ble_gatts_hvx also apply here.
*
* @param[in] conn_handle Connection handle.
* @param[in] start_handle Start of affected attribute handle range.
* @param[in] end_handle End of affected attribute handle range.
*
* @return @ref NRF_SUCCESS Successfully queued the Service Changed indication for transmission.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
* @return @ref BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle(s) supplied, handles must be in the range populated by the application.
* @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation, notifications or indications must be enabled in the CCCD.
* @return @ref NRF_ERROR_BUSY Procedure already in progress.
* @return @ref BLE_ERROR_GATTS_SYS_ATTR_MISSING System attributes missing, use @ref sd_ble_gatts_sys_attr_set to set them to a known value.
*/
SVCALL(SD_BLE_GATTS_SERVICE_CHANGED, uint32_t, sd_ble_gatts_service_changed(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle));
/**@brief Respond to a Read/Write authorization request.
*
* @note This call should only be used as a response to a @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event issued to the application.
*
* @param[in] conn_handle Connection handle.
* @param[in] p_rw_authorize_reply_params Pointer to a structure with the attribute provided by the application.
*
* @return @ref NRF_SUCCESS Successfully queued a response to the peer, and in the case of a write operation, ATT table updated.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
* @return @ref NRF_ERROR_INVALID_STATE No authorization request pending.
* @return @ref NRF_ERROR_INVALID_PARAM Authorization op invalid,
* or for Read Authorization reply: requested handles not replied with,
* or for Write Authorization reply: handle supplied does not match requested handle.
*/
SVCALL(SD_BLE_GATTS_RW_AUTHORIZE_REPLY, uint32_t, sd_ble_gatts_rw_authorize_reply(uint16_t conn_handle, ble_gatts_rw_authorize_reply_params_t const*const p_rw_authorize_reply_params));
/**@brief Update persistent system attribute information.
*
* @details Supply to the stack information about persistent system attributes.
* This call is legal in the connected state only, and is usually
* made immediately after a connection is established and the bond identified.
* usually as a response to a BLE_GATTS_EVT_SYS_ATTR_MISSING.
*
* p_sysattrs may point directly to the application's stored copy of the struct.
* If the pointer is NULL, the system attribute info is initialized, assuming that
* the application does not have any previously saved data for this bond.
*
* @note The state of persistent system attributes is reset upon connection and then remembered for its duration.
*
* @note If this call returns with an error code different from @ref NRF_SUCCESS, the storage of persistent system attributes may have been completed only partially.
* This means that the state of the attribute table is undefined, and the application should either provide a new set of attributes using this same call or
* reset the SoftDevice to return to a known state.
*
* @param[in] conn_handle Connection handle.
* @param[in] p_sys_attr_data Pointer to a saved copy of system attributes supplied to the stack, or NULL.
* @param[in] len Size of data pointed by p_sys_attr_data, in octets.
*
* @return @ref NRF_SUCCESS Successfully set the system attribute information.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
* @return @ref NRF_ERROR_INVALID_DATA Invalid data supplied, the data should be exactly the same as retrieved with @ref sd_ble_gatts_sys_attr_get.
* @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
*/
SVCALL(SD_BLE_GATTS_SYS_ATTR_SET, uint32_t, sd_ble_gatts_sys_attr_set(uint16_t conn_handle, uint8_t const*const p_sys_attr_data, uint16_t len));
/**@brief Retrieve persistent system attribute information from the stack.
*
* @details This call is used to retrieve information about values to be stored perisistently by the application
* after a connection has been terminated. When a new connection is made to the same bond, the values
* should be restored using @ref sd_ble_gatts_sys_attr_set.
* The data should be read before any new advertising is started, or any new connection established. The connection handle for
* the previous now defunct connection will remain valid until a new one is created to allow this API call to refer to it.
*
* @param[in] conn_handle Connection handle of the recently terminated connection.
* @param[in] p_sys_attr_data Pointer to a buffer where updated information about system attributes will be filled in. NULL can be provided to
* obtain the length of the data
* @param[in,out] p_len Size of application buffer if p_sys_attr_data is not NULL. Unconditially updated to actual length of system attribute data.
*
* @return @ref NRF_SUCCESS Successfully retrieved the system attribute information.
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_DATA_SIZE The system attribute information did not fit into the provided buffer.
*/
SVCALL(SD_BLE_GATTS_SYS_ATTR_GET, uint32_t, sd_ble_gatts_sys_attr_get(uint16_t conn_handle, uint8_t * const p_sys_attr_data, uint16_t* const p_len));
#endif // BLE_GATTS_H__
/**
@}
*/

View File

@ -0,0 +1,96 @@
/*
Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
The information contained herein is confidential property of Nordic Semiconductor. The use,
copying, transfer or disclosure of such information is prohibited except by express written
agreement with Nordic Semiconductor.
*/
/**
@addtogroup BLE_COMMON
@{
*/
#ifndef BLE_HCI_H__
#define BLE_HCI_H__
/** @defgroup BLE_HCI_STATUS_CODES Bluetooth status codes
* @{ */
#define BLE_HCI_STATUS_CODE_SUCCESS 0x00
#define BLE_HCI_STATUS_CODE_UNKNOWN_BTLE_COMMAND 0x01
#define BLE_HCI_STATUS_CODE_UNKNOWN_CONNECTION_IDENTIFIER 0x02
/*0x03 Hardware Failure
0x04 Page Timeout
*/
#define BLE_HCI_AUTHENTICATION_FAILURE 0x05
#define BLE_HCI_STATUS_CODE_PIN_OR_KEY_MISSING 0x06
#define BLE_HCI_MEMORY_CAPACITY_EXCEEDED 0x07
#define BLE_HCI_CONNECTION_TIMEOUT 0x08
/*0x09 Connection Limit Exceeded
0x0A Synchronous Connection Limit To A Device Exceeded
0x0B ACL Connection Already Exists*/
#define BLE_HCI_STATUS_CODE_COMMAND_DISALLOWED 0x0C
/*0x0D Connection Rejected due to Limited Resources
0x0E Connection Rejected Due To Security Reasons
0x0F Connection Rejected due to Unacceptable BD_ADDR
0x10 Connection Accept Timeout Exceeded
0x11 Unsupported Feature or Parameter Value*/
#define BLE_HCI_STATUS_CODE_INVALID_BTLE_COMMAND_PARAMETERS 0x12
#define BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION 0x13
#define BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES 0x14
#define BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF 0x15
#define BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION 0x16
/*
0x17 Repeated Attempts
0x18 Pairing Not Allowed
0x19 Unknown LMP PDU
*/
#define BLE_HCI_UNSUPPORTED_REMOTE_FEATURE 0x1A
/*
0x1B SCO Offset Rejected
0x1C SCO Interval Rejected
0x1D SCO Air Mode Rejected*/
#define BLE_HCI_STATUS_CODE_INVALID_LMP_PARAMETERS 0x1E
#define BLE_HCI_STATUS_CODE_UNSPECIFIED_ERROR 0x1F
/*0x20 Unsupported LMP Parameter Value
0x21 Role Change Not Allowed
*/
#define BLE_HCI_STATUS_CODE_LMP_RESPONSE_TIMEOUT 0x22
/*0x23 LMP Error Transaction Collision*/
#define BLE_HCI_STATUS_CODE_LMP_PDU_NOT_ALLOWED 0x24
/*0x25 Encryption Mode Not Acceptable
0x26 Link Key Can Not be Changed
0x27 Requested QoS Not Supported
*/
#define BLE_HCI_INSTANT_PASSED 0x28
#define BLE_HCI_PAIRING_WITH_UNIT_KEY_UNSUPPORTED 0x29
#define BLE_HCI_DIFFERENT_TRANSACTION_COLLISION 0x2A
/*
0x2B Reserved
0x2C QoS Unacceptable Parameter
0x2D QoS Rejected
0x2E Channel Classification Not Supported
0x2F Insufficient Security
0x30 Parameter Out Of Mandatory Range
0x31 Reserved
0x32 Role Switch Pending
0x33 Reserved
0x34 Reserved Slot Violation
0x35 Role Switch Failed
0x36 Extended Inquiry Response Too Large
0x37 Secure Simple Pairing Not Supported By Host.
0x38 Host Busy - Pairing
0x39 Connection Rejected due to No Suitable Channel Found*/
#define BLE_HCI_CONTROLLER_BUSY 0x3A
#define BLE_HCI_CONN_INTERVAL_UNACCEPTABLE 0x3B
#define BLE_HCI_DIRECTED_ADVERTISER_TIMEOUT 0x3C
#define BLE_HCI_CONN_TERMINATED_DUE_TO_MIC_FAILURE 0x3D
#define BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED 0x3E
/** @} */
#endif // BLE_HCI_H__
/** @} */

View File

@ -0,0 +1,135 @@
/* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is confidential property of Nordic Semiconductor. The use,
* copying, transfer or disclosure of such information is prohibited except by express written
* agreement with Nordic Semiconductor.
*
*/
/**
@addtogroup BLE_L2CAP Logical Link Control and Adaptation Protocol (L2CAP)
@{
@brief Definitions and prototypes for the L2CAP interface.
*/
#ifndef BLE_L2CAP_H__
#define BLE_L2CAP_H__
#include "ble_types.h"
#include "ble_ranges.h"
#include "ble_err.h"
#include "nrf_svc.h"
/**@brief L2CAP API SVC numbers. */
enum BLE_L2CAP_SVCS
{
SD_BLE_L2CAP_CID_REGISTER = BLE_L2CAP_SVC_BASE, /**< Register a CID. */
SD_BLE_L2CAP_CID_UNREGISTER, /**< Unregister a CID. */
SD_BLE_L2CAP_TX /**< Transmit a packet. */
};
/**@addtogroup BLE_L2CAP_DEFINES Defines
* @{ */
/**@defgroup BLE_ERRORS_L2CAP SVC return values specific to L2CAP
* @{ */
#define BLE_ERROR_L2CAP_CID_IN_USE (NRF_L2CAP_ERR_BASE + 0x000) /**< CID already in use. */
/** @} */
/**@brief Default L2CAP MTU. */
#define BLE_L2CAP_MTU_DEF (23)
/**@brief Invalid Channel Identifier. */
#define BLE_L2CAP_CID_INVALID (0x0000)
/**@brief Dynamic Channel Identifier base. */
#define BLE_L2CAP_CID_DYN_BASE (0x0040)
/**@brief Maximum amount of dynamic CIDs. */
#define BLE_L2CAP_CID_DYN_MAX (8)
/** @} */
/**@brief Packet header format for L2CAP transmission. */
typedef struct
{
uint16_t len; /**< Length of valid info in data member. */
uint16_t cid; /**< Channel ID on which packet is transmitted. */
} ble_l2cap_header_t;
/**@brief L2CAP Event IDs. */
enum BLE_L2CAP_EVTS
{
BLE_L2CAP_EVT_RX = BLE_L2CAP_EVT_BASE /**< L2CAP packet received. */
};
/**@brief L2CAP Received packet event report. */
typedef struct
{
ble_l2cap_header_t header; /** L2CAP packet header. */
uint8_t data[1]; /**< Packet data, variable length. */
} ble_l2cap_evt_rx_t;
/**@brief L2CAP event callback event structure. */
typedef struct
{
uint16_t conn_handle; /**< Connection Handle on which event occured. */
union
{
ble_l2cap_evt_rx_t rx; /**< RX Event parameters. */
} params;
} ble_l2cap_evt_t;
/**@brief Register a CID with L2CAP.
*
* @details This registers a higher protocol layer with the L2CAP multiplexer, and is requried prior to all operations on the CID.
*
* @param[in] cid L2CAP CID.
*
* @return @ref NRF_SUCCESS Successfully registered a CID with the L2CAP layer.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CID must be above @ref BLE_L2CAP_CID_DYN_BASE.
* @return @ref BLE_ERROR_L2CAP_CID_IN_USE L2CAP CID already in use.
* @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
*/
SVCALL(SD_BLE_L2CAP_CID_REGISTER, uint32_t, sd_ble_l2cap_cid_register(uint16_t cid));
/**@brief Unregister a CID with L2CAP.
*
* @details This unregisters a previously registerd higher protocol layer with the L2CAP multiplexer.
*
* @param[in] cid L2CAP CID.
*
* @return @ref NRF_SUCCESS Successfully unregistered the CID.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
* @return @ref NRF_ERROR_NOT_FOUND CID not previously registered.
*/
SVCALL(SD_BLE_L2CAP_CID_UNREGISTER, uint32_t, sd_ble_l2cap_cid_unregister(uint16_t cid));
/**@brief Transmit an L2CAP packet.
*
* @note It is important to note that a call to this function will <b>consume an application buffer</b>, and will therefore
* generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted.
* Please see the documentation of @ref sd_ble_tx_buffer_count_get for more details.
*
* @param[in] conn_handle Connection Handle.
* @param[in] p_header Pointer to a packet header containing length and CID.
* @param[in] p_data Pointer to the data to be transmitted.
*
* @return @ref NRF_SUCCESS Successfully queued an L2CAP packet for transmission.
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CIDs must be registered beforehand with @ref sd_ble_l2cap_cid_register.
* @return @ref NRF_ERROR_NOT_FOUND CID not found.
* @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
* @return @ref BLE_ERROR_NO_TX_BUFFERS Not enough application buffers available.
* @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, see @ref BLE_L2CAP_MTU_DEF.
*/
SVCALL(SD_BLE_L2CAP_TX, uint32_t, sd_ble_l2cap_tx(uint16_t conn_handle, ble_l2cap_header_t const * const p_header, uint8_t const * const p_data));
#endif // BLE_L2CAP_H__
/**
@}
*/

View File

@ -0,0 +1,72 @@
/*
Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
The information contained herein is confidential property of Nordic Semiconductor. The use,
copying, transfer or disclosure of such information is prohibited except by express written
agreement with Nordic Semiconductor.
*/
/**
@addtogroup BLE_COMMON
@{
@defgroup ble_ranges Module specific SVC and event number subranges
@{
@brief Definition of SVC and event number subranges for each API module.
@note
SVCs and event numbers are split into subranges for each API module.
Each module receives its entire allocated range of SVC calls, whether implemented or not,
but return BLE_ERROR_NOT_SUPPORTED for unimplemented or undefined calls in its range.
Note that the symbols BLE_<module>_SVC_LAST is the end of the allocated SVC range,
rather than the last SVC function call actually defined and implemented.
Specific SVC and event values are defined in each module's ble_<module>.h file,
which defines names of each individual SVC code based on the range start value.
*/
#ifndef BLE_RANGES_H__
#define BLE_RANGES_H__
#define BLE_SVC_BASE 0x60
#define BLE_SVC_LAST 0x6B /* Total: 12. */
#define BLE_RESERVED_SVC_BASE 0x6C
#define BLE_RESERVED_SVC_LAST 0x6F /* Total: 4. */
#define BLE_GAP_SVC_BASE 0x70
#define BLE_GAP_SVC_LAST 0x8F /* Total: 32. */
#define BLE_GATTC_SVC_BASE 0x90
#define BLE_GATTC_SVC_LAST 0x9F /* Total: 16. */
#define BLE_GATTS_SVC_BASE 0xA0
#define BLE_GATTS_SVC_LAST 0xAF /* Total: 16. */
#define BLE_L2CAP_SVC_BASE 0xB0
#define BLE_L2CAP_SVC_LAST 0xBF /* Total: 16. */
#define BLE_EVT_INVALID 0x00
#define BLE_EVT_BASE 0x01
#define BLE_EVT_LAST 0x0F /* Total: 15. */
#define BLE_GAP_EVT_BASE 0x10
#define BLE_GAP_EVT_LAST 0x2F /* Total: 32. */
#define BLE_GATTC_EVT_BASE 0x30
#define BLE_GATTC_EVT_LAST 0x4F /* Total: 32. */
#define BLE_GATTS_EVT_BASE 0x50
#define BLE_GATTS_EVT_LAST 0x6F /* Total: 32. */
#define BLE_L2CAP_EVT_BASE 0x70
#define BLE_L2CAP_EVT_LAST 0x8F /* Total: 32. */
#endif /* BLE_RANGES_H__ */
/**
@}
@}
*/

View File

@ -0,0 +1,157 @@
/* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is confidential property of Nordic Semiconductor. The use,
* copying, transfer or disclosure of such information is prohibited except by express written
* agreement with Nordic Semiconductor.
*
*/
/**
@addtogroup BLE_COMMON
@{
@defgroup ble_types Common types and macro definitions
@{
@brief Common types and macro definitions for the S110 SoftDevice.
*/
#ifndef BLE_TYPES_H__
#define BLE_TYPES_H__
#include <stdint.h>
/** @addtogroup BLE_COMMON_DEFINES Defines
* @{ */
/** @defgroup BLE_CONN_HANDLES BLE Connection Handles
* @{ */
#define BLE_CONN_HANDLE_INVALID 0xFFFF /**< Invalid Connection Handle. */
#define BLE_CONN_HANDLE_ALL 0xFFFE /**< Applies to all Connection Handles. */
/** @} */
/** @defgroup BLE_UUID_VALUES Assigned Values for BLE UUIDs
* @{ */
/* Generic UUIDs, applicable to all services */
#define BLE_UUID_UNKNOWN 0x0000 /**< Reserved UUID. */
#define BLE_UUID_SERVICE_PRIMARY 0x2800 /**< Primary Service. */
#define BLE_UUID_SERVICE_SECONDARY 0x2801 /**< Secondary Service. */
#define BLE_UUID_SERVICE_INCLUDE 0x2802 /**< Include. */
#define BLE_UUID_CHARACTERISTIC 0x2803 /**< Characteristic. */
#define BLE_UUID_DESCRIPTOR_CHAR_EXT_PROP 0x2900 /**< Characteristic Extended Properties Descriptor. */
#define BLE_UUID_DESCRIPTOR_CHAR_USER_DESC 0x2901 /**< Characteristic User Description Descriptor. */
#define BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG 0x2902 /**< Client Characteristic Configuration Descriptor. */
#define BLE_UUID_DESCRIPTOR_SERVER_CHAR_CONFIG 0x2903 /**< Server Characteristic Configuration Descriptor. */
#define BLE_UUID_DESCRIPTOR_CHAR_PRESENTATION_FORMAT 0x2904 /**< Characteristic Presentation Format Descriptor. */
#define BLE_UUID_DESCRIPTOR_CHAR_AGGREGATE_FORMAT 0x2905 /**< Characteristic Aggregate Format Descriptor. */
/* GATT specific UUIDs */
#define BLE_UUID_GATT 0x1801 /**< Generic Attribute Profile. */
#define BLE_UUID_GATT_CHARACTERISTIC_SERVICE_CHANGED 0x2A05 /**< Service Changed Characteristic. */
/* GAP specific UUIDs */
#define BLE_UUID_GAP 0x1800 /**< Generic Access Profile. */
#define BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME 0x2A00 /**< Device Name Characteristic. */
#define BLE_UUID_GAP_CHARACTERISTIC_APPEARANCE 0x2A01 /**< Appearance Characteristic. */
#define BLE_UUID_GAP_CHARACTERISTIC_PPF 0x2A02 /**< Peripheral Privacy Flag Characteristic. */
#define BLE_UUID_GAP_CHARACTERISTIC_RECONN_ADDR 0x2A03 /**< Reconnection Address Characteristic. */
#define BLE_UUID_GAP_CHARACTERISTIC_PPCP 0x2A04 /**< Peripheral Preferred Connection Parameters Characteristic. */
/** @} */
/** @defgroup BLE_UUID_TYPES Types of UUID
* @{ */
#define BLE_UUID_TYPE_UNKNOWN 0x00 /**< Invalid UUID type. */
#define BLE_UUID_TYPE_BLE 0x01 /**< Bluetooth SIG UUID (16-bit). */
#define BLE_UUID_TYPE_VENDOR_BEGIN 0x02 /**< Vendor UUID types start at this index (128-bit). */
/** @} */
/** @defgroup BLE_APPEARANCES Bluetooth Appearance values
* @note Retrieved from http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml
* @{ */
#define BLE_APPEARANCE_UNKNOWN 0 /**< Unknown. */
#define BLE_APPEARANCE_GENERIC_PHONE 64 /**< Generic Phone. */
#define BLE_APPEARANCE_GENERIC_COMPUTER 128 /**< Generic Computer. */
#define BLE_APPEARANCE_GENERIC_WATCH 192 /**< Generic Watch. */
#define BLE_APPEARANCE_WATCH_SPORTS_WATCH 193 /**< Watch: Sports Watch. */
#define BLE_APPEARANCE_GENERIC_CLOCK 256 /**< Generic Clock. */
#define BLE_APPEARANCE_GENERIC_DISPLAY 320 /**< Generic Display. */
#define BLE_APPEARANCE_GENERIC_REMOTE_CONTROL 384 /**< Generic Remote Control. */
#define BLE_APPEARANCE_GENERIC_EYE_GLASSES 448 /**< Generic Eye-glasses. */
#define BLE_APPEARANCE_GENERIC_TAG 512 /**< Generic Tag. */
#define BLE_APPEARANCE_GENERIC_KEYRING 576 /**< Generic Keyring. */
#define BLE_APPEARANCE_GENERIC_MEDIA_PLAYER 640 /**< Generic Media Player. */
#define BLE_APPEARANCE_GENERIC_BARCODE_SCANNER 704 /**< Generic Barcode Scanner. */
#define BLE_APPEARANCE_GENERIC_THERMOMETER 768 /**< Generic Thermometer. */
#define BLE_APPEARANCE_THERMOMETER_EAR 769 /**< Thermometer: Ear. */
#define BLE_APPEARANCE_GENERIC_HEART_RATE_SENSOR 832 /**< Generic Heart rate Sensor. */
#define BLE_APPEARANCE_HEART_RATE_SENSOR_HEART_RATE_BELT 833 /**< Heart Rate Sensor: Heart Rate Belt. */
#define BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE 896 /**< Generic Blood Pressure. */
#define BLE_APPEARANCE_BLOOD_PRESSURE_ARM 897 /**< Blood Pressure: Arm. */
#define BLE_APPEARANCE_BLOOD_PRESSURE_WRIST 898 /**< Blood Pressure: Wrist. */
#define BLE_APPEARANCE_GENERIC_HID 960 /**< Human Interface Device (HID). */
#define BLE_APPEARANCE_HID_KEYBOARD 961 /**< Keyboard (HID Subtype). */
#define BLE_APPEARANCE_HID_MOUSE 962 /**< Mouse (HID Subtype). */
#define BLE_APPEARANCE_HID_JOYSTICK 963 /**< Joystiq (HID Subtype). */
#define BLE_APPEARANCE_HID_GAMEPAD 964 /**< Gamepad (HID Subtype). */
#define BLE_APPEARANCE_HID_DIGITIZERSUBTYPE 965 /**< Digitizer Tablet (HID Subtype). */
#define BLE_APPEARANCE_HID_CARD_READER 966 /**< Card Reader (HID Subtype). */
#define BLE_APPEARANCE_HID_DIGITAL_PEN 967 /**< Digital Pen (HID Subtype). */
#define BLE_APPEARANCE_HID_BARCODE 968 /**< Barcode Scanner (HID Subtype). */
#define BLE_APPEARANCE_GENERIC_GLUCOSE_METER 1024 /**< Generic Glucose Meter. */
#define BLE_APPEARANCE_GENERIC_RUNNING_WALKING_SENSOR 1088 /**< Generic Running Walking Sensor. */
#define BLE_APPEARANCE_RUNNING_WALKING_SENSOR_IN_SHOE 1089 /**< Running Walking Sensor: In-Shoe. */
#define BLE_APPEARANCE_RUNNING_WALKING_SENSOR_ON_SHOE 1090 /**< Running Walking Sensor: On-Shoe. */
#define BLE_APPEARANCE_RUNNING_WALKING_SENSOR_ON_HIP 1091 /**< Running Walking Sensor: On-Hip. */
#define BLE_APPEARANCE_GENERIC_CYCLING 1152 /**< Generic Cycling. */
#define BLE_APPEARANCE_CYCLING_CYCLING_COMPUTER 1153 /**< Cycling: Cycling Computer. */
#define BLE_APPEARANCE_CYCLING_SPEED_SENSOR 1154 /**< Cycling: Speed Sensor. */
#define BLE_APPEARANCE_CYCLING_CADENCE_SENSOR 1155 /**< Cycling: Cadence Sensor. */
#define BLE_APPEARANCE_CYCLING_POWER_SENSOR 1156 /**< Cycling: Power Sensor. */
#define BLE_APPEARANCE_CYCLING_SPEED_CADENCE_SENSOR 1157 /**< Cycling: Speed and Cadence Sensor. */
/** @} */
/** @brief Set .type and .uuid fields of ble_uuid_struct to specified uuid value. */
#define BLE_UUID_BLE_ASSIGN(instance, value) do {\
instance.type = BLE_UUID_TYPE_BLE; \
instance.uuid = value;} while(0)
/** @brief Copy type and uuid members from src to dst ble_uuid_t pointer. Both pointers must be valid/non-null. */
#define BLE_UUID_COPY_PTR(dst, src) do {\
(dst)->type = (src)->type; \
(dst)->uuid = (src)->uuid;} while(0)
/** @brief Copy type and uuid members from src to dst ble_uuid_t struct. */
#define BLE_UUID_COPY_INST(dst, src) do {\
(dst).type = (src).type; \
(dst).uuid = (src).uuid;} while(0)
/** @brief Compare for equality both type and uuid members of two (valid, non-null) ble_uuid_t pointers. */
#define BLE_UUID_EQ(p_uuid1, p_uuid2) \
(((p_uuid1)->type == (p_uuid2)->type) && ((p_uuid1)->uuid == (p_uuid2)->uuid))
/** @brief Compare for difference both type and uuid members of two (valid, non-null) ble_uuid_t pointers. */
#define BLE_UUID_NEQ(p_uuid1, p_uuid2) \
(((p_uuid1)->type != (p_uuid2)->type) || ((p_uuid1)->uuid != (p_uuid2)->uuid))
/** @} */
/** @brief 128 bit UUID values. */
typedef struct
{
unsigned char uuid128[16];
} ble_uuid128_t;
/** @brief Bluetooth Low Energy UUID type, encapsulates both 16-bit and 128-bit UUIDs. */
typedef struct
{
uint16_t uuid; /**< 16-bit UUID value or octets 12-13 of 128-bit UUID. */
uint8_t type; /**< UUID type, see @ref BLE_UUID_TYPES. If type is BLE_UUID_TYPE_UNKNOWN, the value of uuid is undefined. */
} ble_uuid_t;
#endif /* BLE_TYPES_H__ */
/**
@}
@}
*/

View File

@ -0,0 +1,51 @@
/*
* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is confidential property of Nordic Semiconductor. The use,
* copying, transfer or disclosure of such information is prohibited except by express written
* agreement with Nordic Semiconductor.
*
*/
/**
@defgroup nrf_error SoftDevice Global Error Codes
@{
@brief Global Error definitions
*/
/* Header guard */
#ifndef NRF_ERROR_H__
#define NRF_ERROR_H__
/** @defgroup NRF_ERRORS_BASE Error Codes Base number definitions
* @{ */
#define NRF_ERROR_BASE_NUM (0x0) ///< Global error base
#define NRF_ERROR_SDM_BASE_NUM (0x1000) ///< SDM error base
#define NRF_ERROR_SOC_BASE_NUM (0x2000) ///< SoC error base
#define NRF_ERROR_STK_BASE_NUM (0x3000) ///< STK error base
/** @} */
#define NRF_SUCCESS (NRF_ERROR_BASE_NUM + 0) ///< Successful command
#define NRF_ERROR_SVC_HANDLER_MISSING (NRF_ERROR_BASE_NUM + 1) ///< SVC handler is missing
#define NRF_ERROR_SOFTDEVICE_NOT_ENABLED (NRF_ERROR_BASE_NUM + 2) ///< SoftDevice has not been enabled
#define NRF_ERROR_INTERNAL (NRF_ERROR_BASE_NUM + 3) ///< Internal Error
#define NRF_ERROR_NO_MEM (NRF_ERROR_BASE_NUM + 4) ///< No Memory for operation
#define NRF_ERROR_NOT_FOUND (NRF_ERROR_BASE_NUM + 5) ///< Not found
#define NRF_ERROR_NOT_SUPPORTED (NRF_ERROR_BASE_NUM + 6) ///< Not supported
#define NRF_ERROR_INVALID_PARAM (NRF_ERROR_BASE_NUM + 7) ///< Invalid Parameter
#define NRF_ERROR_INVALID_STATE (NRF_ERROR_BASE_NUM + 8) ///< Invalid state, operation disallowed in this state
#define NRF_ERROR_INVALID_LENGTH (NRF_ERROR_BASE_NUM + 9) ///< Invalid Length
#define NRF_ERROR_INVALID_FLAGS (NRF_ERROR_BASE_NUM + 10) ///< Invalid Flags
#define NRF_ERROR_INVALID_DATA (NRF_ERROR_BASE_NUM + 11) ///< Invalid Data
#define NRF_ERROR_DATA_SIZE (NRF_ERROR_BASE_NUM + 12) ///< Data size exceeds limit
#define NRF_ERROR_TIMEOUT (NRF_ERROR_BASE_NUM + 13) ///< Operation timed out
#define NRF_ERROR_NULL (NRF_ERROR_BASE_NUM + 14) ///< Null Pointer
#define NRF_ERROR_FORBIDDEN (NRF_ERROR_BASE_NUM + 15) ///< Forbidden Operation
#define NRF_ERROR_INVALID_ADDR (NRF_ERROR_BASE_NUM + 16) ///< Bad Memory Address
#define NRF_ERROR_BUSY (NRF_ERROR_BASE_NUM + 17) ///< Busy
#endif // NRF_ERROR_H__
/**
@}
*/

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is confidential property of Nordic Semiconductor. The use,
* copying, transfer or disclosure of such information is prohibited except by express written
* agreement with Nordic Semiconductor.
*
*/
/**
@addtogroup nrf_sdm_api
@{
@defgroup nrf_sdm_error SoftDevice Manager Error Codes
@{
@brief Error definitions for the SDM API
*/
/* Header guard */
#ifndef NRF_ERROR_SDM_H__
#define NRF_ERROR_SDM_H__
#include "nrf_error.h"
#define NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN (NRF_ERROR_SDM_BASE_NUM + 0) ///< Unknown lfclk source
#define NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION (NRF_ERROR_SDM_BASE_NUM + 1) ///< Incorrect interrupt configuration (can be caused by using illegal priority levels, or having enabled SoftDevice interrupts)
#define NRF_ERROR_SDM_INCORRECT_CLENR0 (NRF_ERROR_SDM_BASE_NUM + 2) ///< Incorrect CLENR0 (can be caused by erronous SoftDevice flashing)
#endif // NRF_ERROR_SDM_H__
/**
@}
@}
*/

View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is confidential property of Nordic Semiconductor. The use,
* copying, transfer or disclosure of such information is prohibited except by express written
* agreement with Nordic Semiconductor.
*
*/
/**
@addtogroup nrf_soc_api
@{
@defgroup nrf_soc_error SoC Library Error Codes
@{
@brief Error definitions for the SoC library
*/
/* Header guard */
#ifndef NRF_ERROR_SOC_H__
#define NRF_ERROR_SOC_H__
#include "nrf_error.h"
/* Mutex Errors */
#define NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN (NRF_ERROR_SOC_BASE_NUM + 0) ///< Mutex already taken
/* NVIC errors */
#define NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE (NRF_ERROR_SOC_BASE_NUM + 1) ///< NVIC interrupt not available
#define NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED (NRF_ERROR_SOC_BASE_NUM + 2) ///< NVIC interrupt priority not allowed
#define NRF_ERROR_SOC_NVIC_SHOULD_NOT_RETURN (NRF_ERROR_SOC_BASE_NUM + 3) ///< NVIC should not return
/* Power errors */
#define NRF_ERROR_SOC_POWER_MODE_UNKNOWN (NRF_ERROR_SOC_BASE_NUM + 4) ///< Power mode unknown
#define NRF_ERROR_SOC_POWER_POF_THRESHOLD_UNKNOWN (NRF_ERROR_SOC_BASE_NUM + 5) ///< Power POF threshold unknown
#define NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN (NRF_ERROR_SOC_BASE_NUM + 6) ///< Power off should not return
/* Rand errors */
#define NRF_ERROR_SOC_RAND_NOT_ENOUGH_VALUES (NRF_ERROR_SOC_BASE_NUM + 7) ///< RAND not enough values
/* PPI errors */
#define NRF_ERROR_SOC_PPI_INVALID_CHANNEL (NRF_ERROR_SOC_BASE_NUM + 8) ///< Invalid PPI Channel
#define NRF_ERROR_SOC_PPI_INVALID_GROUP (NRF_ERROR_SOC_BASE_NUM + 9) ///< Invalid PPI Group
#endif // NRF_ERROR_SOC_H__
/**
@}
@}
*/

View File

@ -0,0 +1,163 @@
/*
* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is confidential property of Nordic Semiconductor. The use,
* copying, transfer or disclosure of such information is prohibited except by express written
* agreement with Nordic Semiconductor.
*
*/
/**
@defgroup nrf_sdm_api SoftDevice Manager API
@{
@brief APIs for SoftDevice management.
*/
/* Header guard */
#ifndef NRF_SDM_H__
#define NRF_SDM_H__
#include "nrf_svc.h"
#include "nrf51.h"
#include "nrf_soc.h"
#include "nrf_error_sdm.h"
/** @addtogroup NRF_SDM_DEFINES Defines
* @{ */
/**@brief SoftDevice Manager SVC Base number. */
#define SDM_SVC_BASE 0x10
/** @} */
/** @addtogroup NRF_SDM_ENUMS Enumerations
* @{ */
/**@brief nRF SoftDevice Manager API SVC numbers. */
enum NRF_SD_SVCS
{
SD_SOFTDEVICE_ENABLE = SDM_SVC_BASE, /**< ::sd_softdevice_enable */
SD_SOFTDEVICE_DISABLE, /**< ::sd_softdevice_disable */
SD_SOFTDEVICE_IS_ENABLED, /**< ::sd_softdevice_is_enabled */
SD_SOFTDEVICE_FORWARD_TO_APPLICATION,/**< ::sd_softdevice_forward_to_application */
SVC_SDM_LAST /**< Placeholder for last SDM SVC */
};
/**@brief Possible lfclk oscillator sources. */
enum NRF_CLOCK_LFCLKSRCS
{
NRF_CLOCK_LFCLKSRC_SYNTH_250_PPM, /**< LFCLK Synthesized from HFCLK. */
NRF_CLOCK_LFCLKSRC_XTAL_500_PPM, /**< LFCLK crystal oscillator 500 PPM accuracy. */
NRF_CLOCK_LFCLKSRC_XTAL_250_PPM, /**< LFCLK crystal oscillator 250 PPM accuracy. */
NRF_CLOCK_LFCLKSRC_XTAL_150_PPM, /**< LFCLK crystal oscillator 150 PPM accuracy. */
NRF_CLOCK_LFCLKSRC_XTAL_100_PPM, /**< LFCLK crystal oscillator 100 PPM accuracy. */
NRF_CLOCK_LFCLKSRC_XTAL_75_PPM, /**< LFCLK crystal oscillator 75 PPM accuracy. */
NRF_CLOCK_LFCLKSRC_XTAL_50_PPM, /**< LFCLK crystal oscillator 50 PPM accuracy. */
NRF_CLOCK_LFCLKSRC_XTAL_30_PPM, /**< LFCLK crystal oscillator 30 PPM accuracy. */
NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, /**< LFCLK crystal oscillator 20 PPM accuracy. */
NRF_CLOCK_LFCLKSRC_RC_250_PPM_250MS_CALIBRATION, /**< LFCLK RC oscillator, 250ms calibration interval.*/
NRF_CLOCK_LFCLKSRC_RC_250_PPM_500MS_CALIBRATION, /**< LFCLK RC oscillator, 500ms calibration interval.*/
NRF_CLOCK_LFCLKSRC_RC_250_PPM_1000MS_CALIBRATION, /**< LFCLK RC oscillator, 1000ms calibration interval.*/
NRF_CLOCK_LFCLKSRC_RC_250_PPM_2000MS_CALIBRATION, /**< LFCLK RC oscillator, 2000ms calibration interval.*/
NRF_CLOCK_LFCLKSRC_RC_250_PPM_4000MS_CALIBRATION, /**< LFCLK RC oscillator, 4000ms calibration interval.*/
NRF_CLOCK_LFCLKSRC_RC_250_PPM_8000MS_CALIBRATION, /**< LFCLK RC oscillator, 8000ms calibration interval.*/
};
/** @} */
/** @addtogroup NRF_SDM_TYPES Types
* @{ */
/**@brief Type representing lfclk oscillator source. */
typedef uint32_t nrf_clock_lfclksrc_t;
/**@brief SoftDevice Assertion Handler type.
*
* When an unexpected error occurs within the SoftDevice it will call the SoftDevice assertion handler callback.
* The protocol stack will be in an undefined state when this happens and the only way to recover will be to
* perform a reset, using e.g. CMSIS NVIC_SystemReset().
*
* @note This callback is executed in HardFault context, thus SVC functions cannot be called from the SoftDevice assert callback.
*
* @param[in] pc The program counter of the failed assert.
* @param[in] line_number Line number where the assert failed.
* @param[in] file_name File name where the assert failed.
*/
typedef void (*softdevice_assertion_handler_t)(uint32_t pc, uint16_t line_number, const uint8_t * p_file_name);
/** @} */
/** @addtogroup NRF_SDM_FUNCTIONS Functions
* @{ */
/**@brief Enables the SoftDevice and by extension the protocol stack.
*
* Idempotent function to enable the SoftDevice.
*
* @note Some care must be taken if a low frequency clock source is already running when calling this function:
* If the LF clock has a different source then the one currently running, it will be stopped. Then, the new
* clock source will be started.
*
* @note This function has no effect when returning with an error.
*
* @post If return code is ::NRF_SUCCESS
* - SoC library and protocol stack APIs are made available
* - A portion of RAM will be unavailable (see relevant SDS documentation)
* - Some peripherals will be unavailable or available only through the SoC API (see relevant SDS documentation)
* - Interrupts will not arrive from protected peripherals or interrupts
* - nrf_nvic_ functions must be used instead of CMSIS NVIC_ functions for reliable usage of the softdevice.
* - Interrupt latency may be affected by the SoftDevice (see relevant SDS documentation)
* - Chosen low frequency clock source will be running
*
* @param clock_source Low frequency clock source and accuracy. (Note: In the case of XTAL source, the PPM accuracy of the chosen clock source must be greater than or equal to the actual characteristics of your XTAL clock).
* @param assertion_handler Callback for SoftDevice assertions.
*
* @retval ::NRF_SUCCESS
* @retval ::NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION SoftDeviceinterrupt is already enabled, or an enabled interrupt has an illegal priority level
* @retval ::NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN Unknown low frequency clock source selected
*/
SVCALL(SD_SOFTDEVICE_ENABLE, uint32_t, sd_softdevice_enable(nrf_clock_lfclksrc_t clock_source, softdevice_assertion_handler_t assertion_handler));
/**@brief Disables the SoftDevice and by extension the protocol stack.
*
* Idempotent function to disable the SoftDevice.
*
* @post SoC library and protocol stack APIs are made unavailable.
* @post All interrupts that was protected by the SoftDevice will be disabled and initialized to priority 0 (highest).
* @post All peripherals used by the SoftDevice will be reset to default values.
* @post All of RAM become available.
* @post All interrupts are forwarded to the application.
* @post LFCLK source chosen in ::sd_softdevice_enable will be left running.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_SOFTDEVICE_DISABLE, uint32_t, sd_softdevice_disable(void));
/**@brief Check if the SoftDevice is enabled.
*
* @param[out] p_softdevice_enabled If the SoftDevice is enabled: 1 else 0.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_SOFTDEVICE_IS_ENABLED, uint32_t, sd_softdevice_is_enabled(uint8_t * p_softdevice_enabled));
/**@brief Start forwarding interrupts to application.
*
* This function is only intended to be called when a bootloader is enabled is used.
* The bootloader should call this right before it starts the application.
* It is recommended that all interrupt sources are off when this is called,
* or you could end up having interrupts in the application being executed before main() of the application.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_SOFTDEVICE_FORWARD_TO_APPLICATION, uint32_t, sd_softdevice_forward_to_application(void));
/** @} */
#endif // NRF_SDM_H__
/**
@}
*/

View File

@ -0,0 +1,777 @@
/* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is confidential property of Nordic Semiconductor. The use,
* copying, transfer or disclosure of such information is prohibited except by express written
* agreement with Nordic Semiconductor.
*
*/
/**
@defgroup nrf_soc_api SoC Library API
@{
@brief APIs for the SoC library.
*/
#ifndef NRF_SOC_H__
#define NRF_SOC_H__
#include <stdint.h>
#include <stdbool.h>
#include "nrf_svc.h"
#include "nrf51.h"
#include "nrf51_bitfields.h"
#include "nrf_error_soc.h"
/** @addtogroup NRF_SOC_DEFINES Defines
* @{ */
/**@brief The number of the lowest SVC number reserved for the SoC library. */
#define SOC_SVC_BASE 0x20
/**@brief Guranteed time for application to process radio inactive notification. */
#define NRF_RADIO_NOTIFICATION_INACTIVE_GUARANTEED_TIME_US (62)
#define SOC_ECB_KEY_LENGTH (16) /**< ECB key length. */
#define SOC_ECB_CLEARTEXT_LENGTH (16) /**< ECB cleartext length. */
#define SOC_ECB_CIPHERTEXT_LENGTH (SOC_ECB_CLEARTEXT_LENGTH) /**< ECB ciphertext length. */
#define SD_EVT_IRQn (SWI2_IRQn) /**< SoftDevice Event IRQ number. Used for both protocol events and SoC events. */
#define SD_EVT_IRQHandler (SWI2_IRQHandler) /**< SoftDevice Event IRQ handler. Used for both protocol events and SoC events. */
#define RADIO_NOTIFICATION_IRQn (SWI1_IRQn) /**< The radio notification IRQ number. */
#define RADIO_NOTIFICATION_IRQHandler (SWI1_IRQHandler) /**< The radio notification IRQ handler. */
/** @} */
/** @addtogroup NRF_SOC_TYPES Types
* @{ */
/**@brief The SVC numbers used by the SVC functions in the SoC library. */
enum NRF_SOC_SVCS
{
SD_MUTEX_NEW = SOC_SVC_BASE,
SD_MUTEX_ACQUIRE,
SD_MUTEX_RELEASE,
SD_NVIC_ENABLEIRQ,
SD_NVIC_DISABLEIRQ,
SD_NVIC_GETPENDINGIRQ,
SD_NVIC_SETPENDINGIRQ,
SD_NVIC_CLEARPENDINGIRQ,
SD_NVIC_SETPRIORITY,
SD_NVIC_GETPRIORITY,
SD_NVIC_SYSTEMRESET,
SD_NVIC_CRITICAL_REGION_ENTER,
SD_NVIC_CRITICAL_REGION_EXIT,
SD_RAND_APPLICATION_POOL_CAPACITY,
SD_RAND_APPLICATION_BYTES_AVAILABLE,
SD_RAND_APPLICATION_GET_VECTOR,
SD_POWER_MODE_SET,
SD_POWER_SYSTEM_OFF,
SD_POWER_RESET_REASON_GET,
SD_POWER_RESET_REASON_CLR,
SD_POWER_POF_ENABLE,
SD_POWER_POF_THRESHOLD_SET,
SD_POWER_RAMON_SET,
SD_POWER_RAMON_CLR,
SD_POWER_RAMON_GET,
SD_POWER_GPREGRET_SET,
SD_POWER_GPREGRET_CLR,
SD_POWER_GPREGRET_GET,
SD_POWER_DCDC_MODE_SET,
SD_APP_EVT_WAIT,
SD_CLOCK_HFCLK_REQUEST,
SD_CLOCK_HFCLK_RELEASE,
SD_CLOCK_HFCLK_IS_RUNNING,
SD_PPI_CHANNEL_ENABLE_GET,
SD_PPI_CHANNEL_ENABLE_SET,
SD_PPI_CHANNEL_ENABLE_CLR,
SD_PPI_CHANNEL_ASSIGN,
SD_PPI_GROUP_TASK_ENABLE,
SD_PPI_GROUP_TASK_DISABLE,
SD_PPI_GROUP_ASSIGN,
SD_PPI_GROUP_GET,
SD_RADIO_NOTIFICATION_CFG_SET,
SD_ECB_BLOCK_ENCRYPT,
SD_RESERVED1,
SD_RESERVED2,
SD_RESERVED3,
SD_EVT_GET,
SD_TEMP_GET,
SD_FLASH_ERASE_PAGE,
SD_FLASH_WRITE,
SD_FLASH_PROTECT,
SVC_SOC_LAST
};
/**@brief Possible values of a ::nrf_mutex_t. */
enum NRF_MUTEX_VALUES
{
NRF_MUTEX_FREE,
NRF_MUTEX_TAKEN
};
/**@brief Possible values of ::nrf_app_irq_priority_t. */
enum NRF_APP_PRIORITIES
{
NRF_APP_PRIORITY_HIGH = 1,
NRF_APP_PRIORITY_LOW = 3
};
/**@brief Possible values of ::nrf_power_mode_t. */
enum NRF_POWER_MODES
{
NRF_POWER_MODE_CONSTLAT, /**< Constant latency mode. See power management in the reference manual. */
NRF_POWER_MODE_LOWPWR /**< Low power mode. See power management in the reference manual. */
};
/**@brief Possible values of ::nrf_power_failure_threshold_t */
enum NRF_POWER_THRESHOLDS
{
NRF_POWER_THRESHOLD_V21, /**< 2.1 Volts power failure threshold. */
NRF_POWER_THRESHOLD_V23, /**< 2.3 Volts power failure threshold. */
NRF_POWER_THRESHOLD_V25, /**< 2.5 Volts power failure threshold. */
NRF_POWER_THRESHOLD_V27 /**< 2.7 Volts power failure threshold. */
};
/**@brief Possible values of ::nrf_power_dcdc_mode_t. */
enum NRF_POWER_DCDC_MODES
{
NRF_POWER_DCDC_MODE_OFF, /**< The DCDC is always off. */
NRF_POWER_DCDC_MODE_ON, /**< The DCDC is always on. */
NRF_POWER_DCDC_MODE_AUTOMATIC /**< The DCDC is automatically managed. */
};
/**@brief Possible values of ::nrf_radio_notification_distance_t. */
enum NRF_RADIO_NOTIFICATION_DISTANCES
{
NRF_RADIO_NOTIFICATION_DISTANCE_NONE = 0, /**< The event does not have a notification. */
NRF_RADIO_NOTIFICATION_DISTANCE_800US, /**< The distance from the active notification to start of radio activity. */
NRF_RADIO_NOTIFICATION_DISTANCE_1740US, /**< The distance from the active notification to start of radio activity. */
NRF_RADIO_NOTIFICATION_DISTANCE_2680US, /**< The distance from the active notification to start of radio activity. */
NRF_RADIO_NOTIFICATION_DISTANCE_3620US, /**< The distance from the active notification to start of radio activity. */
NRF_RADIO_NOTIFICATION_DISTANCE_4560US, /**< The distance from the active notification to start of radio activity. */
NRF_RADIO_NOTIFICATION_DISTANCE_5500US /**< The distance from the active notification to start of radio activity. */
};
/**@brief Possible values of ::nrf_radio_notification_type_t. */
enum NRF_RADIO_NOTIFICATION_TYPES
{
NRF_RADIO_NOTIFICATION_TYPE_NONE = 0, /**< The event does not have a radio notification signal. */
NRF_RADIO_NOTIFICATION_TYPE_INT_ON_ACTIVE, /**< Using interrupt for notification when the radio will be enabled. */
NRF_RADIO_NOTIFICATION_TYPE_INT_ON_INACTIVE, /**< Using interrupt for notification when the radio has been disabled. */
NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH, /**< Using interrupt for notification both when the radio will be enabled and disabled. */
};
/**@brief SoC Events. */
enum NRF_SOC_EVTS
{
NRF_EVT_HFCLKSTARTED, /**< Event indicating that the HFCLK has started. */
NRF_EVT_POWER_FAILURE_WARNING, /**< Event indicating that a power failure warning has occurred. */
NRF_EVT_FLASH_OPERATION_SUCCESS, /**< Event indicating that the ongoing flash operation has completed successfully. */
NRF_EVT_FLASH_OPERATION_ERROR, /**< Event indicating that the ongoing flash operation has timed out with an error. */
NRF_EVT_RESERVED1,
NRF_EVT_RESERVED2,
NRF_EVT_RESERVED3,
NRF_EVT_RESERVED4,
NRF_EVT_RESERVED5,
NRF_EVT_NUMBER_OF_EVTS
};
/** @} */
/** @addtogroup NRF_SOC_TYPES Types
* @{ */
/**@brief Represents a mutex for use with the nrf_mutex functions.
* @note Accessing the value directly is not safe, use the mutex functions!
*/
typedef volatile uint8_t nrf_mutex_t;
/**@brief The interrupt priorities available to the application while the softdevice is active. */
typedef uint8_t nrf_app_irq_priority_t;
/**@brief Represents a power mode, used in power mode functions */
typedef uint8_t nrf_power_mode_t;
/**@brief Represents a power failure threshold value. */
typedef uint8_t nrf_power_failure_threshold_t;
/**@brief Represents a DCDC mode value. */
typedef uint32_t nrf_power_dcdc_mode_t;
/**@brief Radio notification distances. */
typedef uint8_t nrf_radio_notification_distance_t;
/**@brief Radio notification types. */
typedef uint8_t nrf_radio_notification_type_t;
/**@brief AES ECB data structure */
typedef struct
{
uint8_t key[SOC_ECB_KEY_LENGTH]; /**< Encryption key. */
uint8_t cleartext[SOC_ECB_CLEARTEXT_LENGTH]; /**< Clear Text data. */
uint8_t ciphertext[SOC_ECB_CIPHERTEXT_LENGTH]; /**< Cipher Text data. */
} nrf_ecb_hal_data_t;
/** @} */
/** @addtogroup NRF_SOC_FUNCTIONS Functions
* @{ */
/**@brief Initialize a mutex.
*
* @param[in] p_mutex Pointer to the mutex to initialize.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_MUTEX_NEW, uint32_t, sd_mutex_new(nrf_mutex_t * p_mutex));
/**@brief Attempt to acquire a mutex.
*
* @param[in] p_mutex Pointer to the mutex to acquire.
*
* @retval ::NRF_SUCCESS The mutex was successfully acquired.
* @retval ::NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN The mutex could not be acquired.
*/
SVCALL(SD_MUTEX_ACQUIRE, uint32_t, sd_mutex_acquire(nrf_mutex_t * p_mutex));
/**@brief Release a mutex.
*
* @param[in] p_mutex Pointer to the mutex to release.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_MUTEX_RELEASE, uint32_t, sd_mutex_release(nrf_mutex_t * p_mutex));
/**@brief Enable External Interrupt.
* @note Corresponds to NVIC_EnableIRQ in CMSIS.
*
* @pre{IRQn is valid and not reserved by the stack}
*
* @param[in] IRQn See the NVIC_EnableIRQ documentation in CMSIS.
*
* @retval ::NRF_SUCCESS The interrupt was enabled.
* @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE The interrupt is not available for the application.
* @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED The interrupt has a priority not available for the application.
*/
SVCALL(SD_NVIC_ENABLEIRQ, uint32_t, sd_nvic_EnableIRQ(IRQn_Type IRQn));
/**@brief Disable External Interrupt.
* @note Corresponds to NVIC_DisableIRQ in CMSIS.
*
* @pre{IRQn is valid and not reserved by the stack}
*
* @param[in] IRQn See the NVIC_DisableIRQ documentation in CMSIS
*
* @retval ::NRF_SUCCESS The interrupt was disabled.
* @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE The interrupt is not available for the application.
*/
SVCALL(SD_NVIC_DISABLEIRQ, uint32_t, sd_nvic_DisableIRQ(IRQn_Type IRQn));
/**@brief Get Pending Interrupt.
* @note Corresponds to NVIC_GetPendingIRQ in CMSIS.
*
* @pre{IRQn is valid and not reserved by the stack}
*
* @param[in] IRQn See the NVIC_GetPendingIRQ documentation in CMSIS.
* @param[out] p_pending_irq Return value from NVIC_GetPendingIRQ.
*
* @retval ::NRF_SUCCESS The interrupt is available for the application.
* @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE IRQn is not available for the application.
*/
SVCALL(SD_NVIC_GETPENDINGIRQ, uint32_t, sd_nvic_GetPendingIRQ(IRQn_Type IRQn, uint32_t * p_pending_irq));
/**@brief Set Pending Interrupt.
* @note Corresponds to NVIC_SetPendingIRQ in CMSIS.
*
* @pre{IRQn is valid and not reserved by the stack}
*
* @param[in] IRQn See the NVIC_SetPendingIRQ documentation in CMSIS.
*
* @retval ::NRF_SUCCESS The interrupt is set pending.
* @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE IRQn is not available for the application.
*/
SVCALL(SD_NVIC_SETPENDINGIRQ, uint32_t, sd_nvic_SetPendingIRQ(IRQn_Type IRQn));
/**@brief Clear Pending Interrupt.
* @note Corresponds to NVIC_ClearPendingIRQ in CMSIS.
*
* @pre{IRQn is valid and not reserved by the stack}
*
* @param[in] IRQn See the NVIC_ClearPendingIRQ documentation in CMSIS.
*
* @retval ::NRF_SUCCESS The interrupt pending flag is cleared.
* @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE IRQn is not available for the application.
*/
SVCALL(SD_NVIC_CLEARPENDINGIRQ, uint32_t, sd_nvic_ClearPendingIRQ(IRQn_Type IRQn));
/**@brief Set Interrupt Priority.
* @note Corresponds to NVIC_SetPriority in CMSIS.
*
* @pre{IRQn is valid and not reserved by the stack}
* @pre{priority is valid and not reserved by the stack}
*
* @param[in] IRQn See the NVIC_SetPriority documentation in CMSIS.
* @param[in] priority A valid IRQ priority for use by the application.
*
* @retval ::NRF_SUCCESS The interrupt and priority level is available for the application.
* @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE IRQn is not available for the application.
* @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED The interrupt priority is not available for the application.
*/
SVCALL(SD_NVIC_SETPRIORITY, uint32_t, sd_nvic_SetPriority(IRQn_Type IRQn, nrf_app_irq_priority_t priority));
/**@brief Get Interrupt Priority.
* @note Corresponds to NVIC_GetPriority in CMSIS.
*
* @pre{IRQn is valid and not reserved by the stack}
*
* @param[in] IRQn See the NVIC_GetPriority documentation in CMSIS.
* @param[out] p_priority Return value from NVIC_GetPriority.
*
* @retval ::NRF_SUCCESS The interrupt priority is returned in p_priority.
* @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE - IRQn is not available for the application.
*/
SVCALL(SD_NVIC_GETPRIORITY, uint32_t, sd_nvic_GetPriority(IRQn_Type IRQn, nrf_app_irq_priority_t * p_priority));
/**@brief System Reset.
* @note Corresponds to NVIC_SystemReset in CMSIS.
*
* @retval ::NRF_ERROR_SOC_NVIC_SHOULD_NOT_RETURN
*/
SVCALL(SD_NVIC_SYSTEMRESET, uint32_t, sd_nvic_SystemReset(void));
/**@brief Enters critical region.
*
* @post Application interrupts will be disabled.
* @sa sd_nvic_critical_region_exit
*
* @param[out] p_is_nested_critical_region 1: If in a nested critical region.
* 0: Otherwise.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_NVIC_CRITICAL_REGION_ENTER, uint32_t, sd_nvic_critical_region_enter(uint8_t * p_is_nested_critical_region));
/**@brief Exit critical region.
*
* @pre Application has entered a critical region using ::sd_nvic_critical_region_enter.
* @post If not in a nested critical region, the application interrupts will restored to the state before ::sd_nvic_critical_region_enter was called.
*
* @param[in] is_nested_critical_region If this is set to 1, the critical region won't be exited. @sa sd_nvic_critical_region_enter.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_NVIC_CRITICAL_REGION_EXIT, uint32_t, sd_nvic_critical_region_exit(uint8_t is_nested_critical_region));
/**@brief Query the capacity of the application random pool.
*
* @param[out] p_pool_capacity The capacity of the pool.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_RAND_APPLICATION_POOL_CAPACITY, uint32_t, sd_rand_application_pool_capacity_get(uint8_t * p_pool_capacity));
/**@brief Get number of random bytes available to the application.
*
* @param[out] p_bytes_available The number of bytes currently available in the pool.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_RAND_APPLICATION_BYTES_AVAILABLE, uint32_t, sd_rand_application_bytes_available_get(uint8_t * p_bytes_available));
/**@brief Get random bytes from the application pool.
@param[out] p_buff Pointer to unit8_t buffer for storing the bytes.
@param[in] length Number of bytes to take from pool and place in p_buff.
@retval ::NRF_SUCCESS The requested bytes were written to p_buff.
@retval ::NRF_ERROR_SOC_RAND_NOT_ENOUGH_VALUES No bytes were written to the buffer, because there were not enough bytes available.
*/
SVCALL(SD_RAND_APPLICATION_GET_VECTOR, uint32_t, sd_rand_application_vector_get(uint8_t * p_buff, uint8_t length));
/**@brief Gets the reset reason register.
*
* @param[out] p_reset_reason Contents of the NRF_POWER->RESETREAS register.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_POWER_RESET_REASON_GET, uint32_t, sd_power_reset_reason_get(uint32_t * p_reset_reason));
/**@brief Clears the bits of the reset reason register.
*
* @param[in] reset_reason_clr_msk Contains the bits to clear from the reset reason register.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_POWER_RESET_REASON_CLR, uint32_t, sd_power_reset_reason_clr(uint32_t reset_reason_clr_msk));
/**@brief Sets the power mode when in CPU sleep.
*
* @param[in] power_mode The power mode to use when in CPU sleep. @sa sd_app_evt_wait
*
* @retval ::NRF_SUCCESS The power mode was set.
* @retval ::NRF_ERROR_SOC_POWER_MODE_UNKNOWN The power mode was unknown.
*/
SVCALL(SD_POWER_MODE_SET, uint32_t, sd_power_mode_set(nrf_power_mode_t power_mode));
/**@brief Puts the chip in System OFF mode.
*
* @retval ::NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN
*/
SVCALL(SD_POWER_SYSTEM_OFF, uint32_t, sd_power_system_off(void));
/**@brief Enables or disables the power-fail comparator.
*
* Enabling this will give a softdevice event (NRF_EVT_POWER_FAILURE_WARNING) when the power failure warning occurs.
* The event can be retrieved with sd_evt_get();
*
* @param[in] pof_enable True if the power-fail comparator should be enabled, false if it should be disabled.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_POWER_POF_ENABLE, uint32_t, sd_power_pof_enable(uint8_t pof_enable));
/**@brief Sets the power-fail threshold value.
*
* @param[in] threshold The power-fail threshold value to use.
*
* @retval ::NRF_SUCCESS The power failure threshold was set.
* @retval ::NRF_ERROR_SOC_POWER_POF_THRESHOLD_UNKNOWN The power failure threshold is unknown.
*/
SVCALL(SD_POWER_POF_THRESHOLD_SET, uint32_t, sd_power_pof_threshold_set(nrf_power_failure_threshold_t threshold));
/**@brief Sets bits in the NRF_POWER->RAMON register.
*
* @param[in] ramon Contains the bits needed to be set in the NRF_POWER->RAMON register.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_POWER_RAMON_SET, uint32_t, sd_power_ramon_set(uint32_t ramon));
/** @brief Clears bits in the NRF_POWER->RAMON register.
*
* @param ramon Contains the bits needed to be cleared in the NRF_POWER->RAMON register.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_POWER_RAMON_CLR, uint32_t, sd_power_ramon_clr(uint32_t ramon));
/**@brief Get contents of NRF_POWER->RAMON register, indicates power status of ram blocks.
*
* @param[out] p_ramon Content of NRF_POWER->RAMON register.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_POWER_RAMON_GET, uint32_t, sd_power_ramon_get(uint32_t * p_ramon));
/**@brief Set bits in the NRF_POWER->GPREGRET register.
*
* @param[in] gpregret_msk Bits to be set in the GPREGRET register.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_POWER_GPREGRET_SET, uint32_t, sd_power_gpregret_set(uint32_t gpregret_msk));
/**@brief Clear bits in the NRF_POWER->GPREGRET register.
*
* @param[in] gpregret_msk Bits to be clear in the GPREGRET register.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_POWER_GPREGRET_CLR, uint32_t, sd_power_gpregret_clr(uint32_t gpregret_msk));
/**@brief Get contents of the NRF_POWER->GPREGRET register.
*
* @param[out] p_gpregret Contents of the GPREGRET register.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_POWER_GPREGRET_GET, uint32_t, sd_power_gpregret_get(uint32_t *p_gpregret));
/**@brief Sets the DCDC mode.
*
* Depending on the internal state of the SoftDevice, the mode change may not happen immediately.
* The DCDC mode switch will be blocked when occurring in close proximity to radio transmissions. When
* the radio transmission is done, the last mode will be used.
*
* @param[in] dcdc_mode The mode of the DCDC.
*
* @retval ::NRF_SUCCESS
* @retval ::NRF_ERROR_INVALID_PARAM The DCDC mode is invalid.
*/
SVCALL(SD_POWER_DCDC_MODE_SET, uint32_t, sd_power_dcdc_mode_set(nrf_power_dcdc_mode_t dcdc_mode));
/**@brief Request the high frequency crystal oscillator.
*
* Will start the high frequency crystal oscillator, the startup time of the crystal varies
* and the ::sd_clock_hfclk_is_running function can be polled to check if it has started.
*
* @see sd_clock_hfclk_is_running
* @see sd_clock_hfclk_release
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_CLOCK_HFCLK_REQUEST, uint32_t, sd_clock_hfclk_request(void));
/**@brief Releases the high frequency crystal oscillator.
*
* Will stop the high frequency crystal oscillator, this happens immediately.
*
* @see sd_clock_hfclk_is_running
* @see sd_clock_hfclk_request
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_CLOCK_HFCLK_RELEASE, uint32_t, sd_clock_hfclk_release(void));
/**@brief Checks if the high frequency crystal oscillator is running.
*
* @see sd_clock_hfclk_request
* @see sd_clock_hfclk_release
*
* @param[out] p_is_running 1 if the external crystal oscillator is running, 0 if not.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_CLOCK_HFCLK_IS_RUNNING, uint32_t, sd_clock_hfclk_is_running(uint32_t * p_is_running));
/**@brief Waits for an application event.
*
* An application event is either an application interrupt or a pended interrupt when the
* interrupt is disabled. When the interrupt is enabled it will be taken immediately since
* this function will wait in thread mode, then the execution will return in the application's
* main thread. When an interrupt is disabled and gets pended it will return to the application's
* thread main. The application must ensure that the pended flag is cleared using
* ::sd_nvic_ClearPendingIRQ in order to sleep using this function. This is only necessary for
* disabled interrupts, as the interrupt handler will clear the pending flag automatically for
* enabled interrupts.
*
* In order to wake up from disabled interrupts, the SEVONPEND flag has to be set in the Cortex-M0
* System Control Register (SCR). @sa CMSIS_SCB
*
* @note If an application interrupt has happened since the last time sd_app_evt_wait was
* called this function will return immediately and not go to sleep. This is to avoid race
* conditions that can occur when a flag is updated in the interrupt handler and processed
* in the main loop.
*
* @post An application interrupt has happened or a interrupt pending flag is set.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_APP_EVT_WAIT, uint32_t, sd_app_evt_wait(void));
/**@brief Get PPI channel enable register contents.
*
* @param[out] p_channel_enable The contents of the PPI CHEN register.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_PPI_CHANNEL_ENABLE_GET, uint32_t, sd_ppi_channel_enable_get(uint32_t * p_channel_enable));
/**@brief Set PPI channel enable register.
*
* @param[in] channel_enable_set_msk Mask containing the bits to set in the PPI CHEN register.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_PPI_CHANNEL_ENABLE_SET, uint32_t, sd_ppi_channel_enable_set(uint32_t channel_enable_set_msk));
/**@brief Clear PPI channel enable register.
*
* @param[in] channel_enable_clr_msk Mask containing the bits to clear in the PPI CHEN register.
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_PPI_CHANNEL_ENABLE_CLR, uint32_t, sd_ppi_channel_enable_clr(uint32_t channel_enable_clr_msk));
/**@brief Assign endpoints to a PPI channel.
*
* @param[in] channel_num Number of the PPI channel to assign.
* @param[in] evt_endpoint Event endpoint of the PPI channel.
* @param[in] task_endpoint Task endpoint of the PPI channel.
*
* @retval ::NRF_ERROR_SOC_PPI_INVALID_CHANNEL The channel number is invalid.
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_PPI_CHANNEL_ASSIGN, uint32_t, sd_ppi_channel_assign(uint8_t channel_num, const volatile void * evt_endpoint, const volatile void * task_endpoint));
/**@brief Task to enable a channel group.
*
* @param[in] group_num Number of the channel group.
*
* @retval ::NRF_ERROR_SOC_PPI_INVALID_GROUP The group number is invalid
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_PPI_GROUP_TASK_ENABLE, uint32_t, sd_ppi_group_task_enable(uint8_t group_num));
/**@brief Task to disable a channel group.
*
* @param[in] group_num Number of the PPI group.
*
* @retval ::NRF_ERROR_SOC_PPI_INVALID_GROUP The group number is invalid.
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_PPI_GROUP_TASK_DISABLE, uint32_t, sd_ppi_group_task_disable(uint8_t group_num));
/**@brief Assign PPI channels to a channel group.
*
* @param[in] group_num Number of the channel group.
* @param[in] channel_msk Mask of the channels to assign to the group.
*
* @retval ::NRF_ERROR_SOC_PPI_INVALID_GROUP The group number is invalid.
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_PPI_GROUP_ASSIGN, uint32_t, sd_ppi_group_assign(uint8_t group_num, uint32_t channel_msk));
/**@brief Gets the PPI channels of a channel group.
*
* @param[in] group_num Number of the channel group.
* @param[out] p_channel_msk Mask of the channels assigned to the group.
*
* @retval ::NRF_ERROR_SOC_PPI_INVALID_GROUP The group number is invalid.
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_PPI_GROUP_GET, uint32_t, sd_ppi_group_get(uint8_t group_num, uint32_t * p_channel_msk));
/**@brief Configures the Radio Notification signal.
*
* @note
* - The notification signal latency depends on the interrupt priority settings of SWI used
* for notification signal.
* - In the period between the ACTIVE signal and the start of the Radio Event, the SoftDevice
* will interrupt the application to do Radio Event preparation.
* - Using the Radio Notification feature may limit the bandwidth, as the SoftDevice may have
* to shorten the connection events to have time for the Radio Notification signals.
*
* @param[in] type Type of notification signal.
* @ref NRF_RADIO_NOTIFICATION_TYPE_NONE shall be used to turn off radio
* notification. Using @ref NRF_RADIO_NOTIFICATION_DISTANCE_NONE is
* recommended (but not required) to be used with
* @ref NRF_RADIO_NOTIFICATION_TYPE_NONE.
*
* @param[in] distance Distance between the notification signal and start of radio activity.
* This parameter is ignored when @ref NRF_RADIO_NOTIFICATION_TYPE_NONE or
* @ref NRF_RADIO_NOTIFICATION_TYPE_INT_ON_INACTIVE is used.
*
* @retval ::NRF_ERROR_INVALID_PARAM The group number is invalid.
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_RADIO_NOTIFICATION_CFG_SET, uint32_t, sd_radio_notification_cfg_set(nrf_radio_notification_type_t type, nrf_radio_notification_distance_t distance));
/**@brief Encrypts a block according to the specified parameters.
*
* 128-bit AES encryption.
*
* @param[in, out] p_ecb_data Pointer to the ECB parameters' struct (two input
* parameters and one output parameter).
*
* @retval ::NRF_SUCCESS
*/
SVCALL(SD_ECB_BLOCK_ENCRYPT, uint32_t, sd_ecb_block_encrypt(nrf_ecb_hal_data_t * p_ecb_data));
/**@brief Gets any pending events generated by the SoC API.
*
* The application should keep calling this function to get events, until ::NRF_ERROR_NOT_FOUND is returned.
*
* @param[out] p_evt_id Set to one of the values in @ref NRF_SOC_EVTS, if any events are pending.
*
* @retval ::NRF_SUCCESS An event was pending. The event id is written in the p_evt_id parameter.
* @retval ::NRF_ERROR_NOT_FOUND No pending events.
*/
SVCALL(SD_EVT_GET, uint32_t, sd_evt_get(uint32_t * p_evt_id));
/**@brief Get the temperature measured on the chip
*
* This function will block until the temperature measurement is done.
* It takes around 50us from call to return.
*
* @note Pan #28 in PAN-028 v 1.6 "Negative measured values are not represented correctly" is corrected by this function.
*
* @param[out] p_temp Result of temperature measurement. Die temperature in 0.25 degrees celsius.
*
* @retval ::NRF_SUCCESS A temperature measurement was done, and the temperature was written to temp
*/
SVCALL(SD_TEMP_GET, uint32_t, sd_temp_get(int32_t * p_temp));
/**@brief Flash Write
*
* Commands to write a buffer to flash
*
* This call initiates the flash access command, and its completion will be communicated to the
* application with exactly one of the following events:
* - NRF_EVT_FLASH_OPERATION_SUCCESS - The command was successfully completed.
* - NRF_EVT_FLASH_OPERATION_ERROR - The command could not be started.
*
* @note
* - This call takes control over the radio and the CPU during flash erase and write to make sure that
* they will not interfere with the flash access. This means that all interrupts will be blocked
* for a predictable time (depending on the NVMC specification in nRF51 Series Reference Manual
* and the command parameters).
*
*
* @param[in] p_dst Pointer to start of flash location to be written.
* @param[in] p_src Pointer to buffer with data to be written
* @param[in] size Number of 32-bit words to write. Maximum size is 256 32bit words.
*
* @retval ::NRF_ERROR_INVALID_ADDR Tried to write to a non existing flash address, or p_dst or p_src was unaligned.
* @retval ::NRF_ERROR_BUSY The previous command has not yet completed.
* @retval ::NRF_ERROR_INVALID_LENGTH Size was 0, or more than 256 words.
* @retval ::NRF_ERROR_FORBIDDEN Tried to write to or read from protected location.
* @retval ::NRF_SUCCESS The command was accepted.
*/
SVCALL(SD_FLASH_WRITE, uint32_t, sd_flash_write(uint32_t * const p_dst, uint32_t const * const p_src, uint32_t size));
/**@brief Flash Erase page
*
* Commands to erase a flash page
*
* This call initiates the flash access command, and its completion will be communicated to the
* application with exactly one of the following events:
* - NRF_EVT_FLASH_OPERATION_SUCCESS - The command was successfully completed.
* - NRF_EVT_FLASH_OPERATION_ERROR - The command could not be started.
*
* @note
* - This call takes control over the radio and the CPU during flash erase and write to make sure that
* they will not interfere with the flash access. This means that all interrupts will be blocked
* for a predictable time (depending on the NVMC specification in nRF51 Series Reference Manual
* and the command parameters).
*
*
* @param[in] page_number Pagenumber of the page to erase
* @retval ::NRF_ERROR_INTERNAL If a new session could not be opened due to an internal error.
* @retval ::NRF_ERROR_INVALID_ADDR Tried to erase to a non existing flash page.
* @retval ::NRF_ERROR_BUSY The previous command has not yet completed.
* @retval ::NRF_ERROR_FORBIDDEN Tried to erase a protected page.
* @retval ::NRF_SUCCESS The command was accepted.
*/
SVCALL(SD_FLASH_ERASE_PAGE, uint32_t, sd_flash_page_erase(uint32_t page_number));
/**@brief Flash Protection set
*
* Commands to set the flash protection registers PROTENSETx
*
* @note To read the values in PROTENSETx you can read them directly. They are only write-protected.
*
* @param[in] protenset0 Value to be written to PROTENSET0
* @param[in] protenset1 Value to be written to PROTENSET1
*
* @retval ::NRF_ERROR_FORBIDDEN Tried to protect the SoftDevice
* @retval ::NRF_SUCCESS Values successfully written to PROTENSETx
*/
SVCALL(SD_FLASH_PROTECT, uint32_t, sd_flash_protect(uint32_t protenset0, uint32_t protenset1));
/** @} */
#endif // NRF_SOC_H__
/**
@}
*/

View File

@ -0,0 +1,33 @@
#ifndef NRF_SVC__
#define NRF_SVC__
#ifdef SVCALL_AS_NORMAL_FUNCTION
#define SVCALL(number, return_type, signature) return_type signature
#else
#ifndef SVCALL
#if defined (__CC_ARM)
#define SVCALL(number, return_type, signature) return_type __svc(number) signature
#elif defined (__GNUC__)
#define SVCALL(number, return_type, signature) \
_Pragma("GCC diagnostic ignored \"-Wreturn-type\"") \
_Pragma("GCC diagnostic ignored \"-Wunused-function\"") \
__attribute__((naked)) static return_type signature \
{ \
__asm( \
"svc %0\n" \
"bx r14" : : "I" (number) : "r0" \
); \
}
#elif defined (__ICCARM__)
#define PRAGMA(x) _Pragma(#x)
#define SVCALL(number, return_type, signature) \
PRAGMA(swi_number = number) \
__swi return_type signature;
#else
#define SVCALL(number, return_type, signature) return_type signature
#endif
#endif // SVCALL
#endif // SVCALL_AS_NORMAL_FUNCTION
#endif // NRF_SVC__

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is confidential property of Nordic Semiconductor. The use,
* copying, transfer or disclosure of such information is prohibited except by express written
* agreement with Nordic Semiconductor.
*
*/
/** @brief Utilities for verifying program logic
*/
#ifndef SOFTDEVICE_ASSERT_H_
#define SOFTDEVICE_ASSERT_H_
#include <stdint.h>
/** @brief This function handles assertions.
*
*
* @note
* This function is called when an assertion has triggered.
*
*
* @param line_num The line number where the assertion is called
* @param file_name Pointer to the file name
*/
void assert_softdevice_callback(uint16_t line_num, const uint8_t *file_name);
/*lint -emacro(506, ASSERT) */ /* Suppress "Constant value Boolean */
/*lint -emacro(774, ASSERT) */ /* Suppress "Boolean within 'if' always evaluates to True" */ \
/** @brief Check intended for production code
*
* Check passes if "expr" evaluates to true. */
#define ASSERT(expr) \
if (expr) \
{ \
} \
else \
{ \
assert_softdevice_callback((uint16_t)__LINE__, (uint8_t *)__FILE__); \
/*lint -unreachable */ \
}
#endif /* SOFTDEVICE_ASSERT_H_ */

View File

@ -0,0 +1,174 @@
NORDIC SEMICONDUCTOR ASA SOFTDEVICE LICENSE AGREEMENT
License Agreement for the Nordic Semiconductor ASA ("Nordic")
S110 Bluetooth SoftDevice software package ("SoftDevice").
You ("You" "Licensee") must carefully and thoroughly read this License
Agreement ("Agreement"), and accept to adhere to this Agreement before
downloading, installing and/or using any software or content in the
SoftDevice provided herewith.
YOU ACCEPT THIS LICENSE AGREEMENT BY (A) CLICKING ACCEPT OR AGREE TO
THIS LICENSE AGREEMENT, WHERE THIS OPTION IS MADE AVAILABLE TO YOU; OR
(B) BY ACTUALLY USING THE SOFTDEVICE, IN THIS CASE YOU AGREE THAT THE
USE OF THE SOFTDEVICE CONSTITUTES ACCEPTANCE OF THE LICENSING
AGREEMENT FROM THAT POINT ONWARDS.
IF YOU DO NOT AGREE TO BE BOUND BY THE TERMS OF THIS AGREEMENT, THEN
DO NOT DOWNLOAD, INSTALL/COMPLETE INSTALLATION OF, OR IN ANY OTHER WAY
MAKE USE OF THE SOFTDEVICE.
1. Grant of License
Subject to the terms in this Agreement Nordic grants Licensee a
limited, non-exclusive, non-transferable, non-sub licensable,
revocable license ("License"): (a) to use the SoftDevice solely in
connection with a Nordic integrated circuit, and (b) to distribute the
SoftDevice solely as integrated in Licensee Product. Licensee shall
not use the SoftDevice for any purpose other than specifically
authorized herein. It is a material breach of this agreement to use or
modify the SoftDevice for use on any wireless connectivity integrated
circuit other than a Nordic integrated circuit.
2. Title
Nordic retains full rights, title, and ownership to the SoftDevice and
any and all patents, copyrights, trade secrets, trade names,
trademarks, and other intellectual property rights in and to the
SoftDevice.
3. No Modifications or Reverse Engineering
Licensee shall not, modify, reverse engineer, disassemble, decompile
or otherwise attempt to discover the source code of any non-source
code parts of the SoftDevice including, but not limited to
pre-compiled hex files, binaries and object code.
4. Distribution Restrictions
Except as set forward in Section 1 above, the Licensee may not
disclose or distribute any or all parts of the SoftDevice to any third
party. Licensee agrees to provide reasonable security precautions to
prevent unauthorized access to or use of the SoftDevice as proscribed
herein. Licensee also agrees that use of and access to the SoftDevice
will be strictly limited to the employees and subcontractors of the
Licensee necessary for the performance of development, verification
and production tasks under this Agreement. The Licensee is responsible
for making such employees and subcontractors comply with the
obligations concerning use and non-disclosure of the SoftDevice.
6. No Other Rights
Licensee shall use the SoftDevice only in compliance with this
Agreement and shall refrain from using the SoftDevice in any way that
may be contrary to this Agreement.
7. Fees
Nordic grants the License to the Licensee free of charge provided that
the Licensee undertakes the obligations in the Agreement and warrants
to comply with the Agreement.
8. DISCLAIMER OF WARRANTY
THE SOFTDEVICE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND
EXPRESS OR IMPLIED AND NEITHER NORDIC, ITS LICENSORS OR AFFILIATES NOR
THE COPYRIGHT HOLDERS MAKE ANY REPRESENTATIONS OR WARRANTIES, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR THAT THE
SOFTDEVICE WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
TRADEMARKS OR OTHER RIGHTS. THERE IS NO WARRANTY BY NORDIC OR BY ANY
OTHER PARTY THAT THE FUNCTIONS CONTAINED IN THE SOFTDEVICE WILL MEET
THE REQUIREMENTS OF LICENSEE OR THAT THE OPERATION OF THE SOFTDEVICE
WILL BE UNINTERRUPTED OR ERROR-FREE. LICENSEE ASSUMES ALL
RESPONSIBILITY AND RISK FOR THE SELECTION OF THE SOFTDEVICE TO ACHIEVE
LICENSEES INTENDED RESULTS AND FOR THE INSTALLATION, USE AND RESULTS
OBTAINED FROM IT.
9. No Support
Nordic is not obligated to furnish or make available to Licensee any
further information, software, technical information, know-how,
show-how, bug-fixes or support. Nordic reserves the right to make
changes to the SoftDevice without further notice.
10. Limitation of Liability
In no event shall Nordic, its employees or suppliers, licensors or
affiliates be liable for any lost profits, revenue, sales, data or
costs of procurement of substitute goods or services, property damage,
personal injury, interruption of business, loss of business
information or for any special, direct, indirect, incidental,
economic, punitive, special or consequential damages, however caused
and whether arising under contract, tort, negligence, or other theory
of liability arising out of the use of or inability to use the
SoftDevice, even if Nordic or its employees or suppliers, licensors or
affiliates are advised of the possibility of such damages. Because
some countries/states/jurisdictions do not allow the exclusion or
limitation of liability, but may allow liability to be limited, in
such cases, Nordic, its employees or licensors or affiliates
liability shall be limited to USD 50.
11. Breach of Contract
Upon a breach of contract by the Licensee, Nordic and its licensor are
entitled to damages in respect of any direct loss which can be
reasonably attributed to the breach by the Licensee. If the Licensee
has acted with gross negligence or willful misconduct, the Licensee
shall cover both direct and indirect costs for Nordic and its
licensors.
12. Indemnity
Licensee undertakes to indemnify, hold harmless and defend Nordic and
its directors, officers, affiliates, shareholders, licensors,
employees and agents from and against any claims or lawsuits,
including attorney's fees, that arise or result of the Licensees
execution of the License and which is not due to causes for which
Nordic is responsible.
13. Governing Law
This Agreement shall be construed according to the laws of Norway, and
hereby submits to the exclusive jurisdiction of the Oslo tingrett.
14. Assignment
Licensee shall not assign this Agreement or any rights or obligations
hereunder without the prior written consent of Nordic.
15. Termination
Without prejudice to any other rights, Nordic may cancel this
Agreement if Licensee does not abide by the terms and conditions of
this Agreement. Upon termination Licensee must promptly cease the use
of the License and destroy all copies of the Licensed Technology and
any other material provided by Nordic or its affiliate, or produced by
the Licensee in connection with the Agreement or the Licensed
Technology.
16. Third party beneficiaries
Nordics licensors are intended third party beneficiaries under this
Agreement.

View File

@ -0,0 +1,14 @@
s110_nrf51822_6.0.0
This release consists of the following:
- This readme file
- The s110_nrf51822_6.0.0 license
- The s110_nrf51822_6.0.0 softdevice (binary hex file)
- The s110_nrf51822_6.0.0 API (softdevice header files)
- The s110_nrf51822_6.0.0 release notes
- The s110_nrf51822_6.0.0 migration document
IMPORTANT NOTE: If you intend to use the softdevice with the nRF51
SDK only, you do _not_ need the API files. The API header files are
already installed as part of the nRF51 SDK versions 5.0.0 and 5.1.0.

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2013 Nordic Semiconductor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2013 Nordic Semiconductor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2013 Nordic Semiconductor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2013 Nordic Semiconductor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2013 Nordic Semiconductor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2013 Nordic Semiconductor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2013 Nordic Semiconductor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2013 Nordic Semiconductor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2013 Nordic Semiconductor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -21,10 +21,10 @@ void sleep(void) {
// ensure debug is disconnected if semihost is enabled....
NRF_POWER->TASKS_LOWPWR=1;
// wait for interrupt
__WFI();
__WFE();
}
void deepsleep(void) {
sleep();
NRF_POWER->SYSTEMOFF=1;
// NRF_POWER->SYSTEMOFF=1;
}

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2013 Nordic Semiconductor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2013 Nordic Semiconductor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.