fork

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