David Kester / nRF51822

Dependents:   GonioTrainer

Fork of nRF51822 by Nordic Semiconductor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ble_gap.h Source File

ble_gap.h

00001 /* 
00002  * Copyright (c) Nordic Semiconductor ASA
00003  * All rights reserved.
00004  * 
00005  * Redistribution and use in source and binary forms, with or without modification,
00006  * are permitted provided that the following conditions are met:
00007  * 
00008  *   1. Redistributions of source code must retain the above copyright notice, this
00009  *   list of conditions and the following disclaimer.
00010  * 
00011  *   2. Redistributions in binary form must reproduce the above copyright notice, this
00012  *   list of conditions and the following disclaimer in the documentation and/or
00013  *   other materials provided with the distribution.
00014  * 
00015  *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
00016  *   contributors to this software may be used to endorse or promote products
00017  *   derived from this software without specific prior written permission.
00018  * 
00019  *   4. This software must only be used in a processor manufactured by Nordic
00020  *   Semiconductor ASA, or in a processor manufactured by a third party that
00021  *   is used in combination with a processor manufactured by Nordic Semiconductor.
00022  * 
00023  * 
00024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00025  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00026  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
00028  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00029  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00031  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00033  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  * 
00035  */
00036 
00037 /**
00038   @addtogroup BLE_GAP Generic Access Profile (GAP)
00039   @{
00040   @brief Definitions and prototypes for the GAP interface.
00041  */
00042 
00043 #ifndef BLE_GAP_H__
00044 #define BLE_GAP_H__
00045 
00046 #include "ble_types.h"
00047 #include "ble_ranges.h"
00048 #include "nrf_svc.h"
00049 
00050 /**@addtogroup BLE_GAP_ENUMERATIONS Enumerations
00051  * @{ */
00052 
00053 /**@brief GAP API SVC numbers.
00054  */
00055 enum BLE_GAP_SVCS
00056 {
00057   SD_BLE_GAP_ADDRESS_SET  = BLE_GAP_SVC_BASE,  /**< Set own Bluetooth Address. */
00058   SD_BLE_GAP_ADDRESS_GET,                      /**< Get own Bluetooth Address. */
00059   SD_BLE_GAP_ADV_DATA_SET,                     /**< Set Advertising Data. */
00060   SD_BLE_GAP_ADV_START,                        /**< Start Advertising. */
00061   SD_BLE_GAP_ADV_STOP,                         /**< Stop Advertising. */
00062   SD_BLE_GAP_CONN_PARAM_UPDATE,                /**< Connection Parameter Update. */
00063   SD_BLE_GAP_DISCONNECT,                       /**< Disconnect. */
00064   SD_BLE_GAP_TX_POWER_SET,                     /**< Set TX Power. */
00065   SD_BLE_GAP_APPEARANCE_SET,                   /**< Set Appearance. */
00066   SD_BLE_GAP_APPEARANCE_GET,                   /**< Get Appearance. */
00067   SD_BLE_GAP_PPCP_SET,                         /**< Set PPCP. */
00068   SD_BLE_GAP_PPCP_GET,                         /**< Get PPCP. */
00069   SD_BLE_GAP_DEVICE_NAME_SET,                  /**< Set Device Name. */
00070   SD_BLE_GAP_DEVICE_NAME_GET,                  /**< Get Device Name. */
00071   SD_BLE_GAP_AUTHENTICATE,                     /**< Initiate Pairing/Bonding. */
00072   SD_BLE_GAP_SEC_PARAMS_REPLY,                 /**< Reply with Security Parameters. */
00073   SD_BLE_GAP_AUTH_KEY_REPLY,                   /**< Reply with an authentication key. */
00074   SD_BLE_GAP_ENCRYPT,                          /**< Initiate encryption procedure. */
00075   SD_BLE_GAP_SEC_INFO_REPLY,                   /**< Reply with Security Information. */
00076   SD_BLE_GAP_CONN_SEC_GET,                     /**< Obtain connection security level. */
00077   SD_BLE_GAP_RSSI_START,                       /**< Start reporting of changes in RSSI. */ 
00078   SD_BLE_GAP_RSSI_STOP,                        /**< Stop reporting of changes in RSSI. */ 
00079   SD_BLE_GAP_SCAN_START,                       /**< Start Scanning. */
00080   SD_BLE_GAP_SCAN_STOP,                        /**< Stop Scanning. */
00081   SD_BLE_GAP_CONNECT,                          /**< Connect. */
00082   SD_BLE_GAP_CONNECT_CANCEL,                   /**< Cancel ongoing connection procedure. */
00083   SD_BLE_GAP_RSSI_GET,                         /**< Get the last RSSI sample. */
00084 };
00085 
00086 /**@brief GAP Event IDs.
00087  * IDs that uniquely identify an event coming from the stack to the application.
00088  */
00089 enum BLE_GAP_EVTS
00090 {
00091   BLE_GAP_EVT_CONNECTED  = BLE_GAP_EVT_BASE,    /**< Connection established. @ref ble_gap_evt_connected_t */
00092   BLE_GAP_EVT_DISCONNECTED,                     /**< Disconnected from peer. @ref ble_gap_evt_disconnected_t */
00093   BLE_GAP_EVT_CONN_PARAM_UPDATE,                /**< Connection Parameters updated. ble_gap_evt_conn_param_update_t */
00094   BLE_GAP_EVT_SEC_PARAMS_REQUEST,               /**< Request to provide security parameters. @ref ble_gap_evt_sec_params_request_t */
00095   BLE_GAP_EVT_SEC_INFO_REQUEST,                 /**< Request to provide security information. @ref ble_gap_evt_sec_info_request_t */
00096   BLE_GAP_EVT_PASSKEY_DISPLAY,                  /**< Request to display a passkey to the user. @ref ble_gap_evt_passkey_display_t */
00097   BLE_GAP_EVT_AUTH_KEY_REQUEST,                 /**< Request to provide an authentication key. @ref ble_gap_evt_auth_key_request_t */
00098   BLE_GAP_EVT_AUTH_STATUS,                      /**< Authentication procedure completed with status. @ref ble_gap_evt_auth_status_t */
00099   BLE_GAP_EVT_CONN_SEC_UPDATE,                  /**< Connection security updated. @ref ble_gap_evt_conn_sec_update_t */
00100   BLE_GAP_EVT_TIMEOUT,                          /**< Timeout expired. @ref ble_gap_evt_timeout_t */
00101   BLE_GAP_EVT_RSSI_CHANGED,                     /**< RSSI report. @ref ble_gap_evt_rssi_changed_t */
00102   BLE_GAP_EVT_ADV_REPORT,                       /**< Advertising report. @ref ble_gap_evt_adv_report_t */
00103   BLE_GAP_EVT_SEC_REQUEST,                      /**< Security Request. @ref ble_gap_evt_sec_request_t */
00104   BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST,        /**< Connection Parameter Update Request. @ref ble_gap_evt_conn_param_update_request_t */
00105   BLE_GAP_EVT_SCAN_REQ_REPORT,                  /**< Scan request report. @ref ble_gap_evt_scan_req_report_t */
00106 };
00107 
00108 /**@brief GAP Option IDs.
00109  * IDs that uniquely identify a GAP option.
00110  */
00111 enum BLE_GAP_OPTS
00112 {
00113   BLE_GAP_OPT_CH_MAP  = BLE_GAP_OPT_BASE,       /**< Channel Map. @ref ble_gap_opt_ch_map_t  */
00114   BLE_GAP_OPT_LOCAL_CONN_LATENCY,               /**< Local connection latency. @ref ble_gap_opt_local_conn_latency_t */
00115   BLE_GAP_OPT_PASSKEY,                          /**< Set passkey. @ref ble_gap_opt_passkey_t */
00116   BLE_GAP_OPT_PRIVACY,                          /**< Custom privacy. @ref ble_gap_opt_privacy_t */
00117   BLE_GAP_OPT_SCAN_REQ_REPORT,                  /**< Scan request report. @ref ble_gap_opt_scan_req_report_t */
00118   BLE_GAP_OPT_COMPAT_MODE                       /**< Compatibility mode. @ref ble_gap_opt_compat_mode_t */
00119 };
00120 /** @} */
00121 
00122 /**@addtogroup BLE_GAP_DEFINES Defines
00123  * @{ */
00124 
00125 /**@defgroup BLE_ERRORS_GAP SVC return values specific to GAP
00126  * @{ */
00127 #define BLE_ERROR_GAP_UUID_LIST_MISMATCH            (NRF_GAP_ERR_BASE + 0x000)  /**< UUID list does not contain an integral number of UUIDs. */
00128 #define BLE_ERROR_GAP_DISCOVERABLE_WITH_WHITELIST   (NRF_GAP_ERR_BASE + 0x001)  /**< Use of Whitelist not permitted with discoverable advertising. */
00129 #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. */
00130 #define BLE_ERROR_GAP_WHITELIST_IN_USE              (NRF_GAP_ERR_BASE + 0x003)  /**< Attempt to overwrite the whitelist while already in use by another operation. */ 
00131 /**@} */
00132 
00133 
00134 /**@defgroup BLE_GAP_ROLES GAP Roles
00135  * @note Not explicitly used in peripheral API, but will be relevant for central API.
00136  * @{ */
00137 #define BLE_GAP_ROLE_INVALID     0x0            /**< Invalid Role. */
00138 #define BLE_GAP_ROLE_PERIPH      0x1            /**< Peripheral Role. */
00139 #define BLE_GAP_ROLE_CENTRAL     0x2            /**< Central Role. */
00140 /**@} */
00141 
00142 
00143 /**@defgroup BLE_GAP_TIMEOUT_SOURCES GAP Timeout sources
00144  * @{ */
00145 #define BLE_GAP_TIMEOUT_SRC_ADVERTISING                0x00 /**< Advertising timeout. */
00146 #define BLE_GAP_TIMEOUT_SRC_SECURITY_REQUEST           0x01 /**< Security request timeout. */
00147 #define BLE_GAP_TIMEOUT_SRC_SCAN                       0x02 /**< Scanning timeout. */
00148 #define BLE_GAP_TIMEOUT_SRC_CONN                       0x03 /**< Connection timeout. */
00149 /**@} */
00150 
00151 
00152 /**@defgroup BLE_GAP_ADDR_TYPES GAP Address types
00153  * @{ */
00154 #define BLE_GAP_ADDR_TYPE_PUBLIC                        0x00 /**< Public address. */
00155 #define BLE_GAP_ADDR_TYPE_RANDOM_STATIC                 0x01 /**< Random Static address. */
00156 #define BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE     0x02 /**< Private Resolvable address. */
00157 #define BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE 0x03 /**< Private Non-Resolvable address. */
00158 /**@} */
00159 
00160 /**@defgroup BLE_GAP_ADDR_CYCLE_MODES GAP Address cycle modes
00161  * @{ */
00162 #define BLE_GAP_ADDR_CYCLE_MODE_NONE      0x00 /**< Set addresses directly, no automatic address cycling. */
00163 #define BLE_GAP_ADDR_CYCLE_MODE_AUTO      0x01 /**< Automatically generate and update private addresses. */
00164 /** @} */
00165 
00166 /**@brief The default interval in seconds at which a private address is refreshed when address cycle mode is @ref BLE_GAP_ADDR_CYCLE_MODE_AUTO.  */
00167 #define BLE_GAP_DEFAULT_PRIVATE_ADDR_CYCLE_INTERVAL_S (60 * 15)
00168 
00169 /** @brief BLE address length. */
00170 #define BLE_GAP_ADDR_LEN            6
00171 
00172 
00173 /**@defgroup BLE_GAP_AD_TYPE_DEFINITIONS GAP Advertising and Scan Response Data format
00174  * @note Found at https://www.bluetooth.org/Technical/AssignedNumbers/generic_access_profile.htm
00175  * @{ */
00176 #define BLE_GAP_AD_TYPE_FLAGS                               0x01 /**< Flags for discoverability. */
00177 #define BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE   0x02 /**< Partial list of 16 bit service UUIDs. */
00178 #define BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE         0x03 /**< Complete list of 16 bit service UUIDs. */
00179 #define BLE_GAP_AD_TYPE_32BIT_SERVICE_UUID_MORE_AVAILABLE   0x04 /**< Partial list of 32 bit service UUIDs. */
00180 #define BLE_GAP_AD_TYPE_32BIT_SERVICE_UUID_COMPLETE         0x05 /**< Complete list of 32 bit service UUIDs. */
00181 #define BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_MORE_AVAILABLE  0x06 /**< Partial list of 128 bit service UUIDs. */
00182 #define BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE        0x07 /**< Complete list of 128 bit service UUIDs. */
00183 #define BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME                    0x08 /**< Short local device name. */
00184 #define BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME                 0x09 /**< Complete local device name. */
00185 #define BLE_GAP_AD_TYPE_TX_POWER_LEVEL                      0x0A /**< Transmit power level. */
00186 #define BLE_GAP_AD_TYPE_CLASS_OF_DEVICE                     0x0D /**< Class of device. */
00187 #define BLE_GAP_AD_TYPE_SIMPLE_PAIRING_HASH_C               0x0E /**< Simple Pairing Hash C. */
00188 #define BLE_GAP_AD_TYPE_SIMPLE_PAIRING_RANDOMIZER_R         0x0F /**< Simple Pairing Randomizer R. */
00189 #define BLE_GAP_AD_TYPE_SECURITY_MANAGER_TK_VALUE           0x10 /**< Security Manager TK Value. */
00190 #define BLE_GAP_AD_TYPE_SECURITY_MANAGER_OOB_FLAGS          0x11 /**< Security Manager Out Of Band Flags. */
00191 #define BLE_GAP_AD_TYPE_SLAVE_CONNECTION_INTERVAL_RANGE     0x12 /**< Slave Connection Interval Range. */
00192 #define BLE_GAP_AD_TYPE_SOLICITED_SERVICE_UUIDS_16BIT       0x14 /**< List of 16-bit Service Solicitation UUIDs. */
00193 #define BLE_GAP_AD_TYPE_SOLICITED_SERVICE_UUIDS_128BIT      0x15 /**< List of 128-bit Service Solicitation UUIDs. */
00194 #define BLE_GAP_AD_TYPE_SERVICE_DATA                        0x16 /**< Service Data - 16-bit UUID. */
00195 #define BLE_GAP_AD_TYPE_PUBLIC_TARGET_ADDRESS               0x17 /**< Public Target Address. */
00196 #define BLE_GAP_AD_TYPE_RANDOM_TARGET_ADDRESS               0x18 /**< Random Target Address. */
00197 #define BLE_GAP_AD_TYPE_APPEARANCE                          0x19 /**< Appearance. */
00198 #define BLE_GAP_AD_TYPE_ADVERTISING_INTERVAL                0x1A /**< Advertising Interval. */ 
00199 #define BLE_GAP_AD_TYPE_LE_BLUETOOTH_DEVICE_ADDRESS         0x1B /**< LE Bluetooth Device Address. */
00200 #define BLE_GAP_AD_TYPE_LE_ROLE                             0x1C /**< LE Role. */
00201 #define BLE_GAP_AD_TYPE_SIMPLE_PAIRING_HASH_C256            0x1D /**< Simple Pairing Hash C-256. */
00202 #define BLE_GAP_AD_TYPE_SIMPLE_PAIRING_RANDOMIZER_R256      0x1E /**< Simple Pairing Randomizer R-256. */
00203 #define BLE_GAP_AD_TYPE_SERVICE_DATA_32BIT_UUID             0x20 /**< Service Data - 32-bit UUID. */
00204 #define BLE_GAP_AD_TYPE_SERVICE_DATA_128BIT_UUID            0x21 /**< Service Data - 128-bit UUID. */
00205 #define BLE_GAP_AD_TYPE_3D_INFORMATION_DATA                 0x3D /**< 3D Information Data. */
00206 #define BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA          0xFF /**< Manufacturer Specific Data. */
00207 /**@} */
00208 
00209 
00210 /**@defgroup BLE_GAP_ADV_FLAGS GAP Advertisement Flags
00211  * @{ */
00212 #define BLE_GAP_ADV_FLAG_LE_LIMITED_DISC_MODE         (0x01)   /**< LE Limited Discoverable Mode. */
00213 #define BLE_GAP_ADV_FLAG_LE_GENERAL_DISC_MODE         (0x02)   /**< LE General Discoverable Mode. */
00214 #define BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED         (0x04)   /**< BR/EDR not supported. */
00215 #define BLE_GAP_ADV_FLAG_LE_BR_EDR_CONTROLLER         (0x08)   /**< Simultaneous LE and BR/EDR, Controller. */
00216 #define BLE_GAP_ADV_FLAG_LE_BR_EDR_HOST               (0x10)   /**< Simultaneous LE and BR/EDR, Host. */
00217 #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. */
00218 #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. */
00219 /**@} */
00220 
00221 
00222 /**@defgroup BLE_GAP_ADV_INTERVALS GAP Advertising interval max and min
00223  * @{ */
00224 #define BLE_GAP_ADV_INTERVAL_MIN        0x0020 /**< Minimum Advertising interval in 625 us units, i.e. 20 ms. */
00225 #define BLE_GAP_ADV_NONCON_INTERVAL_MIN 0x00A0 /**< Minimum Advertising interval in 625 us units for non connectable mode, i.e. 100 ms. */
00226 #define BLE_GAP_ADV_INTERVAL_MAX        0x4000 /**< Maximum Advertising interval in 625 us units, i.e. 10.24 s. */
00227  /**@}  */
00228 
00229 
00230 /**@defgroup BLE_GAP_SCAN_INTERVALS GAP Scan interval max and min
00231  * @{ */
00232 #define BLE_GAP_SCAN_INTERVAL_MIN       0x0004 /**< Minimum Scan interval in 625 us units, i.e. 2.5 ms. */
00233 #define BLE_GAP_SCAN_INTERVAL_MAX       0x4000 /**< Maximum Scan interval in 625 us units, i.e. 10.24 s. */
00234  /** @}  */
00235 
00236 
00237 /**@defgroup BLE_GAP_SCAN_WINDOW GAP Scan window max and min
00238  * @{ */
00239 #define BLE_GAP_SCAN_WINDOW_MIN         0x0004 /**< Minimum Scan window in 625 us units, i.e. 2.5 ms. */
00240 #define BLE_GAP_SCAN_WINDOW_MAX         0x4000 /**< Maximum Scan window in 625 us units, i.e. 10.24 s. */
00241  /** @}  */
00242 
00243 
00244 /**@defgroup BLE_GAP_SCAN_TIMEOUT GAP Scan timeout max and min
00245  * @{ */
00246 #define BLE_GAP_SCAN_TIMEOUT_MIN        0x0001 /**< Minimum Scan timeout in seconds. */
00247 #define BLE_GAP_SCAN_TIMEOUT_MAX        0xFFFF /**< Maximum Scan timeout in seconds. */
00248  /** @}  */
00249 
00250 
00251 /**@brief Maximum size of advertising data in octets. */
00252 #define  BLE_GAP_ADV_MAX_SIZE           31
00253 
00254 
00255 /**@defgroup BLE_GAP_ADV_TYPES GAP Advertising types
00256  * @{ */
00257 #define BLE_GAP_ADV_TYPE_ADV_IND          0x00   /**< Connectable undirected. */
00258 #define BLE_GAP_ADV_TYPE_ADV_DIRECT_IND   0x01   /**< Connectable directed. */
00259 #define BLE_GAP_ADV_TYPE_ADV_SCAN_IND     0x02   /**< Scannable undirected. */
00260 #define BLE_GAP_ADV_TYPE_ADV_NONCONN_IND  0x03   /**< Non connectable undirected. */
00261 /**@} */
00262 
00263 
00264 /**@defgroup BLE_GAP_ADV_FILTER_POLICIES GAP Advertising filter policies
00265  * @{ */
00266 #define BLE_GAP_ADV_FP_ANY                0x00   /**< Allow scan requests and connect requests from any device. */
00267 #define BLE_GAP_ADV_FP_FILTER_SCANREQ     0x01   /**< Filter scan requests with whitelist. */
00268 #define BLE_GAP_ADV_FP_FILTER_CONNREQ     0x02   /**< Filter connect requests with whitelist. */
00269 #define BLE_GAP_ADV_FP_FILTER_BOTH        0x03   /**< Filter both scan and connect requests with whitelist. */
00270 /**@} */
00271 
00272 
00273 /**@defgroup BLE_GAP_ADV_TIMEOUT_VALUES GAP Advertising timeout values
00274  * @{ */
00275 #define BLE_GAP_ADV_TIMEOUT_LIMITED_MAX      180 /**< Maximum advertising time in limited discoverable mode (TGAP(lim_adv_timeout) = 180s). */
00276 #define BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED  0 /**< Unlimited advertising in general discoverable mode. */
00277 /**@} */
00278 
00279 
00280 /**@defgroup BLE_GAP_DISC_MODES GAP Discovery modes
00281  * @{ */
00282 #define BLE_GAP_DISC_MODE_NOT_DISCOVERABLE  0x00   /**< Not discoverable discovery Mode. */
00283 #define BLE_GAP_DISC_MODE_LIMITED           0x01   /**< Limited Discovery Mode. */
00284 #define BLE_GAP_DISC_MODE_GENERAL           0x02   /**< General Discovery Mode. */
00285 /**@} */
00286 
00287 /**@defgroup BLE_GAP_IO_CAPS GAP IO Capabilities
00288  * @{ */
00289 #define BLE_GAP_IO_CAPS_DISPLAY_ONLY      0x00   /**< Display Only. */
00290 #define BLE_GAP_IO_CAPS_DISPLAY_YESNO     0x01   /**< Display and Yes/No entry. */
00291 #define BLE_GAP_IO_CAPS_KEYBOARD_ONLY     0x02   /**< Keyboard Only. */
00292 #define BLE_GAP_IO_CAPS_NONE              0x03   /**< No I/O capabilities. */
00293 #define BLE_GAP_IO_CAPS_KEYBOARD_DISPLAY  0x04   /**< Keyboard and Display. */
00294 /**@} */
00295 
00296 
00297 /**@defgroup BLE_GAP_AUTH_KEY_TYPES GAP Authentication Key Types
00298  * @{ */
00299 #define BLE_GAP_AUTH_KEY_TYPE_NONE        0x00   /**< No key (may be used to reject). */
00300 #define BLE_GAP_AUTH_KEY_TYPE_PASSKEY     0x01   /**< 6-digit Passkey. */
00301 #define BLE_GAP_AUTH_KEY_TYPE_OOB         0x02   /**< Out Of Band data. */
00302 /**@} */
00303 
00304 /**@defgroup BLE_GAP_SEC_STATUS GAP Security status
00305  * @{ */
00306 #define BLE_GAP_SEC_STATUS_SUCCESS                0x00  /**< Procedure completed with success. */
00307 #define BLE_GAP_SEC_STATUS_TIMEOUT                0x01  /**< Procedure timed out. */
00308 #define BLE_GAP_SEC_STATUS_PDU_INVALID            0x02  /**< Invalid PDU received. */
00309 #define BLE_GAP_SEC_STATUS_RFU_RANGE1_BEGIN       0x03  /**< Reserved for Future Use range #1 begin. */
00310 #define BLE_GAP_SEC_STATUS_RFU_RANGE1_END         0x80  /**< Reserved for Future Use range #1 end. */
00311 #define BLE_GAP_SEC_STATUS_PASSKEY_ENTRY_FAILED   0x81  /**< Passkey entry failed (user cancelled or other). */
00312 #define BLE_GAP_SEC_STATUS_OOB_NOT_AVAILABLE      0x82  /**< Out of Band Key not available. */
00313 #define BLE_GAP_SEC_STATUS_AUTH_REQ               0x83  /**< Authentication requirements not met. */
00314 #define BLE_GAP_SEC_STATUS_CONFIRM_VALUE          0x84  /**< Confirm value failed. */
00315 #define BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP       0x85  /**< Pairing not supported.  */
00316 #define BLE_GAP_SEC_STATUS_ENC_KEY_SIZE           0x86  /**< Encryption key size. */
00317 #define BLE_GAP_SEC_STATUS_SMP_CMD_UNSUPPORTED    0x87  /**< Unsupported SMP command. */
00318 #define BLE_GAP_SEC_STATUS_UNSPECIFIED            0x88  /**< Unspecified reason. */
00319 #define BLE_GAP_SEC_STATUS_REPEATED_ATTEMPTS      0x89  /**< Too little time elapsed since last attempt. */
00320 #define BLE_GAP_SEC_STATUS_INVALID_PARAMS         0x8A  /**< Invalid parameters. */
00321 #define BLE_GAP_SEC_STATUS_RFU_RANGE2_BEGIN       0x8B  /**< Reserved for Future Use range #2 begin. */
00322 #define BLE_GAP_SEC_STATUS_RFU_RANGE2_END         0xFF  /**< Reserved for Future Use range #2 end. */
00323 /**@} */
00324 
00325 /**@defgroup BLE_GAP_SEC_STATUS_SOURCES GAP Security status sources
00326  * @{ */
00327 #define BLE_GAP_SEC_STATUS_SOURCE_LOCAL           0x00  /**< Local failure. */
00328 #define BLE_GAP_SEC_STATUS_SOURCE_REMOTE          0x01  /**< Remote failure. */
00329 /**@} */
00330 
00331 /**@defgroup BLE_GAP_CP_LIMITS GAP Connection Parameters Limits
00332  * @{ */
00333 #define BLE_GAP_CP_MIN_CONN_INTVL_NONE           0xFFFF  /**< No new minimum connction interval specified in connect parameters. */
00334 #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. */
00335 #define BLE_GAP_CP_MIN_CONN_INTVL_MAX            0x0C80  /**< Highest minimum connection interval permitted, in units of 1.25 ms, i.e. 4 s. */
00336 #define BLE_GAP_CP_MAX_CONN_INTVL_NONE           0xFFFF  /**< No new maximum connction interval specified in connect parameters. */
00337 #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. */
00338 #define BLE_GAP_CP_MAX_CONN_INTVL_MAX            0x0C80  /**< Highest maximum connection interval permitted, in units of 1.25 ms, i.e. 4 s. */
00339 #define BLE_GAP_CP_SLAVE_LATENCY_MAX             0x01F3  /**< Highest slave latency permitted, in connection events. */
00340 #define BLE_GAP_CP_CONN_SUP_TIMEOUT_NONE         0xFFFF  /**< No new supervision timeout specified in connect parameters. */
00341 #define BLE_GAP_CP_CONN_SUP_TIMEOUT_MIN          0x000A  /**< Lowest supervision timeout permitted, in units of 10 ms, i.e. 100 ms. */
00342 #define BLE_GAP_CP_CONN_SUP_TIMEOUT_MAX          0x0C80  /**< Highest supervision timeout permitted, in units of 10 ms, i.e. 32 s. */
00343 /**@} */
00344 
00345 
00346 /**@brief GAP device name maximum length. */
00347 #define BLE_GAP_DEVNAME_MAX_LEN           31
00348 
00349 /**@brief Disable RSSI events for connections */
00350 #define BLE_GAP_RSSI_THRESHOLD_INVALID    0xFF
00351 
00352 /**@defgroup BLE_GAP_CONN_SEC_MODE_SET_MACROS GAP attribute security requirement setters
00353  *
00354  * See @ref ble_gap_conn_sec_mode_t.
00355  * @{ */
00356 /**@brief Set sec_mode pointed to by ptr to have no access rights.*/
00357 #define BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(ptr)         do {(ptr)->sm = 0; (ptr)->lv = 0;} while(0)
00358 /**@brief Set sec_mode pointed to by ptr to require no protection, open link.*/
00359 #define BLE_GAP_CONN_SEC_MODE_SET_OPEN(ptr)              do {(ptr)->sm = 1; (ptr)->lv = 1;} while(0)
00360 /**@brief Set sec_mode pointed to by ptr to require encryption, but no MITM protection.*/
00361 #define BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(ptr)       do {(ptr)->sm = 1; (ptr)->lv = 2;} while(0)
00362 /**@brief Set sec_mode pointed to by ptr to require encryption and MITM protection.*/
00363 #define BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(ptr)     do {(ptr)->sm = 1; (ptr)->lv = 3;} while(0)
00364 /**@brief Set sec_mode pointed to by ptr to require signing or encryption, no MITM protection needed.*/
00365 #define BLE_GAP_CONN_SEC_MODE_SET_SIGNED_NO_MITM(ptr)    do {(ptr)->sm = 2; (ptr)->lv = 1;} while(0)
00366 /**@brief Set sec_mode pointed to by ptr to require signing or encryption with MITM protection.*/
00367 #define BLE_GAP_CONN_SEC_MODE_SET_SIGNED_WITH_MITM(ptr)  do {(ptr)->sm = 2; (ptr)->lv = 2;} while(0)
00368 /**@} */
00369 
00370 
00371 /**@brief GAP Security Random Number Length. */
00372 #define BLE_GAP_SEC_RAND_LEN 8
00373 
00374 /**@brief GAP Security Key Length. */
00375 #define BLE_GAP_SEC_KEY_LEN 16
00376 
00377 /**@brief GAP Passkey Length. */
00378 #define BLE_GAP_PASSKEY_LEN 6
00379 
00380 /**@brief Maximum amount of addresses in a whitelist. */
00381 #define BLE_GAP_WHITELIST_ADDR_MAX_COUNT (8)
00382 
00383 /**@brief Maximum amount of IRKs in a whitelist.
00384  * @note  The number of IRKs is limited to 8, even if the hardware supports more.
00385  */
00386 #define BLE_GAP_WHITELIST_IRK_MAX_COUNT (8)
00387 
00388 /**@defgroup GAP_SEC_MODES GAP Security Modes
00389  * @{ */
00390 #define BLE_GAP_SEC_MODE 0x00 /**< No key (may be used to reject). */
00391 /**@} */
00392 
00393 /**@} */
00394 
00395 /**@addtogroup BLE_GAP_STRUCTURES Structures
00396  * @{ */
00397 
00398 /**@brief Bluetooth Low Energy address. */
00399 typedef struct
00400 {
00401   uint8_t addr_type;                    /**< See @ref BLE_GAP_ADDR_TYPES. */
00402   uint8_t addr[BLE_GAP_ADDR_LEN];       /**< 48-bit address, LSB format. */
00403 } ble_gap_addr_t;
00404 
00405 
00406 /**@brief GAP connection parameters.
00407  *
00408  * @note  When ble_conn_params_t is received in an event, both min_conn_interval and
00409  *        max_conn_interval will be equal to the connection interval set by the central.
00410  *
00411  * @note If both conn_sup_timeout and max_conn_interval are specified, then the following constraint applies:
00412  *       conn_sup_timeout * 4 > (1 + slave_latency) * max_conn_interval
00413  *       that corresponds to the following Bluetooth Spec requirement:
00414  *       The Supervision_Timeout in milliseconds shall be larger than
00415  *       (1 + Conn_Latency) * Conn_Interval_Max * 2, where Conn_Interval_Max is given in milliseconds.
00416  */
00417 typedef struct
00418 {
00419   uint16_t min_conn_interval;         /**< Minimum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/
00420   uint16_t max_conn_interval;         /**< Maximum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/
00421   uint16_t slave_latency;             /**< Slave Latency in number of connection events, see @ref BLE_GAP_CP_LIMITS.*/
00422   uint16_t conn_sup_timeout;          /**< Connection Supervision Timeout in 10 ms units, see @ref BLE_GAP_CP_LIMITS.*/
00423 } ble_gap_conn_params_t;
00424 
00425 
00426 /**@brief GAP connection security modes.
00427  *
00428  * Security Mode 0 Level 0: No access permissions at all (this level is not defined by the Bluetooth Core specification).\n
00429  * Security Mode 1 Level 1: No security is needed (aka open link).\n
00430  * Security Mode 1 Level 2: Encrypted link required, MITM protection not necessary.\n
00431  * Security Mode 1 Level 3: MITM protected encrypted link required.\n
00432  * Security Mode 2 Level 1: Signing or encryption required, MITM protection not necessary.\n
00433  * Security Mode 2 Level 2: MITM protected signing required, unless link is MITM protected encrypted.\n
00434  */
00435 typedef struct
00436 {
00437   uint8_t sm : 4;                     /**< Security Mode (1 or 2), 0 for no permissions at all. */
00438   uint8_t lv : 4;                     /**< Level (1, 2 or 3), 0 for no permissions at all. */
00439 
00440 } ble_gap_conn_sec_mode_t;
00441 
00442 
00443 /**@brief GAP connection security status.*/
00444 typedef struct
00445 {
00446   ble_gap_conn_sec_mode_t sec_mode;           /**< Currently active security mode for this connection.*/
00447   uint8_t                 encr_key_size;      /**< Length of currently active encryption key, 7 to 16 octets (only applicable for bonding procedures). */
00448 } ble_gap_conn_sec_t;
00449 
00450 
00451 /**@brief Identity Resolving Key. */
00452 typedef struct
00453 {
00454   uint8_t irk[BLE_GAP_SEC_KEY_LEN];   /**< Array containing IRK. */
00455 } ble_gap_irk_t;
00456 
00457 
00458 /**@brief Whitelist structure. */
00459 typedef struct
00460 {
00461   ble_gap_addr_t    **pp_addrs;        /**< Pointer to an array of device address pointers, pointing to addresses to be used in whitelist. NULL if none are given. */
00462   uint8_t             addr_count;      /**< Count of device addresses in array, up to @ref BLE_GAP_WHITELIST_ADDR_MAX_COUNT. */
00463   ble_gap_irk_t     **pp_irks;         /**< Pointer to an array of Identity Resolving Key (IRK) pointers, each pointing to an IRK in the whitelist. NULL if none are given. */
00464   uint8_t             irk_count;       /**< Count of IRKs in array, up to @ref BLE_GAP_WHITELIST_IRK_MAX_COUNT. */
00465 } ble_gap_whitelist_t;
00466 
00467 /**@brief Channel mask for RF channels used in advertising and scanning. */ 
00468 typedef struct
00469 {
00470   uint8_t ch_37_off : 1;  /**< Setting this bit to 1 will turn off advertising on channel 37 */
00471   uint8_t ch_38_off : 1;  /**< Setting this bit to 1 will turn off advertising on channel 38 */
00472   uint8_t ch_39_off : 1;  /**< Setting this bit to 1 will turn off advertising on channel 39 */
00473 } ble_gap_adv_ch_mask_t;
00474 
00475 /**@brief GAP advertising parameters.*/
00476 typedef struct
00477 {
00478   uint8_t               type;                 /**< See @ref BLE_GAP_ADV_TYPES. */
00479   ble_gap_addr_t       *p_peer_addr;          /**< For @ref BLE_GAP_ADV_TYPE_ADV_DIRECT_IND mode only, known peer address. */
00480   uint8_t               fp;                   /**< Filter Policy, see @ref BLE_GAP_ADV_FILTER_POLICIES. */
00481   ble_gap_whitelist_t  *p_whitelist;          /**< Pointer to whitelist, NULL if no whitelist or the current active whitelist is to be used. */
00482   uint16_t              interval;             /**< Advertising interval between 0x0020 and 0x4000 in 0.625 ms units (20ms to 10.24s), see @ref BLE_GAP_ADV_INTERVALS.
00483                                                    - If type equals @ref BLE_GAP_ADV_TYPE_ADV_DIRECT_IND, this parameter must be set to 0 for high duty cycle directed advertising.
00484                                                    - If type equals @ref BLE_GAP_ADV_TYPE_ADV_DIRECT_IND, set @ref BLE_GAP_ADV_INTERVAL_MIN <= interval <= @ref BLE_GAP_ADV_INTERVAL_MAX for low duty cycle advertising.*/
00485   uint16_t              timeout;              /**< Advertising timeout between 0x0001 and 0x3FFF in seconds, 0x0000 disables timeout. See also @ref BLE_GAP_ADV_TIMEOUT_VALUES. If type equals @ref BLE_GAP_ADV_TYPE_ADV_DIRECT_IND, this parameter must be set to 0 for High duty cycle directed advertising. */
00486   ble_gap_adv_ch_mask_t channel_mask;         /**< Advertising channel mask. @see ble_gap_channel_mask_t for documentation. */
00487 } ble_gap_adv_params_t;
00488 
00489 
00490 /**@brief GAP scanning parameters. */
00491 typedef struct
00492 {
00493   uint8_t                 active    : 1;        /**< If 1, perform active scanning (scan requests). */
00494   uint8_t                 selective : 1;        /**< If 1, ignore unknown devices (non whitelisted). */
00495   ble_gap_whitelist_t *   p_whitelist;          /**< Pointer to whitelist, NULL if no whitelist or the current active whitelist is to be used. */
00496   uint16_t                interval;             /**< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
00497   uint16_t                window;               /**< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
00498   uint16_t                timeout;              /**< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */
00499 } ble_gap_scan_params_t;
00500 
00501 
00502 /** @brief Keys that can be exchanged during a bonding procedure. */
00503 typedef struct
00504 {
00505   uint8_t enc     : 1;                        /**< Long Term Key and Master Identification. */
00506   uint8_t id      : 1;                        /**< Identity Resolving Key and Identity Address Information. */
00507   uint8_t sign    : 1;                        /**< Connection Signature Resolving Key. */
00508 } ble_gap_sec_kdist_t;
00509 
00510 
00511 /**@brief GAP security parameters. */
00512 typedef struct
00513 {
00514   uint8_t               bond    : 1;               /**< Perform bonding. */
00515   uint8_t               mitm    : 1;               /**< Man In The Middle protection required. */
00516   uint8_t               io_caps : 3;               /**< IO capabilities, see @ref BLE_GAP_IO_CAPS. */
00517   uint8_t               oob     : 1;               /**< Out Of Band data available. */
00518   uint8_t               min_key_size;              /**< Minimum encryption key size in octets between 7 and 16. If 0 then not applicable in this instance. */
00519   uint8_t               max_key_size;              /**< Maximum encryption key size in octets between min_key_size and 16. */
00520   ble_gap_sec_kdist_t   kdist_periph;              /**< Key distribution bitmap: keys that the peripheral device will distribute. */
00521   ble_gap_sec_kdist_t   kdist_central;             /**< Key distribution bitmap: keys that the central device will distribute. */
00522 } ble_gap_sec_params_t;
00523 
00524 
00525 /**@brief GAP Encryption Information. */
00526 typedef struct
00527 {
00528   uint8_t   ltk[BLE_GAP_SEC_KEY_LEN];   /**< Long Term Key. */
00529   uint8_t   auth : 1;                   /**< Authenticated Key. */
00530   uint8_t   ltk_len : 7;                /**< LTK length in octets. */
00531 } ble_gap_enc_info_t;
00532 
00533 
00534 /**@brief GAP Master Identification. */
00535 typedef struct
00536 {
00537   uint16_t  ediv;                       /**< Encrypted Diversifier. */
00538   uint8_t   rand[BLE_GAP_SEC_RAND_LEN]; /**< Random Number. */
00539 } ble_gap_master_id_t;
00540 
00541 
00542 /**@brief GAP Signing Information. */
00543 typedef struct
00544 {
00545   uint8_t   csrk[BLE_GAP_SEC_KEY_LEN];        /**< Connection Signature Resolving Key. */
00546 } ble_gap_sign_info_t;
00547 
00548 
00549 /**@brief Event structure for @ref BLE_GAP_EVT_CONNECTED. */
00550 typedef struct
00551 {
00552   ble_gap_addr_t        peer_addr;              /**< Bluetooth address of the peer device. */
00553   ble_gap_addr_t        own_addr;               /**< Bluetooth address of the local device used during connection setup. */
00554   uint8_t               role;                   /**< BLE role for this connection, see @ref BLE_GAP_ROLES */
00555   uint8_t               irk_match :1;           /**< If 1, peer device's address resolved using an IRK. */
00556   uint8_t               irk_match_idx  :7;      /**< Index in IRK list where the address was matched. */
00557   ble_gap_conn_params_t conn_params;            /**< GAP Connection Parameters. */
00558 } ble_gap_evt_connected_t;
00559 
00560 
00561 /**@brief Event structure for @ref BLE_GAP_EVT_DISCONNECTED. */
00562 typedef struct
00563 {
00564   uint8_t reason;                               /**< HCI error code, see @ref BLE_HCI_STATUS_CODES. */
00565 } ble_gap_evt_disconnected_t;
00566 
00567 
00568 /**@brief Event structure for @ref BLE_GAP_EVT_CONN_PARAM_UPDATE. */
00569 typedef struct
00570 {
00571   ble_gap_conn_params_t conn_params;            /**<  GAP Connection Parameters. */
00572 } ble_gap_evt_conn_param_update_t;
00573 
00574 
00575 /**@brief Event structure for @ref BLE_GAP_EVT_SEC_PARAMS_REQUEST. */
00576 typedef struct
00577 {
00578   ble_gap_sec_params_t peer_params;             /**< Initiator Security Parameters. */
00579 } ble_gap_evt_sec_params_request_t;
00580 
00581 
00582 /**@brief Event structure for @ref BLE_GAP_EVT_SEC_INFO_REQUEST. */
00583 typedef struct
00584 {
00585   ble_gap_addr_t      peer_addr;                     /**< Bluetooth address of the peer device. */
00586   ble_gap_master_id_t master_id;                     /**< Master Identification for LTK lookup. */
00587   uint8_t             enc_info  : 1;                 /**< If 1, Encryption Information required. */
00588   uint8_t             id_info   : 1;                 /**< If 1, Identity Information required. */
00589   uint8_t             sign_info : 1;                 /**< If 1, Signing Information required. */
00590 } ble_gap_evt_sec_info_request_t;
00591 
00592 
00593 /**@brief Event structure for @ref BLE_GAP_EVT_PASSKEY_DISPLAY. */
00594 typedef struct
00595 {
00596   uint8_t passkey[BLE_GAP_PASSKEY_LEN];         /**< 6-digit passkey in ASCII ('0'-'9' digits only). */
00597 } ble_gap_evt_passkey_display_t;
00598 
00599 
00600 /**@brief Event structure for @ref BLE_GAP_EVT_AUTH_KEY_REQUEST. */
00601 typedef struct
00602 {
00603   uint8_t key_type;                             /**< See @ref BLE_GAP_AUTH_KEY_TYPES. */
00604 } ble_gap_evt_auth_key_request_t;
00605 
00606 
00607 /**@brief Security levels supported.
00608  * @note See Bluetooth Specification Version 4.1 Volume 3, Part C, Chapter 10.
00609 */
00610 typedef struct
00611 {
00612   uint8_t lv1 : 1;                              /**< If 1: Level 1 is supported. */
00613   uint8_t lv2 : 1;                              /**< If 1: Level 2 is supported. */
00614   uint8_t lv3 : 1;                              /**< If 1: Level 3 is supported. */
00615 } ble_gap_sec_levels_t;
00616 
00617 
00618 /**@brief Encryption Key. */
00619 typedef struct
00620 {
00621   ble_gap_enc_info_t    enc_info;             /**< Encryption Information. */
00622   ble_gap_master_id_t   master_id;            /**< Master Identification. */
00623 } ble_gap_enc_key_t;
00624 
00625 
00626 /**@brief Identity Key. */
00627 typedef struct
00628 {
00629   ble_gap_irk_t         id_info;              /**< Identity Information. */
00630   ble_gap_addr_t        id_addr_info;         /**< Identity Address Information. */
00631 } ble_gap_id_key_t;
00632 
00633 
00634 /**@brief Security Keys. */
00635 typedef struct
00636 {
00637   ble_gap_enc_key_t     *p_enc_key;           /**< Encryption Key, or NULL. */
00638   ble_gap_id_key_t      *p_id_key;            /**< Identity Key, or NULL. */
00639   ble_gap_sign_info_t   *p_sign_key;          /**< Signing Key, or NULL. */
00640 } ble_gap_sec_keys_t;
00641 
00642 
00643 /**@brief Security key set (both Peripheral and Central keys).
00644  *         Note that when distributing Bluetooth addresses pertaining to the local device those
00645  *         will have to be filled in by the user. */
00646 typedef struct
00647 {
00648   ble_gap_sec_keys_t keys_periph;     /**< Keys distributed by the device in the Peripheral role. */
00649   ble_gap_sec_keys_t keys_central;    /**< Keys distributed by the device in the Central role. */
00650 } ble_gap_sec_keyset_t;
00651 
00652 
00653 /**@brief Event structure for @ref BLE_GAP_EVT_AUTH_STATUS. */
00654 typedef struct
00655 {
00656   uint8_t               auth_status;            /**< Authentication status, see @ref BLE_GAP_SEC_STATUS. */
00657   uint8_t               error_src : 2;          /**< On error, source that caused the failure, see @ref BLE_GAP_SEC_STATUS_SOURCES. */
00658   uint8_t               bonded : 1;             /**< Procedure resulted in a bond. */
00659   ble_gap_sec_levels_t  sm1_levels;             /**< Levels supported in Security Mode 1. */
00660   ble_gap_sec_levels_t  sm2_levels;             /**< Levels supported in Security Mode 2. */
00661   ble_gap_sec_kdist_t   kdist_periph;           /**< Bitmap stating which keys were exchanged (distributed) by the peripheral. */
00662   ble_gap_sec_kdist_t   kdist_central;          /**< Bitmap stating which keys were exchanged (distributed) by the central. */
00663 } ble_gap_evt_auth_status_t;
00664 
00665 
00666 /**@brief Event structure for @ref BLE_GAP_EVT_CONN_SEC_UPDATE. */
00667 typedef struct
00668 {
00669   ble_gap_conn_sec_t conn_sec;                  /**< Connection security level. */
00670 } ble_gap_evt_conn_sec_update_t;
00671 
00672 
00673 /**@brief Event structure for @ref BLE_GAP_EVT_TIMEOUT. */
00674 typedef struct
00675 {
00676   uint8_t src;                                  /**< Source of timeout event, see @ref BLE_GAP_TIMEOUT_SOURCES. */
00677 } ble_gap_evt_timeout_t;
00678 
00679 
00680 /**@brief Event structure for @ref BLE_GAP_EVT_RSSI_CHANGED. */
00681 typedef struct
00682 {
00683   int8_t  rssi;                               /**< Received Signal Strength Indication in dBm. */
00684 } ble_gap_evt_rssi_changed_t;
00685 
00686 
00687 /**@brief Event structure for @ref BLE_GAP_EVT_ADV_REPORT. */
00688 typedef struct
00689 {
00690   ble_gap_addr_t peer_addr;                     /**< Bluetooth address of the peer device. */
00691   int8_t         rssi;                          /**< Received Signal Strength Indication in dBm. */
00692   uint8_t        scan_rsp : 1;                  /**< If 1, the report corresponds to a scan response and the type field may be ignored. */
00693   uint8_t        type     : 2;                  /**< See @ref BLE_GAP_ADV_TYPES. Only valid if the scan_rsp field is 0. */
00694   uint8_t        dlen     : 5;                  /**< Advertising or scan response data length. */
00695   uint8_t        data[BLE_GAP_ADV_MAX_SIZE];    /**< Advertising or scan response data. */
00696 } ble_gap_evt_adv_report_t;
00697 
00698 
00699 /**@brief Event structure for @ref BLE_GAP_EVT_SEC_REQUEST. */
00700 typedef struct
00701 {
00702   uint8_t    bond    : 1;                       /**< Perform bonding. */
00703   uint8_t    mitm    : 1;                       /**< Man In The Middle protection required. */
00704 } ble_gap_evt_sec_request_t;
00705 
00706 
00707 /**@brief Event structure for @ref BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST. */
00708 typedef struct
00709 {
00710   ble_gap_conn_params_t conn_params;            /**<  GAP Connection Parameters. */
00711 } ble_gap_evt_conn_param_update_request_t;
00712 
00713 
00714 /**@brief Event structure for @ref BLE_GAP_EVT_SCAN_REQ_REPORT. */
00715 typedef struct
00716 {
00717   int8_t                  rssi;              /**< Received Signal Strength Indication in dBm. */
00718   ble_gap_addr_t          peer_addr;         /**< Bluetooth address of the peer device. */
00719 } ble_gap_evt_scan_req_report_t;
00720 
00721 
00722 
00723 /**@brief GAP event structure. */
00724 typedef struct
00725 {
00726   uint16_t conn_handle;                                     /**< Connection Handle on which event occured. */
00727   union                                                     /**< union alternative identified by evt_id in enclosing struct. */
00728   {
00729     ble_gap_evt_connected_t                   connected;                    /**< Connected Event Parameters. */
00730     ble_gap_evt_disconnected_t                disconnected;                 /**< Disconnected Event Parameters. */
00731     ble_gap_evt_conn_param_update_t           conn_param_update;            /**< Connection Parameter Update Parameters. */
00732     ble_gap_evt_sec_params_request_t          sec_params_request;           /**< Security Parameters Request Event Parameters. */
00733     ble_gap_evt_sec_info_request_t            sec_info_request;             /**< Security Information Request Event Parameters. */
00734     ble_gap_evt_passkey_display_t             passkey_display;              /**< Passkey Display Event Parameters. */
00735     ble_gap_evt_auth_key_request_t            auth_key_request;             /**< Authentication Key Request Event Parameters. */
00736     ble_gap_evt_auth_status_t                 auth_status;                  /**< Authentication Status Event Parameters. */
00737     ble_gap_evt_conn_sec_update_t             conn_sec_update;              /**< Connection Security Update Event Parameters. */
00738     ble_gap_evt_timeout_t                     timeout;                      /**< Timeout Event Parameters. */
00739     ble_gap_evt_rssi_changed_t                rssi_changed;                 /**< RSSI Event parameters. */
00740     ble_gap_evt_adv_report_t                  adv_report;                   /**< Advertising Report Event Parameters. */
00741     ble_gap_evt_sec_request_t                 sec_request;                  /**< Security Request Event Parameters. */
00742     ble_gap_evt_conn_param_update_request_t   conn_param_update_request;    /**< Connection Parameter Update Parameters. */
00743     ble_gap_evt_scan_req_report_t             scan_req_report;              /**< Scan Request Report parameters. */
00744   } params;                                                                 /**< Event Parameters. */
00745 
00746 } ble_gap_evt_t;
00747 
00748 
00749 /**@brief Channel Map option.
00750  *        Used with @ref sd_ble_opt_get to get the current channel map
00751  *        or @ref sd_ble_opt_set to set a new channel map. When setting the
00752  *        channel map, it applies to all current and future connections. When getting the
00753  *        current channel map, it applies to a single connection and the connection handle
00754  *        must be supplied.
00755  *
00756  * @note  Setting the channel map may take some time, depending on connection parameters.
00757  *        The time taken may be different for each connection and the get operation will
00758  *        return the previous channel map until the new one has taken effect.
00759  *
00760  * @note  After setting the channel map, by spec it can not be set again until at least 1 s has passed.
00761  *        See Bluetooth Specification Version 4.1 Volume 2, Part E, Section 7.3.46.
00762  *
00763  * @retval ::NRF_SUCCESS Get or set successful.
00764  * @retval ::NRF_ERROR_BUSY Channel map was set again before enough time had passed.
00765  * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
00766  * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied for get.
00767  * @retval ::NRF_ERROR_NOT_SUPPORTED Returned by sd_ble_opt_set in peripheral-only SoftDevices.
00768  *
00769  */
00770 typedef struct
00771 {
00772   uint16_t conn_handle;                   /**< Connection Handle (only applicable for get) */
00773   uint8_t ch_map[5];                      /**< Channel Map (37-bit). */
00774 } ble_gap_opt_ch_map_t;
00775 
00776 
00777 /**@brief Local connection latency option.
00778  *
00779  *        Local connection latency is a feature which enables the slave to improve
00780  *        current consumption by ignoring the slave latency set by the peer. The
00781  *        local connection latency can only be set to a multiple of the slave latency,
00782  *        and cannot be longer than half of the supervision timeout.
00783  *
00784  *        Used with @ref sd_ble_opt_set to set the local connection latency. The
00785  *        @ref sd_ble_opt_get is not supported for this option, but the actual
00786  *        local connection latency (unless set to NULL) is set as a return parameter
00787  *        when setting the option.
00788  *
00789  * @note  The latency set will be truncated down to the closest slave latency event
00790  *        multiple, or the nearest multiple before half of the supervision timeout.
00791  *
00792  * @note  The local connection latency is disabled by default, and needs to be enabled for new
00793  *        connections and whenever the connection is updated.
00794  *
00795  * @retval ::NRF_SUCCESS Set successfully.
00796  * @retval ::NRF_ERROR_NOT_SUPPORTED Get is not supported.
00797  * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle parameter.
00798  */
00799 typedef struct
00800 {
00801   uint16_t   conn_handle;                       /**< Connection Handle */
00802   uint16_t   requested_latency;                 /**< Requested local connection latency. */
00803   uint16_t * p_actual_latency;                  /**< Pointer to storage for the actual local connection latency (can be set to NULL to skip return value). */
00804 } ble_gap_opt_local_conn_latency_t;
00805 
00806 
00807 /**@brief Passkey Option.
00808  *
00809  *        Structure containing the passkey to be used during pairing. This can be used with @ref
00810  *        sd_ble_opt_set to make the SoftDevice use a pre-programmed passkey for authentication
00811  *        instead of generating a random one.
00812  *
00813  * @note  @ref sd_ble_opt_get is not supported for this option.
00814  *
00815  */
00816 typedef struct
00817 {
00818   uint8_t * p_passkey;                          /**< Pointer to 6-digit ASCII string (digit 0..9 only, no NULL termination) passkey to be used during pairing. If this is NULL, the SoftDevice will generate a random passkey if required.*/
00819 } ble_gap_opt_passkey_t;
00820 
00821 
00822 /**@brief Custom Privacy Option.
00823  *
00824  *        This structure is used with both @ref sd_ble_opt_set (as input) and with
00825  *        @ref sd_ble_opt_get (as output).
00826  *
00827  *        Structure containing:
00828  *        - A pointer to an IRK to set (if input), or a place to store a read IRK (if output).
00829  *        - A private address refresh cycle.
00830  *
00831  * @note  The specified address cycle interval is used when the address cycle mode is
00832  *        @ref BLE_GAP_ADDR_CYCLE_MODE_AUTO. If 0 is given, the address will not be automatically 
00833  *        refreshed at all. The default interval is @ref BLE_GAP_DEFAULT_PRIVATE_ADDR_CYCLE_INTERVAL_S.
00834  *
00835  * @note  If the current address cycle mode is @ref BLE_GAP_ADDR_CYCLE_MODE_AUTO, the address will immediately be
00836  *        refreshed when a custom privacy option is set. A new address can be generated manually by calling
00837  *        @ref sd_ble_gap_address_set with the same type again. 
00838  *
00839  * @note  If the IRK is updated, the new IRK becomes the one to be distributed in all
00840  *        bonding procedures performed after @ref sd_ble_opt_set returns.
00841  *
00842  * @retval ::NRF_SUCCESS Set or read successfully.
00843  * @retval ::NRF_ERROR_INVALID_ADDR The pointer to IRK storage is invalid.
00844  */
00845 typedef struct
00846 {
00847   ble_gap_irk_t * p_irk;        /**< When input: Pointer to custom IRK, or NULL to use/reset to the device's default IRK. When output: Pointer to where the current IRK is to be stored, or NULL to not read out the IRK. */
00848   uint16_t        interval_s;   /**< When input: Custom private address cycle interval in seconds. When output: The current private address cycle interval. */
00849 } ble_gap_opt_privacy_t;
00850 
00851 
00852 /**@brief Scan request report option.
00853  *
00854  *        This can be used with @ref sd_ble_opt_set to make the SoftDevice send
00855  *        @ref BLE_GAP_EVT_SCAN_REQ_REPORT events.
00856  *
00857  *  @note   Due to the limited space reserved for scan request report events,
00858  *          not all received scan requests will be reported.
00859  *
00860  *  @note   If whitelisting is used, only whitelisted requests are reported.
00861  *
00862  *  @retval ::NRF_SUCCESS Set successfully.
00863  *  @retval ::NRF_ERROR_INVALID_STATE When advertising is ongoing while the option is set.
00864  */
00865 typedef struct
00866 {
00867    uint8_t enable : 1;                           /**< Enable scan request reports. */
00868 } ble_gap_opt_scan_req_report_t;
00869 
00870 /**@brief Compatibility mode option.
00871  *
00872  *        This can be used with @ref sd_ble_opt_set to enable and disable
00873  *        compatibility modes. Compatibility modes are disabled by default.
00874  *
00875  *  @note  Compatibility mode 1 enables interoperability with devices that do not support 
00876  *         a value of 0 for the WinOffset parameter in the Link Layer CONNECT_REQ packet.
00877  *
00878  *  @retval ::NRF_SUCCESS Set successfully.
00879  *  @retval ::NRF_ERROR_INVALID_STATE When connection creation is ongoing while mode 1 is set.
00880  */
00881 typedef struct
00882 {
00883    uint8_t mode_1_enable : 1;                           /**< Enable compatibility mode 1.*/
00884 } ble_gap_opt_compat_mode_t;
00885 
00886 
00887 /**@brief Option structure for GAP options. */
00888 typedef union
00889 {
00890   ble_gap_opt_ch_map_t                  ch_map;                    /**< Parameters for the Channel Map option. */
00891   ble_gap_opt_local_conn_latency_t      local_conn_latency;        /**< Parameters for the Local connection latency option */
00892   ble_gap_opt_passkey_t                 passkey;                   /**< Parameters for the Passkey option.*/
00893   ble_gap_opt_privacy_t                 privacy;                   /**< Parameters for the Custom privacy option. */
00894   ble_gap_opt_scan_req_report_t         scan_req_report;           /**< Parameters for the scan request report option.*/
00895   ble_gap_opt_compat_mode_t             compat_mode;               /**< Parameters for the compatibility mode option.*/
00896 } ble_gap_opt_t;
00897 /**@} */
00898 
00899 
00900 /**@addtogroup BLE_GAP_FUNCTIONS Functions
00901  * @{ */
00902 
00903 /**@brief Set local Bluetooth address.
00904  *
00905  * @note If the address cycle mode is @ref BLE_GAP_ADDR_CYCLE_MODE_AUTO, the address type is required to
00906  * be @ref BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE or
00907  * @ref BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE. The given address is ignored and the
00908  * SoftDevice will generate a new private address automatically every 
00909  * @ref BLE_GAP_DEFAULT_PRIVATE_ADDR_CYCLE_INTERVAL_S seconds. If this API
00910  * call is used again with the same parameters, the SoftDevice will immediately
00911  * generate a new private address to replace the current address.
00912  *
00913  * @note If the application wishes to use a @ref BLE_GAP_ADDR_TYPE_PUBLIC or
00914  * @ref BLE_GAP_ADDR_TYPE_RANDOM_STATIC address, the cycle mode must be
00915  * @ref BLE_GAP_ADDR_CYCLE_MODE_NONE.
00916  *
00917  * @note If this API function is called while advertising or scanning, the softdevice will immediately update the
00918  * advertising or scanning address without the need to stop the procedure in the following cases:
00919  *   - If the previously set address is of type @ref BLE_GAP_ADDR_TYPE_PUBLIC and the new address
00920  *   is also of type @ref BLE_GAP_ADDR_TYPE_PUBLIC
00921  *   - If the previously set address is not @ref BLE_GAP_ADDR_TYPE_PUBLIC and the new address is
00922  *   also not @ref BLE_GAP_ADDR_TYPE_PUBLIC.
00923  * If the address is changed from a @ref BLE_GAP_ADDR_TYPE_PUBLIC address to another type or from
00924  * another type to a @ref BLE_GAP_ADDR_TYPE_PUBLIC address, the change will take effect the next
00925  * time an advertising or scanning procedure is started.
00926  *
00927  * @note If the address cycle mode is @ref BLE_GAP_ADDR_CYCLE_MODE_NONE and the application is
00928  *       using privacy, the application must take care to generate and set new private addresses
00929  *       periodically to comply with the Privacy specification in Bluetooth Core Spec.
00930  *
00931  * @param[in] addr_cycle_mode Address cycle mode, see @ref BLE_GAP_ADDR_CYCLE_MODES.
00932  * @param[in] p_addr          Pointer to address structure.
00933  *
00934  * @retval ::NRF_SUCCESS Address successfully set.
00935  * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
00936  * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameters.
00937  * @retval ::BLE_ERROR_GAP_INVALID_BLE_ADDR Invalid address.
00938  * @retval ::NRF_ERROR_BUSY The stack is busy, process pending events and retry.
00939  * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
00940  */
00941 SVCALL(SD_BLE_GAP_ADDRESS_SET, uint32_t, sd_ble_gap_address_set(uint8_t addr_cycle_mode, const ble_gap_addr_t *p_addr));
00942 
00943 
00944 /**@brief Get local Bluetooth address.
00945  *
00946  * @param[out] p_addr Pointer to address structure to be filled in.
00947  *
00948  * @retval ::NRF_SUCCESS Address successfully retrieved.
00949  * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
00950  */
00951 SVCALL(SD_BLE_GAP_ADDRESS_GET, uint32_t, sd_ble_gap_address_get(ble_gap_addr_t *p_addr));
00952 
00953 
00954 /**@brief Set, clear or update advertising and scan response data.
00955  *
00956  * @note The format of the advertising data will be checked by this call to ensure interoperability.
00957  *       Limitations imposed by this API call to the data provided include having a flags data type in the scan response data and
00958  *       duplicating the local name in the advertising data and scan response data. 
00959  *
00960  * @note To clear the advertising data and set it to a 0-length packet, simply provide a valid pointer (p_data/p_sr_data) with its corresponding 
00961  *        length (dlen/srdlen) set to 0.
00962  *
00963  * @note The call will fail if p_data and p_sr_data are both NULL since this would have no effect.
00964  *
00965  * @param[in] p_data    Raw data to be placed in advertising packet. If NULL, no changes are made to the current advertising packet data.
00966  * @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.
00967  * @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.
00968  * @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.
00969  *
00970  * @retval ::NRF_SUCCESS Advertising data successfully updated or cleared.
00971  * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
00972  * @retval ::NRF_ERROR_INVALID_FLAGS Invalid combination of advertising flags supplied.
00973  * @retval ::NRF_ERROR_INVALID_DATA Invalid data type(s) supplied, check the advertising data format specification.
00974  * @retval ::NRF_ERROR_INVALID_LENGTH Invalid data length(s) supplied.
00975  * @retval ::NRF_ERROR_NOT_SUPPORTED Unsupported data type.
00976  * @retval ::BLE_ERROR_GAP_UUID_LIST_MISMATCH Invalid UUID list supplied.
00977  */
00978 SVCALL(SD_BLE_GAP_ADV_DATA_SET, uint32_t, sd_ble_gap_adv_data_set(uint8_t const *p_data, uint8_t dlen, uint8_t const *p_sr_data, uint8_t srdlen));
00979 
00980 
00981 /**@brief Start advertising (GAP Discoverable, Connectable modes, Broadcast Procedure).
00982  *
00983  * @note An application can start an advertising procedure for broadcasting purposes while a connection
00984  *       is active. After a @ref BLE_GAP_EVT_CONNECTED event is received, this function may therefore
00985  *       be called to start a broadcast advertising procedure. The advertising procedure
00986  *       cannot however be connectable (it must be of type @ref BLE_GAP_ADV_TYPE_ADV_SCAN_IND or
00987  *       @ref BLE_GAP_ADV_TYPE_ADV_NONCONN_IND). @note Only one advertiser may be active at any time.
00988  *
00989  * @note To use the currently active whitelist set p_adv_params->p_whitelist to NULL.
00990  *
00991  * @param[in] p_adv_params Pointer to advertising parameters structure.
00992  *
00993  * @retval ::NRF_SUCCESS The BLE stack has started advertising.
00994  * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
00995  * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
00996  * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, check the accepted ranges and limits.
00997  * @retval ::BLE_ERROR_GAP_INVALID_BLE_ADDR Invalid Bluetooth address supplied.
00998  * @retval ::BLE_ERROR_GAP_DISCOVERABLE_WITH_WHITELIST Discoverable mode and whitelist incompatible.
00999  * @retval ::NRF_ERROR_BUSY The stack is busy, process pending events and retry.
01000  * @retval ::BLE_ERROR_GAP_WHITELIST_IN_USE Unable to replace the whitelist while another operation is using it.
01001  */
01002 SVCALL(SD_BLE_GAP_ADV_START, uint32_t, sd_ble_gap_adv_start(ble_gap_adv_params_t const *p_adv_params));
01003 
01004 
01005 /**@brief Stop advertising (GAP Discoverable, Connectable modes, Broadcast Procedure).
01006  *
01007  * @retval ::NRF_SUCCESS The BLE stack has stopped advertising.
01008  * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation (most probably not in advertising state).
01009  */
01010 SVCALL(SD_BLE_GAP_ADV_STOP, uint32_t, sd_ble_gap_adv_stop(void));
01011 
01012 
01013 /**@brief Update connection parameters.
01014  *
01015  * @details In the central role this will initiate a Link Layer connection parameter update procedure,
01016  *          otherwise in the peripheral role, this will send the corresponding L2CAP request and wait for
01017  *          the central to perform the procedure. In both cases, and regardless of success or failure, the application
01018  *          will be informed of the result with a @ref BLE_GAP_EVT_CONN_PARAM_UPDATE event.
01019  *
01020  * @details This function can be used as a central both to reply to a @ref BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST or to start the procedure unrequested.
01021  *
01022  * @param[in] conn_handle Connection handle.
01023  * @param[in] p_conn_params  Pointer to desired connection parameters. If NULL is provided on a peripheral role,
01024  *                           the parameters in the PPCP characteristic of the GAP service will be used instead.
01025  *                           If NULL is provided on a central role and in response to a @ref BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST, the peripheral request will be rejected
01026  *
01027  * @retval ::NRF_SUCCESS The Connection Update procedure has been started successfully.
01028  * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
01029  * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, check parameter limits and constraints.
01030  * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
01031  * @retval ::NRF_ERROR_BUSY Procedure already in progress or not allowed at this time, process pending events and wait for pending procedures to complete and retry.
01032  * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
01033  * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation.
01034  */
01035 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 *p_conn_params));
01036 
01037 
01038 /**@brief Disconnect (GAP Link Termination).
01039  *
01040  * @details This call initiates the disconnection procedure, and its completion will be communicated to the application
01041  *          with a @ref BLE_GAP_EVT_DISCONNECTED event.
01042  *
01043  * @param[in] conn_handle Connection handle.
01044  * @param[in] hci_status_code HCI status code, see @ref BLE_HCI_STATUS_CODES (accepted values are @ref BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION and @ref BLE_HCI_CONN_INTERVAL_UNACCEPTABLE).
01045  *
01046  * @retval ::NRF_SUCCESS The disconnection procedure has been started successfully.
01047  * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
01048  * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
01049  * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation (disconnection is already in progress).
01050  */
01051 SVCALL(SD_BLE_GAP_DISCONNECT, uint32_t, sd_ble_gap_disconnect(uint16_t conn_handle, uint8_t hci_status_code));
01052 
01053 
01054 /**@brief Set the radio's transmit power.
01055  *
01056  * @param[in] tx_power Radio transmit power in dBm (accepted values are -40, -30, -20, -16, -12, -8, -4, 0, and 4 dBm).
01057  *
01058  * @note -40 dBm will not actually give -40 dBm, but will instead be remapped to -30 dBm.
01059  *
01060  * @retval ::NRF_SUCCESS Successfully changed the transmit power.
01061  * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
01062  */
01063 SVCALL(SD_BLE_GAP_TX_POWER_SET, uint32_t, sd_ble_gap_tx_power_set(int8_t tx_power));
01064 
01065 
01066 /**@brief Set GAP Appearance value.
01067  *
01068  * @param[in] appearance Appearance (16-bit), see @ref BLE_APPEARANCES.
01069  *
01070  * @retval ::NRF_SUCCESS  Appearance value set successfully.
01071  * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
01072  */
01073 SVCALL(SD_BLE_GAP_APPEARANCE_SET, uint32_t, sd_ble_gap_appearance_set(uint16_t appearance));
01074 
01075 
01076 /**@brief Get GAP Appearance value.
01077  *
01078  * @param[out] p_appearance Pointer to appearance (16-bit) to be filled in, see @ref BLE_APPEARANCES.
01079  *
01080  * @retval ::NRF_SUCCESS Appearance value retrieved successfully.
01081  * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
01082  */
01083 SVCALL(SD_BLE_GAP_APPEARANCE_GET, uint32_t, sd_ble_gap_appearance_get(uint16_t *p_appearance));
01084 
01085 
01086 /**@brief Set GAP Peripheral Preferred Connection Parameters.
01087  *
01088  * @param[in] p_conn_params Pointer to a @ref ble_gap_conn_params_t structure with the desired parameters.
01089  *
01090  * @retval ::NRF_SUCCESS Peripheral Preferred Connection Parameters set successfully.
01091  * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
01092  * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
01093  */
01094 SVCALL(SD_BLE_GAP_PPCP_SET, uint32_t, sd_ble_gap_ppcp_set(ble_gap_conn_params_t const *p_conn_params));
01095 
01096 
01097 /**@brief Get GAP Peripheral Preferred Connection Parameters.
01098  *
01099  * @param[out] p_conn_params Pointer to a @ref ble_gap_conn_params_t structure where the parameters will be stored.
01100  *
01101  * @retval ::NRF_SUCCESS Peripheral Preferred Connection Parameters retrieved successfully.
01102  * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
01103  */
01104 SVCALL(SD_BLE_GAP_PPCP_GET, uint32_t, sd_ble_gap_ppcp_get(ble_gap_conn_params_t *p_conn_params));
01105 
01106 
01107 /**@brief Set GAP device name.
01108  *
01109  * @param[in] p_write_perm Write permissions for the Device Name characteristic, see @ref ble_gap_conn_sec_mode_t.
01110  * @param[in] p_dev_name Pointer to a UTF-8 encoded, <b>non NULL-terminated</b> string.
01111  * @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).
01112  *
01113  * @retval ::NRF_SUCCESS GAP device name and permissions set successfully.
01114  * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
01115  * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
01116  * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
01117  */
01118 SVCALL(SD_BLE_GAP_DEVICE_NAME_SET, uint32_t, sd_ble_gap_device_name_set(ble_gap_conn_sec_mode_t const *p_write_perm, uint8_t const *p_dev_name, uint16_t len));
01119 
01120 
01121 /**@brief Get GAP device name.
01122  *
01123  * @param[out]    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.
01124  * @param[in,out] p_len      Length of the buffer pointed by p_dev_name, complete device name length on output.
01125  *
01126  * @note          If the device name is longer than the size of the supplied buffer,
01127  *                p_len will return the complete device name length,
01128  *                and not the number of bytes actually returned in p_dev_name.
01129  *                The application may use this information to allocate a suitable buffer size.
01130  *
01131  * @retval ::NRF_SUCCESS GAP device name retrieved successfully.
01132  * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
01133  * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
01134  */
01135 SVCALL(SD_BLE_GAP_DEVICE_NAME_GET, uint32_t, sd_ble_gap_device_name_get(uint8_t *p_dev_name, uint16_t *p_len));
01136 
01137 
01138 /**@brief Initiate the GAP Authentication procedure.
01139  *
01140  * @param[in] conn_handle Connection handle.
01141  * @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 or bonding procedure.
01142  *                         In the peripheral role, only the timeout, bond and mitm fields of this structure are used.
01143  *                         In the central role, this pointer may be NULL to reject a Security Request.
01144  *
01145  * @details In the central role, this function will send an SMP Pairing Request (or an SMP Pairing Failed if rejected), 
01146  *          otherwise in the peripheral role, an SMP Security Request will be sent.
01147  *
01148  * @note    Calling this function may result in the following events depending on the outcome and parameters: @ref BLE_GAP_EVT_SEC_PARAMS_REQUEST,
01149  *          @ref BLE_GAP_EVT_SEC_INFO_REQUEST, @ref BLE_GAP_EVT_AUTH_KEY_REQUEST, @ref BLE_GAP_EVT_CONN_SEC_UPDATE, @ref BLE_GAP_EVT_AUTH_STATUS.
01150  *
01151  *
01152  * @retval ::NRF_SUCCESS Successfully initiated authentication procedure.
01153  * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
01154  * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
01155  * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
01156  * @retval ::NRF_ERROR_BUSY The stack is busy, process pending events and retry.
01157  * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
01158  * @retval ::NRF_ERROR_TIMEOUT A SMP timout has occured, and further SMP operations on this link is prohibited.
01159  */
01160 SVCALL(SD_BLE_GAP_AUTHENTICATE, uint32_t, sd_ble_gap_authenticate(uint16_t conn_handle, ble_gap_sec_params_t const *p_sec_params));
01161 
01162 
01163 /**@brief Reply with GAP security parameters.
01164  *
01165  * @param[in] conn_handle Connection handle.
01166  * @param[in] sec_status Security status, see @ref BLE_GAP_SEC_STATUS.
01167  * @param[in] p_sec_params Pointer to a @ref ble_gap_sec_params_t security parameters structure. In the central role this must be set to NULL, as the parameters have
01168  *                         already been provided during a previous call to @ref sd_ble_gap_authenticate.
01169  * @param[in,out] p_sec_keyset Pointer to a @ref ble_gap_sec_keyset_t security keyset structure. Any keys distributed as a result of the ongoing security procedure 
01170  *                         will be stored into the memory referenced by the pointers inside this structure. The keys will be stored and available to the application 
01171  *                         upon reception of a @ref BLE_GAP_EVT_AUTH_STATUS event.
01172  *                         The pointer to the ID key data distributed by the <b>local device</b> constitutes however an exception. It can either point to ID key data 
01173  *                         filled in by the user before calling this function, in which case a user-supplied Bluetooth address and IRK will be distributed, 
01174  *                         or the pointer to the ID key data structure can be NULL, in which case the device's configured (or default, if none is configured) 
01175  *                         Bluetooth address and IRK will be distributed. 
01176  *
01177  * @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 @ref NRF_ERROR_INVALID_STATE.
01178  * @note    If the call returns an error code, the request is still pending, and the reply call may be repeated with corrected parameters.
01179  *
01180  * @retval ::NRF_SUCCESS Successfully accepted security parameter from the application.
01181  * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
01182  * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
01183  * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
01184  * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
01185  */
01186 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 *p_sec_params, ble_gap_sec_keyset_t const *p_sec_keyset));
01187 
01188 
01189 /**@brief Reply with an authentication key.
01190  *
01191  * @param[in] conn_handle Connection handle.
01192  * @param[in] key_type See @ref BLE_GAP_AUTH_KEY_TYPES.
01193  * @param[in] p_key If key type is @ref BLE_GAP_AUTH_KEY_TYPE_NONE, then NULL.
01194  *                If key type is @ref BLE_GAP_AUTH_KEY_TYPE_PASSKEY, then a 6-byte ASCII string (digit 0..9 only, no NULL termination).
01195  *                If key type is @ref BLE_GAP_AUTH_KEY_TYPE_OOB, then a 16-byte OOB key value in Little Endian format.
01196  *
01197  * @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 @ref NRF_ERROR_INVALID_STATE.
01198  * @note    If the call returns an error code, the request is still pending, and the reply call may be repeated with corrected parameters.
01199  *
01200  * @retval ::NRF_SUCCESS Authentication key successfully set.
01201  * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
01202  * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
01203  * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
01204  * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
01205  */
01206 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 *p_key));
01207 
01208 
01209 /**@brief Initiate GAP Encryption procedure.
01210  *
01211  * @param[in] conn_handle Connection handle.
01212  * @param[in] p_master_id Pointer to a @ref ble_gap_master_id_t master identification structure.
01213  * @param[in] p_enc_info  Pointer to a @ref ble_gap_enc_info_t encryption information structure.
01214  *
01215  * @details In the central role, this function will initiate the encryption procedure using the encryption information provided.
01216  *
01217  * @note    Calling this function may result in the following event depending on the outcome and parameters: @ref BLE_GAP_EVT_CONN_SEC_UPDATE.
01218  *
01219  * @retval ::NRF_SUCCESS Successfully initiated authentication procedure.
01220  * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
01221  * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
01222  * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
01223  * @retval ::BLE_ERROR_INVALID_ROLE Operation is not supported in the Peripheral role.
01224  * @retval ::NRF_ERROR_BUSY Procedure already in progress or not allowed at this time, wait for pending procedures to complete and retry.
01225  */
01226 SVCALL(SD_BLE_GAP_ENCRYPT, uint32_t, sd_ble_gap_encrypt(uint16_t conn_handle, ble_gap_master_id_t const *p_master_id, ble_gap_enc_info_t const *p_enc_info));
01227 
01228 
01229 /**@brief Reply with GAP security information.
01230  *
01231  * @param[in] conn_handle Connection handle.
01232  * @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.
01233  * @param[in] p_id_info Pointer to a @ref ble_gap_irk_t identity information structure. May be NULL to signal none is available.
01234  * @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.
01235  *
01236  * @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 @ref NRF_ERROR_INVALID_STATE.
01237  * @note    If the call returns an error code, the request is still pending, and the reply call may be repeated with corrected parameters.
01238  * @note    Data signing is not yet supported, and p_sign_info must therefore be NULL.
01239  *
01240  * @retval ::NRF_SUCCESS Successfully accepted security information.
01241  * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
01242  * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
01243  * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
01244  */
01245 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 *p_enc_info, ble_gap_irk_t const *p_id_info, ble_gap_sign_info_t const *p_sign_info));
01246 
01247 
01248 /**@brief Get the current connection security.
01249  *
01250  * @param[in]  conn_handle Connection handle.
01251  * @param[out] p_conn_sec  Pointer to a @ref ble_gap_conn_sec_t structure to be filled in.
01252  *
01253  * @retval ::NRF_SUCCESS Current connection security successfully retrieved.
01254  * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
01255  * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
01256  */
01257 SVCALL(SD_BLE_GAP_CONN_SEC_GET, uint32_t, sd_ble_gap_conn_sec_get(uint16_t conn_handle, ble_gap_conn_sec_t *p_conn_sec));
01258 
01259 
01260 /**@brief Start reporting the received signal strength to the application. 
01261  *
01262  * A new event is reported whenever the RSSI value changes, until @ref sd_ble_gap_rssi_stop is called.
01263  *
01264  * @param[in] conn_handle        Connection handle.
01265  * @param[in] threshold_dbm      Minimum change in dBm before triggering the @ref BLE_GAP_EVT_RSSI_CHANGED event. Events are disabled if threshold_dbm equals @ref BLE_GAP_RSSI_THRESHOLD_INVALID.
01266  * @param[in] skip_count         Number of RSSI samples with a change of threshold_dbm or more before sending a new @ref BLE_GAP_EVT_RSSI_CHANGED event.
01267  *
01268  * @retval ::NRF_SUCCESS                   Successfully activated RSSI reporting.
01269  * @retval ::NRF_ERROR_INVALID_STATE       Disconnection in progress. Invalid state to perform operation.
01270  * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
01271  */
01272 SVCALL(SD_BLE_GAP_RSSI_START, uint32_t, sd_ble_gap_rssi_start(uint16_t conn_handle, uint8_t threshold_dbm, uint8_t skip_count));
01273 
01274 
01275 /**@brief Stop reporting the received signal strength.
01276  *
01277  * @note An RSSI change detected before the call but not yet received by the application 
01278  * may be reported after @ref sd_ble_gap_rssi_stop has been called.
01279  *
01280  * @param[in] conn_handle Connection handle.
01281  *
01282  * @retval ::NRF_SUCCESS                   Successfully deactivated RSSI reporting.
01283  * @retval ::NRF_ERROR_INVALID_STATE       Invalid state to perform operation.
01284  * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
01285  */
01286 SVCALL(SD_BLE_GAP_RSSI_STOP, uint32_t, sd_ble_gap_rssi_stop(uint16_t conn_handle));
01287 
01288 
01289 /**@brief Get the received signal strength for the last connection event.
01290  *
01291  * @param[in]  conn_handle Connection handle.
01292  * @param[out] p_rssi      Pointer to the location where the RSSI measurement shall be stored.
01293  *
01294  * @ref sd_ble_gap_rssi_start must be called to start reporting RSSI before using this function. @ref NRF_ERROR_NOT_FOUND
01295  * will be returned until RSSI was sampled for the first time after calling @ref sd_ble_gap_rssi_start.
01296  *
01297  * @retval ::NRF_SUCCESS                   Successfully read the RSSI.
01298  * @retval ::NRF_ERROR_NOT_FOUND           No sample is available.
01299  * @retval ::NRF_ERROR_INVALID_ADDR        Invalid pointer supplied.
01300  * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
01301  * @retval ::NRF_ERROR_INVALID_STATE       RSSI reporting is not ongoing, or disconnection in progress.
01302  */
01303 SVCALL(SD_BLE_GAP_RSSI_GET, uint32_t, sd_ble_gap_rssi_get(uint16_t conn_handle, int8_t *p_rssi));
01304 
01305 
01306 /**@brief Start scanning (GAP Discovery procedure, Observer Procedure).
01307  *
01308  * @note To use the currently active whitelist set p_scan_params->p_whitelist to NULL.
01309  *
01310  * @param[in] p_scan_params Pointer to scan parameters structure.
01311  *
01312  * @retval ::NRF_SUCCESS Successfully initiated scanning procedure.
01313  * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
01314  * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
01315  * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
01316  * @retval ::NRF_ERROR_BUSY The stack is busy, process pending events and retry.
01317  * @retval ::BLE_ERROR_GAP_WHITELIST_IN_USE Unable to replace the whitelist while another operation is using it.
01318  */
01319 SVCALL(SD_BLE_GAP_SCAN_START, uint32_t, sd_ble_gap_scan_start(ble_gap_scan_params_t const *p_scan_params));
01320 
01321 
01322 /**@brief Stop scanning (GAP Discovery procedure, Observer Procedure).
01323  *
01324  * @retval ::NRF_SUCCESS Successfully stopped scanning procedure.
01325  * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation (most probably not in scanning state).
01326  */
01327 SVCALL(SD_BLE_GAP_SCAN_STOP, uint32_t, sd_ble_gap_scan_stop(void));
01328 
01329 
01330 /**@brief Create a connection (GAP Link Establishment).
01331  *
01332  * @note To use the currently active whitelist set p_scan_params->p_whitelist to NULL.    
01333  *
01334  * @param[in] p_peer_addr   Pointer to peer address. If the selective bit is set in @ref ble_gap_scan_params_t, then this must be NULL.
01335  * @param[in] p_scan_params Pointer to scan parameters structure.
01336  * @param[in] p_conn_params Pointer to desired connection parameters.
01337  *
01338  * @retval ::NRF_SUCCESS Successfully initiated connection procedure.
01339  * @retval ::NRF_ERROR_INVALID_ADDR Invalid parameter(s) pointer supplied.
01340  * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
01341  * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
01342  * @retval ::BLE_ERROR_GAP_INVALID_BLE_ADDR Invalid Peer address.
01343  * @retval ::NRF_ERROR_NO_MEM limit of available connections reached.
01344  * @retval ::NRF_ERROR_BUSY The stack is busy, process pending events and retry. If another connection is being established wait for the corresponding
01345  *                          @ref BLE_GAP_EVT_CONNECTED event before calling again.
01346  * @retval ::BLE_ERROR_GAP_WHITELIST_IN_USE Unable to replace the whitelist while another operation is using it.
01347  */
01348 SVCALL(SD_BLE_GAP_CONNECT, uint32_t, sd_ble_gap_connect(ble_gap_addr_t const *p_peer_addr, ble_gap_scan_params_t const *p_scan_params, ble_gap_conn_params_t const *p_conn_params));
01349 
01350 
01351 /**@brief Cancel a connection establishment.
01352  *
01353  * @retval ::NRF_SUCCESS Successfully cancelled an ongoing connection procedure.
01354  * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
01355  */
01356 SVCALL(SD_BLE_GAP_CONNECT_CANCEL, uint32_t, sd_ble_gap_connect_cancel(void));
01357 
01358 /** @} */
01359 
01360 #endif // BLE_GAP_H__
01361 
01362 /**
01363   @}
01364 */