Birkbeck College Mobile and Ubiquitous Computing IoT Lab Exercise 2

Dependencies:   BLE_API_Native_blog

Committer:
gkroussos
Date:
Sat Mar 07 16:34:53 2015 +0000
Revision:
0:e8fdba0ed044
MUC IoT Workshop v1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gkroussos 0:e8fdba0ed044 1 /* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved.
gkroussos 0:e8fdba0ed044 2 *
gkroussos 0:e8fdba0ed044 3 * The information contained herein is confidential property of Nordic Semiconductor. The use,
gkroussos 0:e8fdba0ed044 4 * copying, transfer or disclosure of such information is prohibited except by express written
gkroussos 0:e8fdba0ed044 5 * agreement with Nordic Semiconductor.
gkroussos 0:e8fdba0ed044 6 *
gkroussos 0:e8fdba0ed044 7 */
gkroussos 0:e8fdba0ed044 8 /**
gkroussos 0:e8fdba0ed044 9 @addtogroup BLE_GAP Generic Access Profile (GAP)
gkroussos 0:e8fdba0ed044 10 @{
gkroussos 0:e8fdba0ed044 11 @brief Definitions and prototypes for the GAP interface.
gkroussos 0:e8fdba0ed044 12 */
gkroussos 0:e8fdba0ed044 13
gkroussos 0:e8fdba0ed044 14 #ifndef BLE_GAP_H__
gkroussos 0:e8fdba0ed044 15 #define BLE_GAP_H__
gkroussos 0:e8fdba0ed044 16
gkroussos 0:e8fdba0ed044 17 #include "ble_types.h"
gkroussos 0:e8fdba0ed044 18 #include "ble_ranges.h"
gkroussos 0:e8fdba0ed044 19 #include "nrf_svc.h"
gkroussos 0:e8fdba0ed044 20
gkroussos 0:e8fdba0ed044 21 /**
gkroussos 0:e8fdba0ed044 22 * @brief GAP API SVC numbers.
gkroussos 0:e8fdba0ed044 23 */
gkroussos 0:e8fdba0ed044 24 enum BLE_GAP_SVCS
gkroussos 0:e8fdba0ed044 25 {
gkroussos 0:e8fdba0ed044 26 SD_BLE_GAP_ADDRESS_SET = BLE_GAP_SVC_BASE, /**< Set own Bluetooth Address. */
gkroussos 0:e8fdba0ed044 27 SD_BLE_GAP_ADDRESS_GET, /**< Get own Bluetooth Address. */
gkroussos 0:e8fdba0ed044 28 SD_BLE_GAP_ADV_DATA_SET, /**< Set Advertisement Data. */
gkroussos 0:e8fdba0ed044 29 SD_BLE_GAP_ADV_START, /**< Start Advertising. */
gkroussos 0:e8fdba0ed044 30 SD_BLE_GAP_ADV_STOP, /**< Stop Advertising. */
gkroussos 0:e8fdba0ed044 31 SD_BLE_GAP_CONN_PARAM_UPDATE, /**< Connection Parameter Update. */
gkroussos 0:e8fdba0ed044 32 SD_BLE_GAP_DISCONNECT, /**< Disconnect. */
gkroussos 0:e8fdba0ed044 33 SD_BLE_GAP_TX_POWER_SET, /**< Set TX Power. */
gkroussos 0:e8fdba0ed044 34 SD_BLE_GAP_APPEARANCE_SET, /**< Set Appearance. */
gkroussos 0:e8fdba0ed044 35 SD_BLE_GAP_APPEARANCE_GET, /**< Get Appearance. */
gkroussos 0:e8fdba0ed044 36 SD_BLE_GAP_PPCP_SET, /**< Set PPCP. */
gkroussos 0:e8fdba0ed044 37 SD_BLE_GAP_PPCP_GET, /**< Get PPCP. */
gkroussos 0:e8fdba0ed044 38 SD_BLE_GAP_DEVICE_NAME_SET, /**< Set Device Name. */
gkroussos 0:e8fdba0ed044 39 SD_BLE_GAP_DEVICE_NAME_GET, /**< Get Device Name. */
gkroussos 0:e8fdba0ed044 40 SD_BLE_GAP_AUTHENTICATE, /**< Initiate Pairing/Bonding. */
gkroussos 0:e8fdba0ed044 41 SD_BLE_GAP_SEC_PARAMS_REPLY, /**< Reply with Security Parameters. */
gkroussos 0:e8fdba0ed044 42 SD_BLE_GAP_AUTH_KEY_REPLY, /**< Reply with an authentication key. */
gkroussos 0:e8fdba0ed044 43 SD_BLE_GAP_SEC_INFO_REPLY, /**< Reply with Security Information. */
gkroussos 0:e8fdba0ed044 44 SD_BLE_GAP_CONN_SEC_GET, /**< Obtain connection security level. */
gkroussos 0:e8fdba0ed044 45 SD_BLE_GAP_RSSI_START, /**< Start reporting of changes in RSSI. */
gkroussos 0:e8fdba0ed044 46 SD_BLE_GAP_RSSI_STOP, /**< Stop reporting of changes in RSSI. */
gkroussos 0:e8fdba0ed044 47 };
gkroussos 0:e8fdba0ed044 48
gkroussos 0:e8fdba0ed044 49
gkroussos 0:e8fdba0ed044 50 /** @addtogroup BLE_GAP_DEFINES Defines
gkroussos 0:e8fdba0ed044 51 * @{ */
gkroussos 0:e8fdba0ed044 52
gkroussos 0:e8fdba0ed044 53 /** @defgroup BLE_ERRORS_GAP SVC return values specific to GAP
gkroussos 0:e8fdba0ed044 54 * @{ */
gkroussos 0:e8fdba0ed044 55 #define BLE_ERROR_GAP_UUID_LIST_MISMATCH (NRF_GAP_ERR_BASE + 0x000) /**< UUID list does not contain an integral number of UUIDs. */
gkroussos 0:e8fdba0ed044 56 #define BLE_ERROR_GAP_DISCOVERABLE_WITH_WHITELIST (NRF_GAP_ERR_BASE + 0x001) /**< Use of Whitelist not permitted with discoverable advertising. */
gkroussos 0:e8fdba0ed044 57 #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. */
gkroussos 0:e8fdba0ed044 58 /** @} */
gkroussos 0:e8fdba0ed044 59
gkroussos 0:e8fdba0ed044 60
gkroussos 0:e8fdba0ed044 61 /** @defgroup BLE_GAP_ROLES GAP Roles
gkroussos 0:e8fdba0ed044 62 * @note Not explicitly used in peripheral API, but will be relevant for central API.
gkroussos 0:e8fdba0ed044 63 * @{ */
gkroussos 0:e8fdba0ed044 64 #define BLE_GAP_ROLE_INVALID 0x0 /**< Invalid Role. */
gkroussos 0:e8fdba0ed044 65 #define BLE_GAP_ROLE_PERIPH 0x1 /**< Peripheral Role. */
gkroussos 0:e8fdba0ed044 66 #define BLE_GAP_ROLE_CENTRAL 0x2 /**< Central Role. */
gkroussos 0:e8fdba0ed044 67 /** @} */
gkroussos 0:e8fdba0ed044 68
gkroussos 0:e8fdba0ed044 69
gkroussos 0:e8fdba0ed044 70 /** @defgroup BLE_GAP_TIMEOUT_SOURCES GAP Timeout sources
gkroussos 0:e8fdba0ed044 71 * @{ */
gkroussos 0:e8fdba0ed044 72 #define BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT 0x00 /**< Advertisement timeout. */
gkroussos 0:e8fdba0ed044 73 #define BLE_GAP_TIMEOUT_SRC_SECURITY_REQUEST 0x01 /**< Security request timeout. */
gkroussos 0:e8fdba0ed044 74 /** @} */
gkroussos 0:e8fdba0ed044 75
gkroussos 0:e8fdba0ed044 76
gkroussos 0:e8fdba0ed044 77 /** @defgroup BLE_GAP_ADDR_TYPES GAP Address types
gkroussos 0:e8fdba0ed044 78 * @{ */
gkroussos 0:e8fdba0ed044 79 #define BLE_GAP_ADDR_TYPE_PUBLIC 0x00 /**< Public address. */
gkroussos 0:e8fdba0ed044 80 #define BLE_GAP_ADDR_TYPE_RANDOM_STATIC 0x01 /**< Random Static address. */
gkroussos 0:e8fdba0ed044 81 #define BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE 0x02 /**< Private Resolvable address. */
gkroussos 0:e8fdba0ed044 82 #define BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE 0x03 /**< Private Non-Resolvable address. */
gkroussos 0:e8fdba0ed044 83 /** @} */
gkroussos 0:e8fdba0ed044 84
gkroussos 0:e8fdba0ed044 85
gkroussos 0:e8fdba0ed044 86 /** @brief BLE address length. */
gkroussos 0:e8fdba0ed044 87 #define BLE_GAP_ADDR_LEN 6
gkroussos 0:e8fdba0ed044 88
gkroussos 0:e8fdba0ed044 89
gkroussos 0:e8fdba0ed044 90 /** @defgroup BLE_GAP_AD_TYPE_DEFINITIONS GAP Advertising and Scan Response Data format
gkroussos 0:e8fdba0ed044 91 * @note Found at https://www.bluetooth.org/Technical/AssignedNumbers/generic_access_profile.htm
gkroussos 0:e8fdba0ed044 92 * @{ */
gkroussos 0:e8fdba0ed044 93 #define BLE_GAP_AD_TYPE_FLAGS 0x01 /**< Flags for discoverability. */
gkroussos 0:e8fdba0ed044 94 #define BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE 0x02 /**< Partial list of 16 bit service UUIDs. */
gkroussos 0:e8fdba0ed044 95 #define BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE 0x03 /**< Complete list of 16 bit service UUIDs. */
gkroussos 0:e8fdba0ed044 96 #define BLE_GAP_AD_TYPE_32BIT_SERVICE_UUID_MORE_AVAILABLE 0x04 /**< Partial list of 32 bit service UUIDs. */
gkroussos 0:e8fdba0ed044 97 #define BLE_GAP_AD_TYPE_32BIT_SERVICE_UUID_COMPLETE 0x05 /**< Complete list of 32 bit service UUIDs. */
gkroussos 0:e8fdba0ed044 98 #define BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_MORE_AVAILABLE 0x06 /**< Partial list of 128 bit service UUIDs. */
gkroussos 0:e8fdba0ed044 99 #define BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE 0x07 /**< Complete list of 128 bit service UUIDs. */
gkroussos 0:e8fdba0ed044 100 #define BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME 0x08 /**< Short local device name. */
gkroussos 0:e8fdba0ed044 101 #define BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME 0x09 /**< Complete local device name. */
gkroussos 0:e8fdba0ed044 102 #define BLE_GAP_AD_TYPE_TX_POWER_LEVEL 0x0A /**< Transmit power level. */
gkroussos 0:e8fdba0ed044 103 #define BLE_GAP_AD_TYPE_CLASS_OF_DEVICE 0x0D /**< Class of device. */
gkroussos 0:e8fdba0ed044 104 #define BLE_GAP_AD_TYPE_SIMPLE_PAIRING_HASH_C 0x0E /**< Simple Pairing Hash C. */
gkroussos 0:e8fdba0ed044 105 #define BLE_GAP_AD_TYPE_SIMPLE_PAIRING_RANDOMIZER_R 0x0F /**< Simple Pairing Randomizer R. */
gkroussos 0:e8fdba0ed044 106 #define BLE_GAP_AD_TYPE_SECURITY_MANAGER_TK_VALUE 0x10 /**< Security Manager TK Value. */
gkroussos 0:e8fdba0ed044 107 #define BLE_GAP_AD_TYPE_SECURITY_MANAGER_OOB_FLAGS 0x11 /**< Security Manager Out Of Band Flags. */
gkroussos 0:e8fdba0ed044 108 #define BLE_GAP_AD_TYPE_SLAVE_CONNECTION_INTERVAL_RANGE 0x12 /**< Slave Connection Interval Range. */
gkroussos 0:e8fdba0ed044 109 #define BLE_GAP_AD_TYPE_SOLICITED_SERVICE_UUIDS_16BIT 0x14 /**< List of 16-bit Service Solicitation UUIDs. */
gkroussos 0:e8fdba0ed044 110 #define BLE_GAP_AD_TYPE_SOLICITED_SERVICE_UUIDS_128BIT 0x15 /**< List of 128-bit Service Solicitation UUIDs. */
gkroussos 0:e8fdba0ed044 111 #define BLE_GAP_AD_TYPE_SERVICE_DATA 0x16 /**< Service Data. */
gkroussos 0:e8fdba0ed044 112 #define BLE_GAP_AD_TYPE_PUBLIC_TARGET_ADDRESS 0x17 /**< Public Target Address. */
gkroussos 0:e8fdba0ed044 113 #define BLE_GAP_AD_TYPE_RANDOM_TARGET_ADDRESS 0x18 /**< Random Target Address. */
gkroussos 0:e8fdba0ed044 114 #define BLE_GAP_AD_TYPE_APPEARANCE 0x19 /**< Appearance. */
gkroussos 0:e8fdba0ed044 115 #define BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA 0xFF /**< Manufacturer Specific Data. */
gkroussos 0:e8fdba0ed044 116 /** @} */
gkroussos 0:e8fdba0ed044 117
gkroussos 0:e8fdba0ed044 118
gkroussos 0:e8fdba0ed044 119 /** @defgroup BLE_GAP_ADV_FLAGS GAP Advertisement Flags
gkroussos 0:e8fdba0ed044 120 * @{ */
gkroussos 0:e8fdba0ed044 121 #define BLE_GAP_ADV_FLAG_LE_LIMITED_DISC_MODE (0x01) /**< LE Limited Discoverable Mode. */
gkroussos 0:e8fdba0ed044 122 #define BLE_GAP_ADV_FLAG_LE_GENERAL_DISC_MODE (0x02) /**< LE General Discoverable Mode. */
gkroussos 0:e8fdba0ed044 123 #define BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED (0x04) /**< BR/EDR not supported. */
gkroussos 0:e8fdba0ed044 124 #define BLE_GAP_ADV_FLAG_LE_BR_EDR_CONTROLLER (0x08) /**< Simultaneous LE and BR/EDR, Controller. */
gkroussos 0:e8fdba0ed044 125 #define BLE_GAP_ADV_FLAG_LE_BR_EDR_HOST (0x10) /**< Simultaneous LE and BR/EDR, Host. */
gkroussos 0:e8fdba0ed044 126 #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. */
gkroussos 0:e8fdba0ed044 127 #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. */
gkroussos 0:e8fdba0ed044 128 /** @} */
gkroussos 0:e8fdba0ed044 129
gkroussos 0:e8fdba0ed044 130
gkroussos 0:e8fdba0ed044 131 /** @defgroup BLE_GAP_ADV_INTERVALS GAP Advertising interval max and min
gkroussos 0:e8fdba0ed044 132 * @{ */
gkroussos 0:e8fdba0ed044 133 #define BLE_GAP_ADV_INTERVAL_MIN 0x0020 /**< Minimum Advertising interval in 625 us units, i.e. 20 ms. */
gkroussos 0:e8fdba0ed044 134 #define BLE_GAP_ADV_NONCON_INTERVAL_MIN 0x00A0 /**< Minimum Advertising interval in 625 us units for non connectable mode, i.e. 100 ms. */
gkroussos 0:e8fdba0ed044 135 #define BLE_GAP_ADV_INTERVAL_MAX 0x4000 /**< Maximum Advertising interval in 625 us units, i.e. 10.24 s. */
gkroussos 0:e8fdba0ed044 136 /** @} */
gkroussos 0:e8fdba0ed044 137
gkroussos 0:e8fdba0ed044 138
gkroussos 0:e8fdba0ed044 139 /** @brief Maximum size of advertising data in octets. */
gkroussos 0:e8fdba0ed044 140 #define BLE_GAP_ADV_MAX_SIZE 31
gkroussos 0:e8fdba0ed044 141
gkroussos 0:e8fdba0ed044 142
gkroussos 0:e8fdba0ed044 143 /** @defgroup BLE_GAP_ADV_TYPES GAP Advertising types
gkroussos 0:e8fdba0ed044 144 * @{ */
gkroussos 0:e8fdba0ed044 145 #define BLE_GAP_ADV_TYPE_ADV_IND 0x00 /**< Connectable undirected. */
gkroussos 0:e8fdba0ed044 146 #define BLE_GAP_ADV_TYPE_ADV_DIRECT_IND 0x01 /**< Connectable directed. */
gkroussos 0:e8fdba0ed044 147 #define BLE_GAP_ADV_TYPE_ADV_SCAN_IND 0x02 /**< Scannable undirected. */
gkroussos 0:e8fdba0ed044 148 #define BLE_GAP_ADV_TYPE_ADV_NONCONN_IND 0x03 /**< Non connectable undirected. */
gkroussos 0:e8fdba0ed044 149 /** @} */
gkroussos 0:e8fdba0ed044 150
gkroussos 0:e8fdba0ed044 151
gkroussos 0:e8fdba0ed044 152 /** @defgroup BLE_GAP_ADV_FILTER_POLICIES GAP Advertising filter policies
gkroussos 0:e8fdba0ed044 153 * @{ */
gkroussos 0:e8fdba0ed044 154 #define BLE_GAP_ADV_FP_ANY 0x00 /**< Allow scan requests and connect requests from any device. */
gkroussos 0:e8fdba0ed044 155 #define BLE_GAP_ADV_FP_FILTER_SCANREQ 0x01 /**< Filter scan requests with whitelist. */
gkroussos 0:e8fdba0ed044 156 #define BLE_GAP_ADV_FP_FILTER_CONNREQ 0x02 /**< Filter connect requests with whitelist. */
gkroussos 0:e8fdba0ed044 157 #define BLE_GAP_ADV_FP_FILTER_BOTH 0x03 /**< Filter both scan and connect requests with whitelist. */
gkroussos 0:e8fdba0ed044 158 /** @} */
gkroussos 0:e8fdba0ed044 159
gkroussos 0:e8fdba0ed044 160
gkroussos 0:e8fdba0ed044 161 /** @defgroup BLE_GAP_ADV_TIMEOUT_VALUES GAP Advertising timeout values
gkroussos 0:e8fdba0ed044 162 * @{ */
gkroussos 0:e8fdba0ed044 163 #define BLE_GAP_ADV_TIMEOUT_LIMITED_MAX 180 /**< Maximum advertising time in limited discoverable mode (TGAP(lim_adv_timeout) = 180s in spec (Addendum 2)). */
gkroussos 0:e8fdba0ed044 164 #define BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED 0 /**< Unlimited advertising in general discoverable mode. */
gkroussos 0:e8fdba0ed044 165 /** @} */
gkroussos 0:e8fdba0ed044 166
gkroussos 0:e8fdba0ed044 167
gkroussos 0:e8fdba0ed044 168 /** @defgroup BLE_GAP_DISC_MODES GAP Discovery modes
gkroussos 0:e8fdba0ed044 169 * @{ */
gkroussos 0:e8fdba0ed044 170 #define BLE_GAP_DISC_MODE_NOT_DISCOVERABLE 0x00 /**< Not discoverable discovery Mode. */
gkroussos 0:e8fdba0ed044 171 #define BLE_GAP_DISC_MODE_LIMITED 0x01 /**< Limited Discovery Mode. */
gkroussos 0:e8fdba0ed044 172 #define BLE_GAP_DISC_MODE_GENERAL 0x02 /**< General Discovery Mode. */
gkroussos 0:e8fdba0ed044 173 /** @} */
gkroussos 0:e8fdba0ed044 174
gkroussos 0:e8fdba0ed044 175 /** @defgroup BLE_GAP_IO_CAPS GAP IO Capabilities
gkroussos 0:e8fdba0ed044 176 * @{ */
gkroussos 0:e8fdba0ed044 177 #define BLE_GAP_IO_CAPS_DISPLAY_ONLY 0x00 /**< Display Only. */
gkroussos 0:e8fdba0ed044 178 #define BLE_GAP_IO_CAPS_DISPLAY_YESNO 0x01 /**< Display and Yes/No entry. */
gkroussos 0:e8fdba0ed044 179 #define BLE_GAP_IO_CAPS_KEYBOARD_ONLY 0x02 /**< Keyboard Only. */
gkroussos 0:e8fdba0ed044 180 #define BLE_GAP_IO_CAPS_NONE 0x03 /**< No I/O capabilities. */
gkroussos 0:e8fdba0ed044 181 #define BLE_GAP_IO_CAPS_KEYBOARD_DISPLAY 0x04 /**< Keyboard and Display. */
gkroussos 0:e8fdba0ed044 182 /** @} */
gkroussos 0:e8fdba0ed044 183
gkroussos 0:e8fdba0ed044 184
gkroussos 0:e8fdba0ed044 185 /** @defgroup BLE_GAP_AUTH_KEY_TYPES GAP Authentication Key Types
gkroussos 0:e8fdba0ed044 186 * @{ */
gkroussos 0:e8fdba0ed044 187 #define BLE_GAP_AUTH_KEY_TYPE_NONE 0x00 /**< No key (may be used to reject). */
gkroussos 0:e8fdba0ed044 188 #define BLE_GAP_AUTH_KEY_TYPE_PASSKEY 0x01 /**< 6-digit Passkey. */
gkroussos 0:e8fdba0ed044 189 #define BLE_GAP_AUTH_KEY_TYPE_OOB 0x02 /**< Out Of Band data. */
gkroussos 0:e8fdba0ed044 190 /** @} */
gkroussos 0:e8fdba0ed044 191
gkroussos 0:e8fdba0ed044 192 /** @defgroup BLE_GAP_SEC_STATUS GAP Security status
gkroussos 0:e8fdba0ed044 193 * @{ */
gkroussos 0:e8fdba0ed044 194 #define BLE_GAP_SEC_STATUS_SUCCESS 0x00 /**< Successful parameters. */
gkroussos 0:e8fdba0ed044 195 #define BLE_GAP_SEC_STATUS_TIMEOUT 0x01 /**< Procedure timed out. */
gkroussos 0:e8fdba0ed044 196 #define BLE_GAP_SEC_STATUS_PDU_INVALID 0x02 /**< Invalid PDU received. */
gkroussos 0:e8fdba0ed044 197 #define BLE_GAP_SEC_STATUS_PASSKEY_ENTRY_FAILED 0x81 /**< Passkey entry failed (user cancelled or other). */
gkroussos 0:e8fdba0ed044 198 #define BLE_GAP_SEC_STATUS_OOB_NOT_AVAILABLE 0x82 /**< Out of Band Key not available. */
gkroussos 0:e8fdba0ed044 199 #define BLE_GAP_SEC_STATUS_AUTH_REQ 0x83 /**< Authentication requirements not met. */
gkroussos 0:e8fdba0ed044 200 #define BLE_GAP_SEC_STATUS_CONFIRM_VALUE 0x84 /**< Confirm value failed. */
gkroussos 0:e8fdba0ed044 201 #define BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP 0x85 /**< Pairing not supported. */
gkroussos 0:e8fdba0ed044 202 #define BLE_GAP_SEC_STATUS_ENC_KEY_SIZE 0x86 /**< Encryption key size. */
gkroussos 0:e8fdba0ed044 203 #define BLE_GAP_SEC_STATUS_SMP_CMD_UNSUPPORTED 0x87 /**< Unsupported SMP command. */
gkroussos 0:e8fdba0ed044 204 #define BLE_GAP_SEC_STATUS_UNSPECIFIED 0x88 /**< Unspecified reason. */
gkroussos 0:e8fdba0ed044 205 #define BLE_GAP_SEC_STATUS_REPEATED_ATTEMPTS 0x89 /**< Too little time elapsed since last attempt. */
gkroussos 0:e8fdba0ed044 206 #define BLE_GAP_SEC_STATUS_INVALID_PARAMS 0x8A /**< Invalid parameters. */
gkroussos 0:e8fdba0ed044 207 /** @} */
gkroussos 0:e8fdba0ed044 208
gkroussos 0:e8fdba0ed044 209 /** @defgroup BLE_GAP_SEC_STATUS_SOURCES GAP Security status sources
gkroussos 0:e8fdba0ed044 210 * @{ */
gkroussos 0:e8fdba0ed044 211 #define BLE_GAP_SEC_STATUS_SOURCE_LOCAL 0x00 /**< Local failure. */
gkroussos 0:e8fdba0ed044 212 #define BLE_GAP_SEC_STATUS_SOURCE_REMOTE 0x01 /**< Remote failure. */
gkroussos 0:e8fdba0ed044 213 /** @} */
gkroussos 0:e8fdba0ed044 214
gkroussos 0:e8fdba0ed044 215 /** @defgroup BLE_GAP_CP_LIMITS GAP Connection Parameters Limits
gkroussos 0:e8fdba0ed044 216 * @{ */
gkroussos 0:e8fdba0ed044 217 #define BLE_GAP_CP_MIN_CONN_INTVL_NONE 0xFFFF /**< No new minimum connction interval specified in connect parameters. */
gkroussos 0:e8fdba0ed044 218 #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. */
gkroussos 0:e8fdba0ed044 219 #define BLE_GAP_CP_MIN_CONN_INTVL_MAX 0x0C80 /**< Highest minimum connection interval permitted, in units of 1.25 ms, i.e. 4 s. */
gkroussos 0:e8fdba0ed044 220 #define BLE_GAP_CP_MAX_CONN_INTVL_NONE 0xFFFF /**< No new maximum connction interval specified in connect parameters. */
gkroussos 0:e8fdba0ed044 221 #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. */
gkroussos 0:e8fdba0ed044 222 #define BLE_GAP_CP_MAX_CONN_INTVL_MAX 0x0C80 /**< Highest maximum connection interval permitted, in units of 1.25 ms, i.e. 4 s. */
gkroussos 0:e8fdba0ed044 223 #define BLE_GAP_CP_SLAVE_LATENCY_MAX 0x03E8 /**< Highest slave latency permitted, in connection events. */
gkroussos 0:e8fdba0ed044 224 #define BLE_GAP_CP_CONN_SUP_TIMEOUT_NONE 0xFFFF /**< No new supervision timeout specified in connect parameters. */
gkroussos 0:e8fdba0ed044 225 #define BLE_GAP_CP_CONN_SUP_TIMEOUT_MIN 0x000A /**< Lowest supervision timeout permitted, in units of 10 ms, i.e. 100 ms. */
gkroussos 0:e8fdba0ed044 226 #define BLE_GAP_CP_CONN_SUP_TIMEOUT_MAX 0x0C80 /**< Highest supervision timeout permitted, in units of 10 ms, i.e. 32 s. */
gkroussos 0:e8fdba0ed044 227 /** @} */
gkroussos 0:e8fdba0ed044 228
gkroussos 0:e8fdba0ed044 229
gkroussos 0:e8fdba0ed044 230 /**@brief GAP device name maximum length. */
gkroussos 0:e8fdba0ed044 231 #define BLE_GAP_DEVNAME_MAX_LEN 31
gkroussos 0:e8fdba0ed044 232
gkroussos 0:e8fdba0ed044 233
gkroussos 0:e8fdba0ed044 234 /** @defgroup BLE_GAP_CONN_SEC_MODE_SET_MACROS GAP attribute security requirement setters
gkroussos 0:e8fdba0ed044 235 *
gkroussos 0:e8fdba0ed044 236 * See @ref ble_gap_conn_sec_mode_t.
gkroussos 0:e8fdba0ed044 237 * @{ */
gkroussos 0:e8fdba0ed044 238 /** @brief Set sec_mode pointed to by ptr to have no access rights.*/
gkroussos 0:e8fdba0ed044 239 #define BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(ptr) do {(ptr)->sm = 0; (ptr)->lv = 0;} while(0)
gkroussos 0:e8fdba0ed044 240 /** @brief Set sec_mode pointed to by ptr to require no protection, open link.*/
gkroussos 0:e8fdba0ed044 241 #define BLE_GAP_CONN_SEC_MODE_SET_OPEN(ptr) do {(ptr)->sm = 1; (ptr)->lv = 1;} while(0)
gkroussos 0:e8fdba0ed044 242 /** @brief Set sec_mode pointed to by ptr to require encryption, but no MITM protection.*/
gkroussos 0:e8fdba0ed044 243 #define BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(ptr) do {(ptr)->sm = 1; (ptr)->lv = 2;} while(0)
gkroussos 0:e8fdba0ed044 244 /** @brief Set sec_mode pointed to by ptr to require encryption and MITM protection.*/
gkroussos 0:e8fdba0ed044 245 #define BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(ptr) do {(ptr)->sm = 1; (ptr)->lv = 3;} while(0)
gkroussos 0:e8fdba0ed044 246 /** @brief Set sec_mode pointed to by ptr to require signing or encryption, no MITM protection needed.*/
gkroussos 0:e8fdba0ed044 247 #define BLE_GAP_CONN_SEC_MODE_SET_SIGNED_NO_MITM(ptr) do {(ptr)->sm = 2; (ptr)->lv = 1;} while(0)
gkroussos 0:e8fdba0ed044 248 /** @brief Set sec_mode pointed to by ptr to require signing or encryption with MITM protection.*/
gkroussos 0:e8fdba0ed044 249 #define BLE_GAP_CONN_SEC_MODE_SET_SIGNED_WITH_MITM(ptr) do {(ptr)->sm = 2; (ptr)->lv = 2;} while(0)
gkroussos 0:e8fdba0ed044 250 /** @} */
gkroussos 0:e8fdba0ed044 251
gkroussos 0:e8fdba0ed044 252
gkroussos 0:e8fdba0ed044 253 /**@brief GAP Security Key Length. */
gkroussos 0:e8fdba0ed044 254 #define BLE_GAP_SEC_KEY_LEN 16
gkroussos 0:e8fdba0ed044 255
gkroussos 0:e8fdba0ed044 256 /**@brief Maximum amount of addresses in a whitelist. */
gkroussos 0:e8fdba0ed044 257 #define BLE_GAP_WHITELIST_ADDR_MAX_COUNT (8)
gkroussos 0:e8fdba0ed044 258
gkroussos 0:e8fdba0ed044 259 /**@brief Maximum amount of IRKs in a whitelist.
gkroussos 0:e8fdba0ed044 260 * @note The number of IRKs is limited to 8, even if the hardware supports more.
gkroussos 0:e8fdba0ed044 261 */
gkroussos 0:e8fdba0ed044 262 #define BLE_GAP_WHITELIST_IRK_MAX_COUNT (8)
gkroussos 0:e8fdba0ed044 263
gkroussos 0:e8fdba0ed044 264 /** @defgroup GAP_SEC_MODES GAP Security Modes
gkroussos 0:e8fdba0ed044 265 * @{ */
gkroussos 0:e8fdba0ed044 266 #define BLE_GAP_SEC_MODE 0x00 /**< No key (may be used to reject). */
gkroussos 0:e8fdba0ed044 267
gkroussos 0:e8fdba0ed044 268 /** @} */
gkroussos 0:e8fdba0ed044 269
gkroussos 0:e8fdba0ed044 270
gkroussos 0:e8fdba0ed044 271 /** @} */
gkroussos 0:e8fdba0ed044 272
gkroussos 0:e8fdba0ed044 273 /**@brief Bluetooth Low Energy address. */
gkroussos 0:e8fdba0ed044 274 typedef struct
gkroussos 0:e8fdba0ed044 275 {
gkroussos 0:e8fdba0ed044 276 uint8_t addr_type; /**< See @ref BLE_GAP_ADDR_TYPES. */
gkroussos 0:e8fdba0ed044 277 uint8_t addr[BLE_GAP_ADDR_LEN]; /**< 48-bit address, LSB format. */
gkroussos 0:e8fdba0ed044 278 } ble_gap_addr_t;
gkroussos 0:e8fdba0ed044 279
gkroussos 0:e8fdba0ed044 280
gkroussos 0:e8fdba0ed044 281 /**@brief GAP connection parameters.
gkroussos 0:e8fdba0ed044 282 *
gkroussos 0:e8fdba0ed044 283 * @note When ble_conn_params_t is received in an event, both min_conn_interval and
gkroussos 0:e8fdba0ed044 284 * max_conn_interval will be equal to the connection interval set by the central.
gkroussos 0:e8fdba0ed044 285 */
gkroussos 0:e8fdba0ed044 286 typedef struct
gkroussos 0:e8fdba0ed044 287 {
gkroussos 0:e8fdba0ed044 288 uint16_t min_conn_interval; /**< Minimum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/
gkroussos 0:e8fdba0ed044 289 uint16_t max_conn_interval; /**< Maximum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/
gkroussos 0:e8fdba0ed044 290 uint16_t slave_latency; /**< Slave Latency in number of connection events, see @ref BLE_GAP_CP_LIMITS.*/
gkroussos 0:e8fdba0ed044 291 uint16_t conn_sup_timeout; /**< Connection Supervision Timeout in 10 ms units, see @ref BLE_GAP_CP_LIMITS.*/
gkroussos 0:e8fdba0ed044 292 } ble_gap_conn_params_t;
gkroussos 0:e8fdba0ed044 293
gkroussos 0:e8fdba0ed044 294
gkroussos 0:e8fdba0ed044 295 /**@brief GAP link requirements.
gkroussos 0:e8fdba0ed044 296 *
gkroussos 0:e8fdba0ed044 297 * See Bluetooth Core specification, Volume 3 Part C 10.2 for details.
gkroussos 0:e8fdba0ed044 298 *
gkroussos 0:e8fdba0ed044 299 * Security Mode 0 Level 0: No access permissions at all (this level is not defined by the Bluetooth Core specification).\n
gkroussos 0:e8fdba0ed044 300 * Security Mode 1 Level 1: No security is needed (aka open link).\n
gkroussos 0:e8fdba0ed044 301 * Security Mode 1 Level 2: Encrypted link required, MITM protection not necessary.\n
gkroussos 0:e8fdba0ed044 302 * Security Mode 1 Level 3: MITM protected encrypted link required.\n
gkroussos 0:e8fdba0ed044 303 * Security Mode 2 Level 1: Signing or encryption required, MITM protection not necessary.\n
gkroussos 0:e8fdba0ed044 304 * Security Mode 2 Level 2: MITM protected signing required, unless link is MITM protected encrypted.\n
gkroussos 0:e8fdba0ed044 305 */
gkroussos 0:e8fdba0ed044 306 typedef struct
gkroussos 0:e8fdba0ed044 307 {
gkroussos 0:e8fdba0ed044 308 uint8_t sm : 4; /**< Security Mode (1 or 2), 0 for no permissions at all. */
gkroussos 0:e8fdba0ed044 309 uint8_t lv : 4; /**< Level (1, 2 or 3), 0 for no permissions at all. */
gkroussos 0:e8fdba0ed044 310
gkroussos 0:e8fdba0ed044 311 } ble_gap_conn_sec_mode_t;
gkroussos 0:e8fdba0ed044 312
gkroussos 0:e8fdba0ed044 313
gkroussos 0:e8fdba0ed044 314
gkroussos 0:e8fdba0ed044 315 /**@brief GAP connection security status.*/
gkroussos 0:e8fdba0ed044 316 typedef struct
gkroussos 0:e8fdba0ed044 317 {
gkroussos 0:e8fdba0ed044 318 ble_gap_conn_sec_mode_t sec_mode; /**< Currently active security mode for this connection.*/
gkroussos 0:e8fdba0ed044 319 uint8_t encr_key_size; /**< Length of currently active encryption key, 7 to 16 octets.*/
gkroussos 0:e8fdba0ed044 320 } ble_gap_conn_sec_t;
gkroussos 0:e8fdba0ed044 321
gkroussos 0:e8fdba0ed044 322
gkroussos 0:e8fdba0ed044 323
gkroussos 0:e8fdba0ed044 324 /**@brief Identity Resolving Key. */
gkroussos 0:e8fdba0ed044 325 typedef struct
gkroussos 0:e8fdba0ed044 326 {
gkroussos 0:e8fdba0ed044 327 uint8_t irk[BLE_GAP_SEC_KEY_LEN]; /**< Array containing IRK. */
gkroussos 0:e8fdba0ed044 328 } ble_gap_irk_t;
gkroussos 0:e8fdba0ed044 329
gkroussos 0:e8fdba0ed044 330
gkroussos 0:e8fdba0ed044 331 /**@brief Whitelist structure. */
gkroussos 0:e8fdba0ed044 332 typedef struct
gkroussos 0:e8fdba0ed044 333 {
gkroussos 0:e8fdba0ed044 334 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. */
gkroussos 0:e8fdba0ed044 335 uint8_t addr_count; /**< Count of device addresses in array, up to @ref BLE_GAP_WHITELIST_ADDR_MAX_COUNT. */
gkroussos 0:e8fdba0ed044 336 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. */
gkroussos 0:e8fdba0ed044 337 uint8_t irk_count; /**< Count of IRKs in array, up to @ref BLE_GAP_WHITELIST_IRK_MAX_COUNT. */
gkroussos 0:e8fdba0ed044 338 } ble_gap_whitelist_t;
gkroussos 0:e8fdba0ed044 339
gkroussos 0:e8fdba0ed044 340
gkroussos 0:e8fdba0ed044 341 /**@brief GAP advertising parameters.*/
gkroussos 0:e8fdba0ed044 342 typedef struct
gkroussos 0:e8fdba0ed044 343 {
gkroussos 0:e8fdba0ed044 344 uint8_t type; /**< See @ref BLE_GAP_ADV_TYPES. */
gkroussos 0:e8fdba0ed044 345 ble_gap_addr_t* p_peer_addr; /**< For BLE_GAP_CONN_MODE_DIRECTED mode only, known peer address. */
gkroussos 0:e8fdba0ed044 346 uint8_t fp; /**< Filter Policy, see @ref BLE_GAP_ADV_FILTER_POLICIES. */
gkroussos 0:e8fdba0ed044 347 ble_gap_whitelist_t * p_whitelist; /**< Pointer to whitelist, NULL if none is given. */
gkroussos 0:e8fdba0ed044 348 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. */
gkroussos 0:e8fdba0ed044 349 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. */
gkroussos 0:e8fdba0ed044 350 } ble_gap_adv_params_t;
gkroussos 0:e8fdba0ed044 351
gkroussos 0:e8fdba0ed044 352
gkroussos 0:e8fdba0ed044 353 /**@brief GAP scanning parameters. */
gkroussos 0:e8fdba0ed044 354 typedef struct
gkroussos 0:e8fdba0ed044 355 {
gkroussos 0:e8fdba0ed044 356 uint8_t filter; /**< Filter based on discovery mode, see @ref BLE_GAP_DISC_MODES. */
gkroussos 0:e8fdba0ed044 357 uint8_t active : 1; /**< If 1, perform active scanning (scan requests). */
gkroussos 0:e8fdba0ed044 358 uint8_t selective : 1; /**< If 1, ignore unknown devices (non whitelisted). */
gkroussos 0:e8fdba0ed044 359 uint16_t interval; /**< Scan interval between 0x0020 and 0x4000 in 0.625ms units (20ms to 10.24s). */
gkroussos 0:e8fdba0ed044 360 uint16_t window; /**< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
gkroussos 0:e8fdba0ed044 361 uint16_t timeout; /**< Scan timeout between 0x0001 and 0x3FFF in seconds, 0x0000 disables timeout. */
gkroussos 0:e8fdba0ed044 362 } ble_gap_scan_params_t;
gkroussos 0:e8fdba0ed044 363
gkroussos 0:e8fdba0ed044 364
gkroussos 0:e8fdba0ed044 365 /**@brief GAP security parameters. */
gkroussos 0:e8fdba0ed044 366 typedef struct
gkroussos 0:e8fdba0ed044 367 {
gkroussos 0:e8fdba0ed044 368 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. */
gkroussos 0:e8fdba0ed044 369 uint8_t bond : 1; /**< Perform bonding. */
gkroussos 0:e8fdba0ed044 370 uint8_t mitm : 1; /**< Man In The Middle protection required. */
gkroussos 0:e8fdba0ed044 371 uint8_t io_caps : 3; /**< IO capabilities, see @ref BLE_GAP_IO_CAPS. */
gkroussos 0:e8fdba0ed044 372 uint8_t oob : 1; /**< Out Of Band data available. */
gkroussos 0:e8fdba0ed044 373 uint8_t min_key_size; /**< Minimum encryption key size in octets between 7 and 16. */
gkroussos 0:e8fdba0ed044 374 uint8_t max_key_size; /**< Maximum encryption key size in octets between min_key_size and 16. */
gkroussos 0:e8fdba0ed044 375 } ble_gap_sec_params_t;
gkroussos 0:e8fdba0ed044 376
gkroussos 0:e8fdba0ed044 377
gkroussos 0:e8fdba0ed044 378 /**@brief GAP Encryption Information. */
gkroussos 0:e8fdba0ed044 379 typedef struct
gkroussos 0:e8fdba0ed044 380 {
gkroussos 0:e8fdba0ed044 381 uint16_t div; /**< Encryption Diversifier. */
gkroussos 0:e8fdba0ed044 382 uint8_t ltk[BLE_GAP_SEC_KEY_LEN]; /**< Long Term Key. */
gkroussos 0:e8fdba0ed044 383 uint8_t auth : 1; /**< Authenticated Key. */
gkroussos 0:e8fdba0ed044 384 uint8_t ltk_len : 7; /**< LTK length in octets. */
gkroussos 0:e8fdba0ed044 385 } ble_gap_enc_info_t;
gkroussos 0:e8fdba0ed044 386
gkroussos 0:e8fdba0ed044 387
gkroussos 0:e8fdba0ed044 388 /**@brief GAP Master Identification. */
gkroussos 0:e8fdba0ed044 389 typedef struct
gkroussos 0:e8fdba0ed044 390 {
gkroussos 0:e8fdba0ed044 391 uint16_t ediv; /**< Encrypted Diversifier. */
gkroussos 0:e8fdba0ed044 392 uint8_t rand[8]; /**< Random Number. */
gkroussos 0:e8fdba0ed044 393 } ble_gap_master_id_t;
gkroussos 0:e8fdba0ed044 394
gkroussos 0:e8fdba0ed044 395
gkroussos 0:e8fdba0ed044 396 /**@brief GAP Identity Information. */
gkroussos 0:e8fdba0ed044 397 typedef struct
gkroussos 0:e8fdba0ed044 398 {
gkroussos 0:e8fdba0ed044 399 ble_gap_addr_t addr; /**< Bluetooth address to which this key applies. */
gkroussos 0:e8fdba0ed044 400 uint8_t irk[BLE_GAP_SEC_KEY_LEN]; /**< Identity Resolution Key. */
gkroussos 0:e8fdba0ed044 401 } ble_gap_id_info_t;
gkroussos 0:e8fdba0ed044 402
gkroussos 0:e8fdba0ed044 403
gkroussos 0:e8fdba0ed044 404 /**@brief GAP Signing Information. */
gkroussos 0:e8fdba0ed044 405 typedef struct
gkroussos 0:e8fdba0ed044 406 {
gkroussos 0:e8fdba0ed044 407 uint8_t csrk[BLE_GAP_SEC_KEY_LEN]; /* Connection Signature Resolving Key. */
gkroussos 0:e8fdba0ed044 408 } ble_gap_sign_info_t;
gkroussos 0:e8fdba0ed044 409
gkroussos 0:e8fdba0ed044 410
gkroussos 0:e8fdba0ed044 411
gkroussos 0:e8fdba0ed044 412 /**
gkroussos 0:e8fdba0ed044 413 * @brief GAP Event IDs.
gkroussos 0:e8fdba0ed044 414 * Those IDs uniquely identify an event coming from the stack to the application.
gkroussos 0:e8fdba0ed044 415 */
gkroussos 0:e8fdba0ed044 416 enum BLE_GAP_EVTS
gkroussos 0:e8fdba0ed044 417 {
gkroussos 0:e8fdba0ed044 418 BLE_GAP_EVT_CONNECTED = BLE_GAP_EVT_BASE, /**< Connection established. */
gkroussos 0:e8fdba0ed044 419 BLE_GAP_EVT_DISCONNECTED, /**< Disconnected from peer. */
gkroussos 0:e8fdba0ed044 420 BLE_GAP_EVT_CONN_PARAM_UPDATE, /**< Connection Parameters updated. */
gkroussos 0:e8fdba0ed044 421 BLE_GAP_EVT_SEC_PARAMS_REQUEST, /**< Request to provide security parameters. */
gkroussos 0:e8fdba0ed044 422 BLE_GAP_EVT_SEC_INFO_REQUEST, /**< Request to provide security information. */
gkroussos 0:e8fdba0ed044 423 BLE_GAP_EVT_PASSKEY_DISPLAY, /**< Request to display a passkey to the user. */
gkroussos 0:e8fdba0ed044 424 BLE_GAP_EVT_AUTH_KEY_REQUEST, /**< Request to provide an authentication key. */
gkroussos 0:e8fdba0ed044 425 BLE_GAP_EVT_AUTH_STATUS, /**< Authentication procedure completed with status. */
gkroussos 0:e8fdba0ed044 426 BLE_GAP_EVT_CONN_SEC_UPDATE, /**< Connection security updated. */
gkroussos 0:e8fdba0ed044 427 BLE_GAP_EVT_TIMEOUT, /**< Timeout expired. */
gkroussos 0:e8fdba0ed044 428 BLE_GAP_EVT_RSSI_CHANGED, /**< Signal strength measurement report. */
gkroussos 0:e8fdba0ed044 429 };
gkroussos 0:e8fdba0ed044 430
gkroussos 0:e8fdba0ed044 431
gkroussos 0:e8fdba0ed044 432 /** @brief Event data for connected event. */
gkroussos 0:e8fdba0ed044 433 typedef struct
gkroussos 0:e8fdba0ed044 434 {
gkroussos 0:e8fdba0ed044 435 ble_gap_addr_t peer_addr; /**< Bluetooth address of the peer device. */
gkroussos 0:e8fdba0ed044 436 uint8_t irk_match :1; /**< If 1, peer device's address resolved using an IRK. */
gkroussos 0:e8fdba0ed044 437 uint8_t irk_match_idx :7; /**< Index in IRK list where the address was matched. */
gkroussos 0:e8fdba0ed044 438 ble_gap_conn_params_t conn_params; /**< GAP Connection Parameters. */
gkroussos 0:e8fdba0ed044 439 } ble_gap_evt_connected_t;
gkroussos 0:e8fdba0ed044 440
gkroussos 0:e8fdba0ed044 441
gkroussos 0:e8fdba0ed044 442 /** @brief Event data for disconnected event. */
gkroussos 0:e8fdba0ed044 443 typedef struct
gkroussos 0:e8fdba0ed044 444 {
gkroussos 0:e8fdba0ed044 445 uint8_t reason; /**< HCI error code. */
gkroussos 0:e8fdba0ed044 446 } ble_gap_evt_disconnected_t;
gkroussos 0:e8fdba0ed044 447
gkroussos 0:e8fdba0ed044 448
gkroussos 0:e8fdba0ed044 449 /** @brief Event data for connection parameter update event. */
gkroussos 0:e8fdba0ed044 450 typedef struct
gkroussos 0:e8fdba0ed044 451 {
gkroussos 0:e8fdba0ed044 452 ble_gap_conn_params_t conn_params; /**< GAP Connection Parameters. */
gkroussos 0:e8fdba0ed044 453 } ble_gap_evt_conn_param_update_t;
gkroussos 0:e8fdba0ed044 454
gkroussos 0:e8fdba0ed044 455
gkroussos 0:e8fdba0ed044 456 /** @brief Event data for security parameters request event. */
gkroussos 0:e8fdba0ed044 457 typedef struct
gkroussos 0:e8fdba0ed044 458 {
gkroussos 0:e8fdba0ed044 459 ble_gap_sec_params_t peer_params; /**< Initiator Security Parameters. */
gkroussos 0:e8fdba0ed044 460 } ble_gap_evt_sec_params_request_t;
gkroussos 0:e8fdba0ed044 461
gkroussos 0:e8fdba0ed044 462
gkroussos 0:e8fdba0ed044 463 /** @brief Event data for securito info request event. */
gkroussos 0:e8fdba0ed044 464 typedef struct
gkroussos 0:e8fdba0ed044 465 {
gkroussos 0:e8fdba0ed044 466 ble_gap_addr_t peer_addr; /**< Bluetooth address of the peer device. */
gkroussos 0:e8fdba0ed044 467 uint16_t div; /**< Encryption diversifier for LTK lookup. */
gkroussos 0:e8fdba0ed044 468 uint8_t enc_info : 1; /**< If 1, Encryption Information required. */
gkroussos 0:e8fdba0ed044 469 uint8_t id_info : 1; /**< If 1, Identity Information required. */
gkroussos 0:e8fdba0ed044 470 uint8_t sign_info : 1; /**< If 1, Signing Information required. */
gkroussos 0:e8fdba0ed044 471 } ble_gap_evt_sec_info_request_t;
gkroussos 0:e8fdba0ed044 472
gkroussos 0:e8fdba0ed044 473
gkroussos 0:e8fdba0ed044 474 /** @brief Event data for passkey display event. */
gkroussos 0:e8fdba0ed044 475 typedef struct
gkroussos 0:e8fdba0ed044 476 {
gkroussos 0:e8fdba0ed044 477 uint8_t passkey[6]; /**< 6-digit passkey in ASCII ('0'-'9' digits only). */
gkroussos 0:e8fdba0ed044 478 } ble_gap_evt_passkey_display_t;
gkroussos 0:e8fdba0ed044 479
gkroussos 0:e8fdba0ed044 480
gkroussos 0:e8fdba0ed044 481 /** @brief Event data for authentication key request event. */
gkroussos 0:e8fdba0ed044 482 typedef struct
gkroussos 0:e8fdba0ed044 483 {
gkroussos 0:e8fdba0ed044 484 uint8_t key_type; /**< See @ref BLE_GAP_AUTH_KEY_TYPES. */
gkroussos 0:e8fdba0ed044 485 } ble_gap_evt_auth_key_request_t;
gkroussos 0:e8fdba0ed044 486
gkroussos 0:e8fdba0ed044 487
gkroussos 0:e8fdba0ed044 488 /** @brief Security levels supported.
gkroussos 0:e8fdba0ed044 489 * @note See Bluetooth Specification Version 4.0 Volume 3, Chapter 10.
gkroussos 0:e8fdba0ed044 490 */
gkroussos 0:e8fdba0ed044 491 typedef struct
gkroussos 0:e8fdba0ed044 492 {
gkroussos 0:e8fdba0ed044 493 uint8_t lv1 : 1; /**< If 1: Level 1 is supported. */
gkroussos 0:e8fdba0ed044 494 uint8_t lv2 : 1; /**< If 1: Level 2 is supported. */
gkroussos 0:e8fdba0ed044 495 uint8_t lv3 : 1; /**< If 1: Level 3 is supported. */
gkroussos 0:e8fdba0ed044 496 } ble_gap_sec_levels_t;
gkroussos 0:e8fdba0ed044 497
gkroussos 0:e8fdba0ed044 498
gkroussos 0:e8fdba0ed044 499 /** @brief Keys that have been exchanged. */
gkroussos 0:e8fdba0ed044 500 typedef struct
gkroussos 0:e8fdba0ed044 501 {
gkroussos 0:e8fdba0ed044 502 uint8_t ltk : 1; /**< Long Term Key. */
gkroussos 0:e8fdba0ed044 503 uint8_t ediv_rand : 1; /**< Encrypted Diversifier and Random value. */
gkroussos 0:e8fdba0ed044 504 uint8_t irk : 1; /**< Identity Resolving Key. */
gkroussos 0:e8fdba0ed044 505 uint8_t address : 1; /**< Public or static random address. */
gkroussos 0:e8fdba0ed044 506 uint8_t csrk : 1; /**< Connection Signature Resolving Key. */
gkroussos 0:e8fdba0ed044 507 } ble_gap_sec_keys_t;
gkroussos 0:e8fdba0ed044 508
gkroussos 0:e8fdba0ed044 509
gkroussos 0:e8fdba0ed044 510 /** @brief Event data for authentication status event. */
gkroussos 0:e8fdba0ed044 511 typedef struct
gkroussos 0:e8fdba0ed044 512 {
gkroussos 0:e8fdba0ed044 513 uint8_t auth_status; /**< Authentication status, see @ref BLE_GAP_SEC_STATUS. */
gkroussos 0:e8fdba0ed044 514 uint8_t error_src; /**< On error, source that caused the failure, see @ref BLE_GAP_SEC_STATUS_SOURCES. */
gkroussos 0:e8fdba0ed044 515 ble_gap_sec_levels_t sm1_levels; /**< Levels supported in Security Mode 1. */
gkroussos 0:e8fdba0ed044 516 ble_gap_sec_levels_t sm2_levels; /**< Levels supported in Security Mode 2. */
gkroussos 0:e8fdba0ed044 517 ble_gap_sec_keys_t periph_kex; /**< Bitmap stating which keys were exchanged (distributed) by the peripheral. */
gkroussos 0:e8fdba0ed044 518 ble_gap_sec_keys_t central_kex; /**< Bitmap stating which keys were exchanged (distributed) by the central. */
gkroussos 0:e8fdba0ed044 519 struct periph_keys_t
gkroussos 0:e8fdba0ed044 520 {
gkroussos 0:e8fdba0ed044 521 ble_gap_enc_info_t enc_info; /**< Peripheral's Encryption information. */
gkroussos 0:e8fdba0ed044 522 } periph_keys; /**< Actual keys distributed from the Peripheral to the Central. */
gkroussos 0:e8fdba0ed044 523 struct central_keys_t
gkroussos 0:e8fdba0ed044 524 {
gkroussos 0:e8fdba0ed044 525 ble_gap_irk_t irk; /**< Central's IRK. */
gkroussos 0:e8fdba0ed044 526 ble_gap_addr_t id_info; /**< Central's Identity Info. */
gkroussos 0:e8fdba0ed044 527 } central_keys; /**< Actual keys distributed from the Central to the Peripheral. */
gkroussos 0:e8fdba0ed044 528 } ble_gap_evt_auth_status_t;
gkroussos 0:e8fdba0ed044 529
gkroussos 0:e8fdba0ed044 530
gkroussos 0:e8fdba0ed044 531 /** @brief Event data for connection security update event. */
gkroussos 0:e8fdba0ed044 532 typedef struct
gkroussos 0:e8fdba0ed044 533 {
gkroussos 0:e8fdba0ed044 534 ble_gap_conn_sec_t conn_sec; /**< Connection security level. */
gkroussos 0:e8fdba0ed044 535 } ble_gap_evt_conn_sec_update_t;
gkroussos 0:e8fdba0ed044 536
gkroussos 0:e8fdba0ed044 537
gkroussos 0:e8fdba0ed044 538 /** @brief Event data for timeout event. */
gkroussos 0:e8fdba0ed044 539 typedef struct
gkroussos 0:e8fdba0ed044 540 {
gkroussos 0:e8fdba0ed044 541 uint8_t src; /**< Source of timeout event, see @ref BLE_GAP_TIMEOUT_SOURCES. */
gkroussos 0:e8fdba0ed044 542 } ble_gap_evt_timeout_t;
gkroussos 0:e8fdba0ed044 543
gkroussos 0:e8fdba0ed044 544
gkroussos 0:e8fdba0ed044 545 /** @brief Event data for advertisement report event. */
gkroussos 0:e8fdba0ed044 546 typedef struct
gkroussos 0:e8fdba0ed044 547 {
gkroussos 0:e8fdba0ed044 548 int8_t rssi; /**< Received Signal Strength Indication in dBm. */
gkroussos 0:e8fdba0ed044 549 } ble_gap_evt_rssi_changed_t;
gkroussos 0:e8fdba0ed044 550
gkroussos 0:e8fdba0ed044 551
gkroussos 0:e8fdba0ed044 552
gkroussos 0:e8fdba0ed044 553 /**@brief GAP event callback event structure. */
gkroussos 0:e8fdba0ed044 554 typedef struct
gkroussos 0:e8fdba0ed044 555 {
gkroussos 0:e8fdba0ed044 556 uint16_t conn_handle; /**< Connection Handle on which event occured. */
gkroussos 0:e8fdba0ed044 557 union /**< union alternative identified by evt_id in enclosing struct. */
gkroussos 0:e8fdba0ed044 558 {
gkroussos 0:e8fdba0ed044 559 ble_gap_evt_connected_t connected; /**< Connected Event Parameters. */
gkroussos 0:e8fdba0ed044 560 ble_gap_evt_disconnected_t disconnected; /**< Disconnected Event Parameters. */
gkroussos 0:e8fdba0ed044 561 ble_gap_evt_conn_param_update_t conn_param_update; /**< Connection Parameter Update Parameters. */
gkroussos 0:e8fdba0ed044 562 ble_gap_evt_sec_params_request_t sec_params_request; /**< Security Parameters Request Event Parameters. */
gkroussos 0:e8fdba0ed044 563 ble_gap_evt_sec_info_request_t sec_info_request; /**< Security Information Request Event Parameters. */
gkroussos 0:e8fdba0ed044 564 ble_gap_evt_passkey_display_t passkey_display; /**< Passkey Display Event Parameters. */
gkroussos 0:e8fdba0ed044 565 ble_gap_evt_auth_key_request_t auth_key_request; /**< Authentication Key Request Event Parameters. */
gkroussos 0:e8fdba0ed044 566 ble_gap_evt_auth_status_t auth_status; /**< Authentication Status Event Parameters. */
gkroussos 0:e8fdba0ed044 567 ble_gap_evt_conn_sec_update_t conn_sec_update; /**< Connection Security Update Event Parameters. */
gkroussos 0:e8fdba0ed044 568 ble_gap_evt_timeout_t timeout; /**< Timeout Event Parameters. */
gkroussos 0:e8fdba0ed044 569 ble_gap_evt_rssi_changed_t rssi_changed; /**< RSSI Event parameters. */
gkroussos 0:e8fdba0ed044 570 } params;
gkroussos 0:e8fdba0ed044 571
gkroussos 0:e8fdba0ed044 572 } ble_gap_evt_t;
gkroussos 0:e8fdba0ed044 573
gkroussos 0:e8fdba0ed044 574
gkroussos 0:e8fdba0ed044 575 /**@brief Set local Bluetooth address.
gkroussos 0:e8fdba0ed044 576 *
gkroussos 0:e8fdba0ed044 577 * @param[in] p_addr Pointer to address structure.
gkroussos 0:e8fdba0ed044 578 *
gkroussos 0:e8fdba0ed044 579 * @return @ref NRF_SUCCESS Address successfully set.
gkroussos 0:e8fdba0ed044 580 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
gkroussos 0:e8fdba0ed044 581 * @return @ref BLE_ERROR_GAP_INVALID_BLE_ADDR Invalid address.
gkroussos 0:e8fdba0ed044 582 * @return @ref NRF_ERROR_BUSY The stack is busy, process pending events and retry.
gkroussos 0:e8fdba0ed044 583 */
gkroussos 0:e8fdba0ed044 584 SVCALL(SD_BLE_GAP_ADDRESS_SET, uint32_t, sd_ble_gap_address_set(ble_gap_addr_t const * const p_addr));
gkroussos 0:e8fdba0ed044 585
gkroussos 0:e8fdba0ed044 586
gkroussos 0:e8fdba0ed044 587 /**@brief Get local Bluetooth address.
gkroussos 0:e8fdba0ed044 588 *
gkroussos 0:e8fdba0ed044 589 * @param[out] p_addr Pointer to address structure.
gkroussos 0:e8fdba0ed044 590 *
gkroussos 0:e8fdba0ed044 591 * @return @ref NRF_SUCCESS Address successfully retrieved.
gkroussos 0:e8fdba0ed044 592 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
gkroussos 0:e8fdba0ed044 593 */
gkroussos 0:e8fdba0ed044 594 SVCALL(SD_BLE_GAP_ADDRESS_GET, uint32_t, sd_ble_gap_address_get(ble_gap_addr_t * const p_addr));
gkroussos 0:e8fdba0ed044 595
gkroussos 0:e8fdba0ed044 596
gkroussos 0:e8fdba0ed044 597 /**@brief Set, clear or update advertisement and scan response data.
gkroussos 0:e8fdba0ed044 598 *
gkroussos 0:e8fdba0ed044 599 * @note The format of the advertisement data will be checked by this call to ensure interoperability.
gkroussos 0:e8fdba0ed044 600 * Limitations imposed by this API call to the data provided include having a flags data type in the scan response data and
gkroussos 0:e8fdba0ed044 601 * duplicating the local name in the advertisement data and scan response data.
gkroussos 0:e8fdba0ed044 602 *
gkroussos 0:e8fdba0ed044 603 * @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
gkroussos 0:e8fdba0ed044 604 * length (dlen/srdlen) set to 0.
gkroussos 0:e8fdba0ed044 605 *
gkroussos 0:e8fdba0ed044 606 * @note: The call will fail if p_data and p_sr_data are both NULL since this would have no effect.
gkroussos 0:e8fdba0ed044 607 *
gkroussos 0:e8fdba0ed044 608 * @param[in] p_data Raw data to be placed in advertisement packet. If NULL, no changes are made to the current advertisement packet data.
gkroussos 0:e8fdba0ed044 609 * @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.
gkroussos 0:e8fdba0ed044 610 * @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.
gkroussos 0:e8fdba0ed044 611 * @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.
gkroussos 0:e8fdba0ed044 612 *
gkroussos 0:e8fdba0ed044 613 * @return @ref NRF_SUCCESS Advertisement data successfully updated or cleared.
gkroussos 0:e8fdba0ed044 614 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
gkroussos 0:e8fdba0ed044 615 * @return @ref NRF_ERROR_INVALID_FLAGS Invalid combination of advertising flags supplied.
gkroussos 0:e8fdba0ed044 616 * @return @ref NRF_ERROR_INVALID_DATA Invalid data type(s) supplied, check the advertising data format specification.
gkroussos 0:e8fdba0ed044 617 * @return @ref NRF_ERROR_INVALID_LENGTH Invalid data length(s) supplied.
gkroussos 0:e8fdba0ed044 618 * @return @ref BLE_ERROR_GAP_UUID_LIST_MISMATCH Invalid UUID list supplied.
gkroussos 0:e8fdba0ed044 619 * @return @ref NRF_ERROR_BUSY The stack is busy, process pending events and retry.
gkroussos 0:e8fdba0ed044 620 */
gkroussos 0:e8fdba0ed044 621 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));
gkroussos 0:e8fdba0ed044 622
gkroussos 0:e8fdba0ed044 623
gkroussos 0:e8fdba0ed044 624 /**@brief Start advertising (GAP Discoverable, Connectable modes, Broadcast Procedure).
gkroussos 0:e8fdba0ed044 625 *
gkroussos 0:e8fdba0ed044 626 * @param[in] p_adv_params Pointer to advertising parameters structure.
gkroussos 0:e8fdba0ed044 627 *
gkroussos 0:e8fdba0ed044 628 * @return @ref NRF_SUCCESS The BLE stack has started advertising.
gkroussos 0:e8fdba0ed044 629 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
gkroussos 0:e8fdba0ed044 630 * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
gkroussos 0:e8fdba0ed044 631 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, check the accepted ranges and limits.
gkroussos 0:e8fdba0ed044 632 * @return @ref BLE_ERROR_GAP_INVALID_BLE_ADDR Invalid Bluetooth address supplied.
gkroussos 0:e8fdba0ed044 633 * @return @ref BLE_ERROR_GAP_DISCOVERABLE_WITH_WHITELIST Discoverable mode and whitelist incompatible.
gkroussos 0:e8fdba0ed044 634 */
gkroussos 0:e8fdba0ed044 635 SVCALL(SD_BLE_GAP_ADV_START, uint32_t, sd_ble_gap_adv_start(ble_gap_adv_params_t const * const p_adv_params));
gkroussos 0:e8fdba0ed044 636
gkroussos 0:e8fdba0ed044 637
gkroussos 0:e8fdba0ed044 638 /**@brief Stop advertising (GAP Discoverable, Connectable modes, Broadcast Procedure).
gkroussos 0:e8fdba0ed044 639 *
gkroussos 0:e8fdba0ed044 640 * @return @ref NRF_SUCCESS The BLE stack has stopped advertising.
gkroussos 0:e8fdba0ed044 641 * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation (most probably not in advertising state).
gkroussos 0:e8fdba0ed044 642 */
gkroussos 0:e8fdba0ed044 643 SVCALL(SD_BLE_GAP_ADV_STOP, uint32_t, sd_ble_gap_adv_stop(void));
gkroussos 0:e8fdba0ed044 644
gkroussos 0:e8fdba0ed044 645
gkroussos 0:e8fdba0ed044 646 /**@brief Update connection parameters.
gkroussos 0:e8fdba0ed044 647 *
gkroussos 0:e8fdba0ed044 648 * @details In the central role this will initiate a Link Layer connection parameter update procedure,
gkroussos 0:e8fdba0ed044 649 * otherwise in the peripheral role, this will send the corresponding L2CAP request and wait for
gkroussos 0:e8fdba0ed044 650 * the central to perform the procedure. In both cases, and regardless of success or failure, the application
gkroussos 0:e8fdba0ed044 651 * will be informed of the result with a @ref BLE_GAP_EVT_CONN_PARAM_UPDATE event.
gkroussos 0:e8fdba0ed044 652 *
gkroussos 0:e8fdba0ed044 653 * @note If both a connection supervision timeout and a maximum connection interval are specified, then the following constraint
gkroussos 0:e8fdba0ed044 654 * applies: (conn_sup_timeout * 8) >= (max_conn_interval * (slave_latency + 1))
gkroussos 0:e8fdba0ed044 655 *
gkroussos 0:e8fdba0ed044 656 * @param[in] conn_handle Connection handle.
gkroussos 0:e8fdba0ed044 657 * @param[in] p_conn_params Pointer to desired connection parameters. If NULL is provided on a peripheral role,
gkroussos 0:e8fdba0ed044 658 * the parameters in the PPCP characteristic of the GAP service will be used instead.
gkroussos 0:e8fdba0ed044 659 *
gkroussos 0:e8fdba0ed044 660 * @return @ref NRF_SUCCESS The Connection Update procedure has been started successfully.
gkroussos 0:e8fdba0ed044 661 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
gkroussos 0:e8fdba0ed044 662 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, check parameter limits and constraints.
gkroussos 0:e8fdba0ed044 663 * @return @ref NRF_ERROR_BUSY Procedure already in progress or not allowed at this time, process pending events and retry.
gkroussos 0:e8fdba0ed044 664 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
gkroussos 0:e8fdba0ed044 665 * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
gkroussos 0:e8fdba0ed044 666 */
gkroussos 0:e8fdba0ed044 667 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));
gkroussos 0:e8fdba0ed044 668
gkroussos 0:e8fdba0ed044 669
gkroussos 0:e8fdba0ed044 670 /**@brief Disconnect (GAP Link Termination).
gkroussos 0:e8fdba0ed044 671 *
gkroussos 0:e8fdba0ed044 672 * @details This call initiates the disconnection procedure, and its completion will be communicated to the application
gkroussos 0:e8fdba0ed044 673 * with a BLE_GAP_EVT_DISCONNECTED event.
gkroussos 0:e8fdba0ed044 674 *
gkroussos 0:e8fdba0ed044 675 * @param[in] conn_handle Connection handle.
gkroussos 0:e8fdba0ed044 676 * @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).
gkroussos 0:e8fdba0ed044 677 *
gkroussos 0:e8fdba0ed044 678 * @return @ref NRF_SUCCESS The disconnection procedure has been started successfully.
gkroussos 0:e8fdba0ed044 679 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
gkroussos 0:e8fdba0ed044 680 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
gkroussos 0:e8fdba0ed044 681 * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation (disconnection is already in progress or not connected at all).
gkroussos 0:e8fdba0ed044 682 */
gkroussos 0:e8fdba0ed044 683 SVCALL(SD_BLE_GAP_DISCONNECT, uint32_t, sd_ble_gap_disconnect(uint16_t conn_handle, uint8_t hci_status_code));
gkroussos 0:e8fdba0ed044 684
gkroussos 0:e8fdba0ed044 685
gkroussos 0:e8fdba0ed044 686 /**@brief Set the radio's transmit power.
gkroussos 0:e8fdba0ed044 687 *
gkroussos 0:e8fdba0ed044 688 * @param[in] tx_power Radio transmit power in dBm (accepted values are -40, -30, -20, -16, -12, -8, -4, 0, and 4 dBm).
gkroussos 0:e8fdba0ed044 689 *
gkroussos 0:e8fdba0ed044 690 * @note -40 dBm will not actually give -40 dBm, but will instead be remapped to -30 dBm.
gkroussos 0:e8fdba0ed044 691 *
gkroussos 0:e8fdba0ed044 692 * @return @ref NRF_SUCCESS Successfully changed the transmit power.
gkroussos 0:e8fdba0ed044 693 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
gkroussos 0:e8fdba0ed044 694 * @return @ref NRF_ERROR_BUSY The stack is busy, process pending events and retry.
gkroussos 0:e8fdba0ed044 695 */
gkroussos 0:e8fdba0ed044 696 SVCALL(SD_BLE_GAP_TX_POWER_SET, uint32_t, sd_ble_gap_tx_power_set(int8_t tx_power));
gkroussos 0:e8fdba0ed044 697
gkroussos 0:e8fdba0ed044 698
gkroussos 0:e8fdba0ed044 699 /**@brief Set GAP Appearance value.
gkroussos 0:e8fdba0ed044 700 *
gkroussos 0:e8fdba0ed044 701 * @param[in] appearance Appearance (16-bit), see @ref BLE_APPEARANCES.
gkroussos 0:e8fdba0ed044 702 *
gkroussos 0:e8fdba0ed044 703 * @return @ref NRF_SUCCESS Appearance value set successfully.
gkroussos 0:e8fdba0ed044 704 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
gkroussos 0:e8fdba0ed044 705 */
gkroussos 0:e8fdba0ed044 706 SVCALL(SD_BLE_GAP_APPEARANCE_SET, uint32_t, sd_ble_gap_appearance_set(uint16_t appearance));
gkroussos 0:e8fdba0ed044 707
gkroussos 0:e8fdba0ed044 708
gkroussos 0:e8fdba0ed044 709 /**@brief Get GAP Appearance value.
gkroussos 0:e8fdba0ed044 710 *
gkroussos 0:e8fdba0ed044 711 * @param[out] p_appearance Appearance (16-bit), see @ref BLE_APPEARANCES.
gkroussos 0:e8fdba0ed044 712 *
gkroussos 0:e8fdba0ed044 713 * @return @ref NRF_SUCCESS Appearance value retrieved successfully.
gkroussos 0:e8fdba0ed044 714 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
gkroussos 0:e8fdba0ed044 715 */
gkroussos 0:e8fdba0ed044 716 SVCALL(SD_BLE_GAP_APPEARANCE_GET, uint32_t, sd_ble_gap_appearance_get(uint16_t * const p_appearance));
gkroussos 0:e8fdba0ed044 717
gkroussos 0:e8fdba0ed044 718
gkroussos 0:e8fdba0ed044 719 /**@brief Set GAP Peripheral Preferred Connection Parameters.
gkroussos 0:e8fdba0ed044 720 *
gkroussos 0:e8fdba0ed044 721 * @param[in] p_conn_params Pointer to a @ref ble_gap_conn_params_t structure with the desired parameters.
gkroussos 0:e8fdba0ed044 722 *
gkroussos 0:e8fdba0ed044 723 * @return @ref NRF_SUCCESS Peripheral Preferred Connection Parameters set successfully.
gkroussos 0:e8fdba0ed044 724 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
gkroussos 0:e8fdba0ed044 725 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
gkroussos 0:e8fdba0ed044 726 */
gkroussos 0:e8fdba0ed044 727 SVCALL(SD_BLE_GAP_PPCP_SET, uint32_t, sd_ble_gap_ppcp_set(ble_gap_conn_params_t const * const p_conn_params));
gkroussos 0:e8fdba0ed044 728
gkroussos 0:e8fdba0ed044 729
gkroussos 0:e8fdba0ed044 730 /**@brief Get GAP Peripheral Preferred Connection Parameters.
gkroussos 0:e8fdba0ed044 731 *
gkroussos 0:e8fdba0ed044 732 * @param[out] p_conn_params Pointer to a @ref ble_gap_conn_params_t structure where the parameters will be stored.
gkroussos 0:e8fdba0ed044 733 *
gkroussos 0:e8fdba0ed044 734 * @return @ref NRF_SUCCESS Peripheral Preferred Connection Parameters retrieved successfully.
gkroussos 0:e8fdba0ed044 735 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
gkroussos 0:e8fdba0ed044 736 */
gkroussos 0:e8fdba0ed044 737 SVCALL(SD_BLE_GAP_PPCP_GET, uint32_t, sd_ble_gap_ppcp_get(ble_gap_conn_params_t * const p_conn_params));
gkroussos 0:e8fdba0ed044 738
gkroussos 0:e8fdba0ed044 739
gkroussos 0:e8fdba0ed044 740 /**@brief Set GAP device name.
gkroussos 0:e8fdba0ed044 741 *
gkroussos 0:e8fdba0ed044 742 * @param[in] p_write_perm Write permissions for the Device Name characteristic see @ref ble_gap_conn_sec_mode_t.
gkroussos 0:e8fdba0ed044 743 * @param[in] p_dev_name Pointer to a UTF-8 encoded, <b>non NULL-terminated</b> string.
gkroussos 0:e8fdba0ed044 744 * @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).
gkroussos 0:e8fdba0ed044 745 *
gkroussos 0:e8fdba0ed044 746 * @return @ref NRF_SUCCESS GAP device name and permissions set successfully.
gkroussos 0:e8fdba0ed044 747 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
gkroussos 0:e8fdba0ed044 748 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
gkroussos 0:e8fdba0ed044 749 * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
gkroussos 0:e8fdba0ed044 750 */
gkroussos 0:e8fdba0ed044 751 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));
gkroussos 0:e8fdba0ed044 752
gkroussos 0:e8fdba0ed044 753
gkroussos 0:e8fdba0ed044 754 /**@brief Get GAP device name.
gkroussos 0:e8fdba0ed044 755 *
gkroussos 0:e8fdba0ed044 756 * @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.
gkroussos 0:e8fdba0ed044 757 * @param[in,out] p_len Length of the buffer pointed by p_dev_name, complete device name length on output.
gkroussos 0:e8fdba0ed044 758 *
gkroussos 0:e8fdba0ed044 759 * @note If the device name is longer than the size of the supplied buffer,
gkroussos 0:e8fdba0ed044 760 * p_len will return the complete device name length,
gkroussos 0:e8fdba0ed044 761 * and not the number of bytes actually returned in p_dev_name.
gkroussos 0:e8fdba0ed044 762 * The application may use this information to allocate a suitable buffer size.
gkroussos 0:e8fdba0ed044 763 *
gkroussos 0:e8fdba0ed044 764 * @return @ref NRF_SUCCESS GAP device name retrieved successfully.
gkroussos 0:e8fdba0ed044 765 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
gkroussos 0:e8fdba0ed044 766 * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
gkroussos 0:e8fdba0ed044 767 */
gkroussos 0:e8fdba0ed044 768 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));
gkroussos 0:e8fdba0ed044 769
gkroussos 0:e8fdba0ed044 770
gkroussos 0:e8fdba0ed044 771 /**@brief Initiate GAP Authentication procedure.
gkroussos 0:e8fdba0ed044 772 *
gkroussos 0:e8fdba0ed044 773 * @param[in] conn_handle Connection handle.
gkroussos 0:e8fdba0ed044 774 * @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.
gkroussos 0:e8fdba0ed044 775 *
gkroussos 0:e8fdba0ed044 776 * @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.
gkroussos 0:e8fdba0ed044 777 * In the peripheral role, only the timeout, bond and mitm fields of @ref ble_gap_sec_params_t are used.
gkroussos 0:e8fdba0ed044 778 *
gkroussos 0:e8fdba0ed044 779 * @note The GAP Authentication procedure may be triggered by the central without calling this function when accessing a secure service.
gkroussos 0:e8fdba0ed044 780 * @note Calling this function may result in the following events depending on the outcome and parameters: @ref BLE_GAP_EVT_SEC_PARAMS_REQUEST,
gkroussos 0:e8fdba0ed044 781 * @ref BLE_GAP_EVT_SEC_INFO_REQUEST, @ref BLE_GAP_EVT_AUTH_KEY_REQUEST, @ref BLE_GAP_EVT_AUTH_STATUS.
gkroussos 0:e8fdba0ed044 782 * @note The timeout parameter in @ref ble_gap_sec_params_t is interpreted here as the Security Request timeout
gkroussos 0:e8fdba0ed044 783 *
gkroussos 0:e8fdba0ed044 784 *
gkroussos 0:e8fdba0ed044 785 * @return @ref NRF_SUCCESS Successfully initiated authentication procedure.
gkroussos 0:e8fdba0ed044 786 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
gkroussos 0:e8fdba0ed044 787 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
gkroussos 0:e8fdba0ed044 788 * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
gkroussos 0:e8fdba0ed044 789 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
gkroussos 0:e8fdba0ed044 790 */
gkroussos 0:e8fdba0ed044 791 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));
gkroussos 0:e8fdba0ed044 792
gkroussos 0:e8fdba0ed044 793
gkroussos 0:e8fdba0ed044 794 /**@brief Reply with GAP security parameters.
gkroussos 0:e8fdba0ed044 795 *
gkroussos 0:e8fdba0ed044 796 * @param[in] conn_handle Connection handle.
gkroussos 0:e8fdba0ed044 797 * @param[in] sec_status Security status, see @ref BLE_GAP_SEC_STATUS.
gkroussos 0:e8fdba0ed044 798 * @param[in] p_sec_params Pointer to a @ref ble_gap_sec_params_t security parameters structure.
gkroussos 0:e8fdba0ed044 799 *
gkroussos 0:e8fdba0ed044 800 * @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.
gkroussos 0:e8fdba0ed044 801 * @note If the call returns an error code, the request is still pending, and the reply call may be repeated with corrected parameters.
gkroussos 0:e8fdba0ed044 802 * @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
gkroussos 0:e8fdba0ed044 803 * if the application supplies a different value.
gkroussos 0:e8fdba0ed044 804 *
gkroussos 0:e8fdba0ed044 805 * @return @ref NRF_SUCCESS Successfully accepted security parameter from the application.
gkroussos 0:e8fdba0ed044 806 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
gkroussos 0:e8fdba0ed044 807 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
gkroussos 0:e8fdba0ed044 808 * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
gkroussos 0:e8fdba0ed044 809 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
gkroussos 0:e8fdba0ed044 810 */
gkroussos 0:e8fdba0ed044 811 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));
gkroussos 0:e8fdba0ed044 812
gkroussos 0:e8fdba0ed044 813
gkroussos 0:e8fdba0ed044 814 /**@brief Reply with an authentication key.
gkroussos 0:e8fdba0ed044 815 *
gkroussos 0:e8fdba0ed044 816 * @param[in] conn_handle Connection handle.
gkroussos 0:e8fdba0ed044 817 * @param[in] key_type See @ref BLE_GAP_AUTH_KEY_TYPES.
gkroussos 0:e8fdba0ed044 818 * @param[in] key If key type is BLE_GAP_AUTH_KEY_TYPE_NONE, then NULL.
gkroussos 0:e8fdba0ed044 819 * If key type is BLE_GAP_AUTH_KEY_TYPE_PASSKEY, then a 6-byte ASCII string (digit 0..9 only, no NULL termination).
gkroussos 0:e8fdba0ed044 820 * If key type is BLE_GAP_AUTH_KEY_TYPE_OOB, then a 16-byte OOB key value in Little Endian format.
gkroussos 0:e8fdba0ed044 821 *
gkroussos 0:e8fdba0ed044 822 * @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.
gkroussos 0:e8fdba0ed044 823 * @note If the call returns an error code, the request is still pending, and the reply call may be repeated with corrected parameters.
gkroussos 0:e8fdba0ed044 824 *
gkroussos 0:e8fdba0ed044 825 * @return @ref NRF_SUCCESS Authentication key successfully set.
gkroussos 0:e8fdba0ed044 826 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
gkroussos 0:e8fdba0ed044 827 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
gkroussos 0:e8fdba0ed044 828 * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
gkroussos 0:e8fdba0ed044 829 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
gkroussos 0:e8fdba0ed044 830 */
gkroussos 0:e8fdba0ed044 831 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));
gkroussos 0:e8fdba0ed044 832
gkroussos 0:e8fdba0ed044 833
gkroussos 0:e8fdba0ed044 834 /**@brief Reply with GAP security information.
gkroussos 0:e8fdba0ed044 835 *
gkroussos 0:e8fdba0ed044 836 * @param[in] conn_handle Connection handle.
gkroussos 0:e8fdba0ed044 837 * @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.
gkroussos 0:e8fdba0ed044 838 * @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.
gkroussos 0:e8fdba0ed044 839 *
gkroussos 0:e8fdba0ed044 840 * @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.
gkroussos 0:e8fdba0ed044 841 * @note If the call returns an error code, the request is still pending, and the reply call may be repeated with corrected parameters.
gkroussos 0:e8fdba0ed044 842 * @note Data signing is not implemented yet. p_sign_info must therefore be NULL.
gkroussos 0:e8fdba0ed044 843 *
gkroussos 0:e8fdba0ed044 844 * @return @ref NRF_SUCCESS Successfully accepted security information.
gkroussos 0:e8fdba0ed044 845 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
gkroussos 0:e8fdba0ed044 846 * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
gkroussos 0:e8fdba0ed044 847 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
gkroussos 0:e8fdba0ed044 848 * @return @ref NRF_ERROR_BUSY The stack is busy, process pending events and retry.
gkroussos 0:e8fdba0ed044 849 */
gkroussos 0:e8fdba0ed044 850 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));
gkroussos 0:e8fdba0ed044 851
gkroussos 0:e8fdba0ed044 852
gkroussos 0:e8fdba0ed044 853 /**@brief Get the current connection security.
gkroussos 0:e8fdba0ed044 854 *
gkroussos 0:e8fdba0ed044 855 * @param[in] conn_handle Connection handle.
gkroussos 0:e8fdba0ed044 856 * @param[out] p_conn_sec Pointer to a @ref ble_gap_conn_sec_t structure to be filled in.
gkroussos 0:e8fdba0ed044 857 *
gkroussos 0:e8fdba0ed044 858 * @return @ref NRF_SUCCESS Current connection security successfully retrieved.
gkroussos 0:e8fdba0ed044 859 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
gkroussos 0:e8fdba0ed044 860 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
gkroussos 0:e8fdba0ed044 861 */
gkroussos 0:e8fdba0ed044 862 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));
gkroussos 0:e8fdba0ed044 863
gkroussos 0:e8fdba0ed044 864
gkroussos 0:e8fdba0ed044 865 /**@brief Start reporting the received signal strength to the application.
gkroussos 0:e8fdba0ed044 866 *
gkroussos 0:e8fdba0ed044 867 * A new event is reported whenever the RSSI value changes, until @ref sd_ble_gap_rssi_stop is called.
gkroussos 0:e8fdba0ed044 868 *
gkroussos 0:e8fdba0ed044 869 * @param[in] conn_handle Connection handle.
gkroussos 0:e8fdba0ed044 870 *
gkroussos 0:e8fdba0ed044 871 * @return @ref NRF_SUCCESS Successfully activated RSSI reporting.
gkroussos 0:e8fdba0ed044 872 * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
gkroussos 0:e8fdba0ed044 873 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
gkroussos 0:e8fdba0ed044 874 */
gkroussos 0:e8fdba0ed044 875 SVCALL(SD_BLE_GAP_RSSI_START, uint32_t, sd_ble_gap_rssi_start(uint16_t conn_handle));
gkroussos 0:e8fdba0ed044 876
gkroussos 0:e8fdba0ed044 877
gkroussos 0:e8fdba0ed044 878 /**@brief Stop reporting the received singnal strength.
gkroussos 0:e8fdba0ed044 879 *
gkroussos 0:e8fdba0ed044 880 * An RSSI change detected before the call but not yet received by the application
gkroussos 0:e8fdba0ed044 881 * may be reported after @ref sd_ble_gap_rssi_stop has been called.
gkroussos 0:e8fdba0ed044 882 *
gkroussos 0:e8fdba0ed044 883 * @param[in] conn_handle Connection handle.
gkroussos 0:e8fdba0ed044 884 *
gkroussos 0:e8fdba0ed044 885 * @return @ref NRF_SUCCESS Successfully deactivated RSSI reporting.
gkroussos 0:e8fdba0ed044 886 * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
gkroussos 0:e8fdba0ed044 887 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
gkroussos 0:e8fdba0ed044 888 */
gkroussos 0:e8fdba0ed044 889 SVCALL(SD_BLE_GAP_RSSI_STOP, uint32_t, sd_ble_gap_rssi_stop(uint16_t conn_handle));
gkroussos 0:e8fdba0ed044 890
gkroussos 0:e8fdba0ed044 891 #endif // BLE_GAP_H__
gkroussos 0:e8fdba0ed044 892
gkroussos 0:e8fdba0ed044 893 /**
gkroussos 0:e8fdba0ed044 894 @}
gkroussos 0:e8fdba0ed044 895 */