My fork of X_NUCLEO_IDB0XA1

Fork of X_NUCLEO_IDB0XA1 by ST

Committer:
Vincent Coubard
Date:
Thu Sep 15 16:59:44 2016 +0100
Revision:
306:3a7d9f923493
Parent:
302:ed6f74ab78f9
Merge sync_with_github into the default branch to makes the online IDE happy.

Sync with 7c82dbe71630c69410de24d80a5a854feaf53729

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wolfgang Betz 130:770ce14d3d15 1 /* mbed Microcontroller Library
Wolfgang Betz 130:770ce14d3d15 2 * Copyright (c) 2006-2013 ARM Limited
Wolfgang Betz 130:770ce14d3d15 3 *
Wolfgang Betz 130:770ce14d3d15 4 * Licensed under the Apache License, Version 2.0 (the "License");
Wolfgang Betz 130:770ce14d3d15 5 * you may not use this file except in compliance with the License.
Wolfgang Betz 130:770ce14d3d15 6 * You may obtain a copy of the License at
Wolfgang Betz 130:770ce14d3d15 7 *
Wolfgang Betz 130:770ce14d3d15 8 * http://www.apache.org/licenses/LICENSE-2.0
Wolfgang Betz 130:770ce14d3d15 9 *
Wolfgang Betz 130:770ce14d3d15 10 * Unless required by applicable law or agreed to in writing, software
Wolfgang Betz 130:770ce14d3d15 11 * distributed under the License is distributed on an "AS IS" BASIS,
Wolfgang Betz 130:770ce14d3d15 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Wolfgang Betz 130:770ce14d3d15 13 * See the License for the specific language governing permissions and
Wolfgang Betz 130:770ce14d3d15 14 * limitations under the License.
Wolfgang Betz 130:770ce14d3d15 15 */
Wolfgang Betz 130:770ce14d3d15 16
Wolfgang Betz 130:770ce14d3d15 17
Wolfgang Betz 130:770ce14d3d15 18 /**
Wolfgang Betz 130:770ce14d3d15 19 ******************************************************************************
Vincent Coubard 255:97adb68decd4 20 * @file BlueNRGGap.cpp
Wolfgang Betz 130:770ce14d3d15 21 * @author STMicroelectronics
Wolfgang Betz 130:770ce14d3d15 22 * @brief Implementation of BLE_API Gap Class
Wolfgang Betz 130:770ce14d3d15 23 ******************************************************************************
Wolfgang Betz 130:770ce14d3d15 24 * @copy
Wolfgang Betz 130:770ce14d3d15 25 *
Wolfgang Betz 130:770ce14d3d15 26 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
Wolfgang Betz 130:770ce14d3d15 27 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
Wolfgang Betz 130:770ce14d3d15 28 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
Wolfgang Betz 130:770ce14d3d15 29 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
Wolfgang Betz 130:770ce14d3d15 30 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
Wolfgang Betz 130:770ce14d3d15 31 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
Wolfgang Betz 130:770ce14d3d15 32 *
Wolfgang Betz 130:770ce14d3d15 33 * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
Andrea Palmieri 229:9981f62cdb1a 34 */
Wolfgang Betz 130:770ce14d3d15 35
Wolfgang Betz 130:770ce14d3d15 36 /** @defgroup BlueNRGGap
Wolfgang Betz 130:770ce14d3d15 37 * @brief BlueNRG BLE_API GAP Adaptation
Wolfgang Betz 130:770ce14d3d15 38 * @{
Wolfgang Betz 130:770ce14d3d15 39 */
Wolfgang Betz 130:770ce14d3d15 40
Wolfgang Betz 130:770ce14d3d15 41 #include "BlueNRGDevice.h"
Vincent Coubard 278:a5209d8cfd61 42 #ifdef YOTTA_CFG_MBED_OS
Vincent Coubard 278:a5209d8cfd61 43 #include "mbed-drivers/mbed.h"
Vincent Coubard 278:a5209d8cfd61 44 #else
Vincent Coubard 278:a5209d8cfd61 45 #include "mbed.h"
Vincent Coubard 302:ed6f74ab78f9 46 #endif
Vincent Coubard 293:5a1f577bf92f 47 #include "ble_payload.h"
Vincent Coubard 293:5a1f577bf92f 48 #include "ble_utils.h"
Vincent Coubard 293:5a1f577bf92f 49 #include "ble_debug.h"
Wolfgang Betz 130:770ce14d3d15 50
Wolfgang Betz 130:770ce14d3d15 51 /*
Wolfgang Betz 130:770ce14d3d15 52 * Utility to process GAP specific events (e.g., Advertising timeout)
Wolfgang Betz 130:770ce14d3d15 53 */
Wolfgang Betz 130:770ce14d3d15 54 void BlueNRGGap::Process(void)
Vincent Coubard 255:97adb68decd4 55 {
Wolfgang Betz 130:770ce14d3d15 56 if(AdvToFlag) {
Wolfgang Betz 130:770ce14d3d15 57 stopAdvertising();
Wolfgang Betz 130:770ce14d3d15 58 }
Wolfgang Betz 130:770ce14d3d15 59
Wolfgang Betz 130:770ce14d3d15 60 }
Wolfgang Betz 130:770ce14d3d15 61
Wolfgang Betz 130:770ce14d3d15 62 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 63 /*!
Vincent Coubard 255:97adb68decd4 64 @brief Sets the advertising parameters and payload for the device.
Wolfgang Betz 130:770ce14d3d15 65 Note: Some data types give error when their adv data is updated using aci_gap_update_adv_data() API
Wolfgang Betz 130:770ce14d3d15 66
Wolfgang Betz 130:770ce14d3d15 67 @params[in] advData
Wolfgang Betz 130:770ce14d3d15 68 The primary advertising data payload
Wolfgang Betz 130:770ce14d3d15 69 @params[in] scanResponse
Wolfgang Betz 130:770ce14d3d15 70 The optional Scan Response payload if the advertising
Wolfgang Betz 130:770ce14d3d15 71 type is set to \ref GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED
Wolfgang Betz 130:770ce14d3d15 72 in \ref GapAdveritinngParams
Wolfgang Betz 130:770ce14d3d15 73
Wolfgang Betz 130:770ce14d3d15 74 @returns \ref ble_error_t
Wolfgang Betz 130:770ce14d3d15 75
Wolfgang Betz 130:770ce14d3d15 76 @retval BLE_ERROR_NONE
Wolfgang Betz 130:770ce14d3d15 77 Everything executed properly
Wolfgang Betz 130:770ce14d3d15 78
Wolfgang Betz 130:770ce14d3d15 79 @retval BLE_ERROR_BUFFER_OVERFLOW
Wolfgang Betz 130:770ce14d3d15 80 The proposed action would cause a buffer overflow. All
Wolfgang Betz 130:770ce14d3d15 81 advertising payloads must be <= 31 bytes, for example.
Wolfgang Betz 130:770ce14d3d15 82
Wolfgang Betz 130:770ce14d3d15 83 @retval BLE_ERROR_NOT_IMPLEMENTED
Wolfgang Betz 130:770ce14d3d15 84 A feature was requested that is not yet supported in the
Wolfgang Betz 130:770ce14d3d15 85 nRF51 firmware or hardware.
Wolfgang Betz 130:770ce14d3d15 86
Wolfgang Betz 130:770ce14d3d15 87 @retval BLE_ERROR_PARAM_OUT_OF_RANGE
Wolfgang Betz 130:770ce14d3d15 88 One of the proposed values is outside the valid range.
Wolfgang Betz 130:770ce14d3d15 89
Wolfgang Betz 130:770ce14d3d15 90 @section EXAMPLE
Wolfgang Betz 130:770ce14d3d15 91
Wolfgang Betz 130:770ce14d3d15 92 @code
Wolfgang Betz 130:770ce14d3d15 93
Wolfgang Betz 130:770ce14d3d15 94 @endcode
Wolfgang Betz 130:770ce14d3d15 95 */
Wolfgang Betz 130:770ce14d3d15 96 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 97 ble_error_t BlueNRGGap::setAdvertisingData(const GapAdvertisingData &advData, const GapAdvertisingData &scanResponse)
Vincent Coubard 255:97adb68decd4 98 {
Wolfgang Betz 132:51056160fa4a 99 PRINTF("BlueNRGGap::setAdvertisingData\n\r");
Wolfgang Betz 130:770ce14d3d15 100 /* Make sure we don't exceed the advertising payload length */
Wolfgang Betz 130:770ce14d3d15 101 if (advData.getPayloadLen() > GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
Andrea Palmieri 237:64c2ddbd9329 102 PRINTF("Exceeded the advertising payload length\n\r");
Wolfgang Betz 130:770ce14d3d15 103 return BLE_ERROR_BUFFER_OVERFLOW;
Wolfgang Betz 130:770ce14d3d15 104 }
Vincent Coubard 254:f4d217cadbde 105
Wolfgang Betz 130:770ce14d3d15 106 /* Make sure we have a payload! */
Vincent Coubard 270:ca649990a830 107 if (advData.getPayloadLen() != 0) {
Andrea Palmieri 236:2a73f3a97452 108 PayloadPtr loadPtr(advData.getPayload(), advData.getPayloadLen());
Andrea Palmieri 236:2a73f3a97452 109
Vincent Coubard 253:9665a6f8bbdb 110 /* Align the GAP Service Appearance Char value coherently
Vincent Coubard 253:9665a6f8bbdb 111 This setting is duplicate (see below GapAdvertisingData::APPEARANCE)
Vincent Coubard 253:9665a6f8bbdb 112 since BLE API has an overloaded function for appearance
Vincent Coubard 253:9665a6f8bbdb 113 */
Vincent Coubard 253:9665a6f8bbdb 114 STORE_LE_16(deviceAppearance, advData.getAppearance());
Vincent Coubard 253:9665a6f8bbdb 115 setAppearance((GapAdvertisingData::Appearance)(deviceAppearance[1]<<8|deviceAppearance[0]));
Vincent Coubard 254:f4d217cadbde 116
Vincent Coubard 254:f4d217cadbde 117
Vincent Coubard 255:97adb68decd4 118 for(uint8_t index=0; index<loadPtr.getPayloadUnitCount(); index++) {
Wolfgang Betz 130:770ce14d3d15 119 loadPtr.getUnitAtIndex(index);
Wolfgang Betz 130:770ce14d3d15 120
Wolfgang Betz 132:51056160fa4a 121 PRINTF("adData[%d].length=%d\n\r", index,(uint8_t)(*loadPtr.getUnitAtIndex(index).getLenPtr()));
Vincent Coubard 255:97adb68decd4 122 PRINTF("adData[%d].AdType=0x%x\n\r", index,(uint8_t)(*loadPtr.getUnitAtIndex(index).getAdTypePtr()));
Vincent Coubard 255:97adb68decd4 123
Wolfgang Betz 130:770ce14d3d15 124 switch(*loadPtr.getUnitAtIndex(index).getAdTypePtr()) {
Vincent Coubard 270:ca649990a830 125 /**< TX Power Level (in dBm) */
Vincent Coubard 270:ca649990a830 126 case GapAdvertisingData::TX_POWER_LEVEL:
Wolfgang Betz 130:770ce14d3d15 127 {
Vincent Coubard 255:97adb68decd4 128 PRINTF("Advertising type: TX_POWER_LEVEL\n\r");
Wolfgang Betz 130:770ce14d3d15 129 int8_t enHighPower = 0;
Wolfgang Betz 130:770ce14d3d15 130 int8_t paLevel = 0;
Andrea Palmieri 251:86df2c289e7c 131
Wolfgang Betz 130:770ce14d3d15 132 int8_t dbm = *loadPtr.getUnitAtIndex(index).getDataPtr();
Andrea Palmieri 251:86df2c289e7c 133 tBleStatus ret = getHighPowerAndPALevelValue(dbm, enHighPower, paLevel);
Andrea Palmieri 251:86df2c289e7c 134 #ifdef DEBUG
Andrea Palmieri 251:86df2c289e7c 135 PRINTF("dbm=%d, ret=%d\n\r", dbm, ret);
Andrea Palmieri 251:86df2c289e7c 136 PRINTF("enHighPower=%d, paLevel=%d\n\r", enHighPower, paLevel);
Wolfgang Betz 130:770ce14d3d15 137 #endif
Andrea Palmieri 251:86df2c289e7c 138 if(ret == BLE_STATUS_SUCCESS) {
Andrea Palmieri 251:86df2c289e7c 139 aci_hal_set_tx_power_level(enHighPower, paLevel);
Andrea Palmieri 251:86df2c289e7c 140 }
Wolfgang Betz 130:770ce14d3d15 141 break;
Wolfgang Betz 130:770ce14d3d15 142 }
Vincent Coubard 270:ca649990a830 143 /**< Appearance */
Vincent Coubard 270:ca649990a830 144 case GapAdvertisingData::APPEARANCE:
Vincent Coubard 253:9665a6f8bbdb 145 {
Vincent Coubard 253:9665a6f8bbdb 146 PRINTF("Advertising type: APPEARANCE\n\r");
Vincent Coubard 253:9665a6f8bbdb 147
Vincent Coubard 253:9665a6f8bbdb 148 GapAdvertisingData::Appearance appearanceP;
Vincent Coubard 253:9665a6f8bbdb 149 memcpy(deviceAppearance, loadPtr.getUnitAtIndex(index).getDataPtr(), 2);
Vincent Coubard 253:9665a6f8bbdb 150
Vincent Coubard 253:9665a6f8bbdb 151 PRINTF("input: deviceAppearance= 0x%x 0x%x\n\r", deviceAppearance[1], deviceAppearance[0]);
Vincent Coubard 253:9665a6f8bbdb 152
Vincent Coubard 253:9665a6f8bbdb 153 appearanceP = (GapAdvertisingData::Appearance)(deviceAppearance[1]<<8|deviceAppearance[0]);
Vincent Coubard 253:9665a6f8bbdb 154 /* Align the GAP Service Appearance Char value coherently */
Vincent Coubard 253:9665a6f8bbdb 155 setAppearance(appearanceP);
Vincent Coubard 253:9665a6f8bbdb 156 break;
Vincent Coubard 253:9665a6f8bbdb 157 }
Vincent Coubard 254:f4d217cadbde 158
Andrea Palmieri 236:2a73f3a97452 159 } // end switch
Andrea Palmieri 236:2a73f3a97452 160
Andrea Palmieri 236:2a73f3a97452 161 } //end for
Andrea Palmieri 236:2a73f3a97452 162
Wolfgang Betz 130:770ce14d3d15 163 }
Vincent Coubard 255:97adb68decd4 164
Vincent Coubard 302:ed6f74ab78f9 165 // update the advertising data in the shield if advertising is running
Vincent Coubard 302:ed6f74ab78f9 166 if (state.advertising == 1) {
Vincent Coubard 302:ed6f74ab78f9 167 tBleStatus ret = hci_le_set_scan_resp_data(scanResponse.getPayloadLen(), scanResponse.getPayload());
Vincent Coubard 302:ed6f74ab78f9 168
Vincent Coubard 302:ed6f74ab78f9 169 if(BLE_STATUS_SUCCESS != ret) {
Vincent Coubard 302:ed6f74ab78f9 170 PRINTF(" error while setting scan response data (ret=0x%x)\n", ret);
Vincent Coubard 302:ed6f74ab78f9 171 switch (ret) {
Vincent Coubard 302:ed6f74ab78f9 172 case BLE_STATUS_TIMEOUT:
Vincent Coubard 302:ed6f74ab78f9 173 return BLE_STACK_BUSY;
Vincent Coubard 302:ed6f74ab78f9 174 default:
Vincent Coubard 302:ed6f74ab78f9 175 return BLE_ERROR_UNSPECIFIED;
Vincent Coubard 302:ed6f74ab78f9 176 }
Vincent Coubard 302:ed6f74ab78f9 177 }
Vincent Coubard 302:ed6f74ab78f9 178
Vincent Coubard 302:ed6f74ab78f9 179 ret = hci_le_set_advertising_data(advData.getPayloadLen(), advData.getPayload());
Vincent Coubard 302:ed6f74ab78f9 180 if (ret) {
Vincent Coubard 302:ed6f74ab78f9 181 PRINTF("error while setting the payload\r\n");
Vincent Coubard 302:ed6f74ab78f9 182 return BLE_ERROR_UNSPECIFIED;
Vincent Coubard 302:ed6f74ab78f9 183 }
Vincent Coubard 302:ed6f74ab78f9 184 }
Vincent Coubard 302:ed6f74ab78f9 185
Vincent Coubard 270:ca649990a830 186 _advData = advData;
Vincent Coubard 270:ca649990a830 187 _scanResponse = scanResponse;
Vincent Coubard 255:97adb68decd4 188
Wolfgang Betz 130:770ce14d3d15 189 return BLE_ERROR_NONE;
Wolfgang Betz 130:770ce14d3d15 190 }
Wolfgang Betz 130:770ce14d3d15 191
Wolfgang Betz 130:770ce14d3d15 192 /*
Wolfgang Betz 130:770ce14d3d15 193 * Utility to set ADV timeout flag
Wolfgang Betz 130:770ce14d3d15 194 */
Wolfgang Betz 130:770ce14d3d15 195 void BlueNRGGap::setAdvToFlag(void) {
Wolfgang Betz 130:770ce14d3d15 196 AdvToFlag = true;
Wolfgang Betz 130:770ce14d3d15 197 }
Wolfgang Betz 130:770ce14d3d15 198
Wolfgang Betz 130:770ce14d3d15 199 /*
Wolfgang Betz 130:770ce14d3d15 200 * ADV timeout callback
Andrea Palmieri 229:9981f62cdb1a 201 */
Wolfgang Betz 138:32e3c4ca7a45 202 #ifdef AST_FOR_MBED_OS
Wolfgang Betz 132:51056160fa4a 203 static void advTimeoutCB(void)
Wolfgang Betz 132:51056160fa4a 204 {
Wolfgang Betz 132:51056160fa4a 205 Gap::GapState_t state;
Vincent Coubard 255:97adb68decd4 206
Wolfgang Betz 132:51056160fa4a 207 state = BlueNRGGap::getInstance().getState();
Wolfgang Betz 132:51056160fa4a 208 if (state.advertising == 1) {
Vincent Coubard 255:97adb68decd4 209
Wolfgang Betz 132:51056160fa4a 210 BlueNRGGap::getInstance().stopAdvertising();
Vincent Coubard 255:97adb68decd4 211
Wolfgang Betz 132:51056160fa4a 212 }
Wolfgang Betz 132:51056160fa4a 213 }
Wolfgang Betz 132:51056160fa4a 214 #else
Wolfgang Betz 130:770ce14d3d15 215 static void advTimeoutCB(void)
Wolfgang Betz 130:770ce14d3d15 216 {
Wolfgang Betz 130:770ce14d3d15 217 Gap::GapState_t state;
Vincent Coubard 255:97adb68decd4 218
Wolfgang Betz 130:770ce14d3d15 219 state = BlueNRGGap::getInstance().getState();
Wolfgang Betz 130:770ce14d3d15 220 if (state.advertising == 1) {
Vincent Coubard 255:97adb68decd4 221
Wolfgang Betz 130:770ce14d3d15 222 BlueNRGGap::getInstance().setAdvToFlag();
Vincent Coubard 255:97adb68decd4 223
Wolfgang Betz 130:770ce14d3d15 224 Timeout t = BlueNRGGap::getInstance().getAdvTimeout();
Wolfgang Betz 130:770ce14d3d15 225 t.detach(); /* disable the callback from the timeout */
Wolfgang Betz 130:770ce14d3d15 226
Wolfgang Betz 130:770ce14d3d15 227 }
Wolfgang Betz 130:770ce14d3d15 228 }
Wolfgang Betz 138:32e3c4ca7a45 229 #endif /* AST_FOR_MBED_OS */
Vincent Coubard 255:97adb68decd4 230
Wolfgang Betz 130:770ce14d3d15 231 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 232 /*!
Wolfgang Betz 130:770ce14d3d15 233 @brief Starts the BLE HW, initialising any services that were
Wolfgang Betz 130:770ce14d3d15 234 added before this function was called.
Vincent Coubard 255:97adb68decd4 235
Wolfgang Betz 130:770ce14d3d15 236 @param[in] params
Wolfgang Betz 130:770ce14d3d15 237 Basic advertising details, including the advertising
Wolfgang Betz 130:770ce14d3d15 238 delay, timeout and how the device should be advertised
Vincent Coubard 255:97adb68decd4 239
Wolfgang Betz 130:770ce14d3d15 240 @note All services must be added before calling this function!
Wolfgang Betz 130:770ce14d3d15 241
Wolfgang Betz 130:770ce14d3d15 242 @returns ble_error_t
Wolfgang Betz 130:770ce14d3d15 243
Wolfgang Betz 130:770ce14d3d15 244 @retval BLE_ERROR_NONE
Wolfgang Betz 130:770ce14d3d15 245 Everything executed properly
Wolfgang Betz 130:770ce14d3d15 246
Wolfgang Betz 130:770ce14d3d15 247 @section EXAMPLE
Wolfgang Betz 130:770ce14d3d15 248
Wolfgang Betz 130:770ce14d3d15 249 @code
Wolfgang Betz 130:770ce14d3d15 250
Wolfgang Betz 130:770ce14d3d15 251 @endcode
Wolfgang Betz 130:770ce14d3d15 252 */
Wolfgang Betz 130:770ce14d3d15 253 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 254
Wolfgang Betz 130:770ce14d3d15 255 ble_error_t BlueNRGGap::startAdvertising(const GapAdvertisingParams &params)
Andrea Palmieri 187:2e517d3ddd71 256 {
Andrea Palmieri 187:2e517d3ddd71 257 tBleStatus ret;
Vincent Coubard 270:ca649990a830 258 int err;
Andrea Palmieri 187:2e517d3ddd71 259
Wolfgang Betz 130:770ce14d3d15 260 /* Make sure we support the advertising type */
Wolfgang Betz 130:770ce14d3d15 261 if (params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) {
Andrea Palmieri 220:e02936f0d4c7 262 /* ToDo: This requires a proper security implementation, etc. */
Wolfgang Betz 130:770ce14d3d15 263 return BLE_ERROR_NOT_IMPLEMENTED;
Wolfgang Betz 130:770ce14d3d15 264 }
Wolfgang Betz 130:770ce14d3d15 265
Wolfgang Betz 130:770ce14d3d15 266 /* Check interval range */
Wolfgang Betz 130:770ce14d3d15 267 if (params.getAdvertisingType() == GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED) {
Wolfgang Betz 130:770ce14d3d15 268 /* Min delay is slightly longer for unconnectable devices */
Wolfgang Betz 130:770ce14d3d15 269 if ((params.getIntervalInADVUnits() < GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MIN_NONCON) ||
Wolfgang Betz 130:770ce14d3d15 270 (params.getIntervalInADVUnits() > GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MAX)) {
Wolfgang Betz 130:770ce14d3d15 271 return BLE_ERROR_PARAM_OUT_OF_RANGE;
Wolfgang Betz 130:770ce14d3d15 272 }
Wolfgang Betz 130:770ce14d3d15 273 } else {
Wolfgang Betz 130:770ce14d3d15 274 if ((params.getIntervalInADVUnits() < GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MIN) ||
Wolfgang Betz 130:770ce14d3d15 275 (params.getIntervalInADVUnits() > GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MAX)) {
Wolfgang Betz 130:770ce14d3d15 276 return BLE_ERROR_PARAM_OUT_OF_RANGE;
Wolfgang Betz 130:770ce14d3d15 277 }
Wolfgang Betz 130:770ce14d3d15 278 }
Wolfgang Betz 130:770ce14d3d15 279
Wolfgang Betz 130:770ce14d3d15 280 /* Check timeout is zero for Connectable Directed */
Wolfgang Betz 130:770ce14d3d15 281 if ((params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) && (params.getTimeout() != 0)) {
Wolfgang Betz 130:770ce14d3d15 282 /* Timeout must be 0 with this type, although we'll never get here */
Wolfgang Betz 130:770ce14d3d15 283 /* since this isn't implemented yet anyway */
Wolfgang Betz 130:770ce14d3d15 284 return BLE_ERROR_PARAM_OUT_OF_RANGE;
Wolfgang Betz 130:770ce14d3d15 285 }
Wolfgang Betz 130:770ce14d3d15 286
Wolfgang Betz 130:770ce14d3d15 287 /* Check timeout for other advertising types */
Wolfgang Betz 130:770ce14d3d15 288 if ((params.getAdvertisingType() != GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) &&
Wolfgang Betz 130:770ce14d3d15 289 (params.getTimeout() > GapAdvertisingParams::GAP_ADV_PARAMS_TIMEOUT_MAX)) {
Wolfgang Betz 130:770ce14d3d15 290 return BLE_ERROR_PARAM_OUT_OF_RANGE;
Wolfgang Betz 130:770ce14d3d15 291 }
Wolfgang Betz 130:770ce14d3d15 292
Andrea Palmieri 229:9981f62cdb1a 293 /*
Andrea Palmieri 229:9981f62cdb1a 294 * Advertising filter policy setting
Andrea Palmieri 229:9981f62cdb1a 295 * FIXME: the Security Manager should be implemented
Andrea Palmieri 229:9981f62cdb1a 296 */
Andrea Palmieri 229:9981f62cdb1a 297 AdvertisingPolicyMode_t mode = getAdvertisingPolicyMode();
Andrea Palmieri 229:9981f62cdb1a 298 if(mode != ADV_POLICY_IGNORE_WHITELIST) {
Andrea Palmieri 229:9981f62cdb1a 299 ret = aci_gap_configure_whitelist();
Andrea Palmieri 229:9981f62cdb1a 300 if(ret != BLE_STATUS_SUCCESS) {
Andrea Palmieri 229:9981f62cdb1a 301 PRINTF("aci_gap_configure_whitelist ret=0x%x\n\r", ret);
Andrea Palmieri 229:9981f62cdb1a 302 return BLE_ERROR_OPERATION_NOT_PERMITTED;
Andrea Palmieri 229:9981f62cdb1a 303 }
Andrea Palmieri 229:9981f62cdb1a 304 }
Andrea Palmieri 229:9981f62cdb1a 305
Andrea Palmieri 229:9981f62cdb1a 306 uint8_t advFilterPolicy = NO_WHITE_LIST_USE;
Andrea Palmieri 229:9981f62cdb1a 307 switch(mode) {
Andrea Palmieri 229:9981f62cdb1a 308 case ADV_POLICY_FILTER_SCAN_REQS:
Andrea Palmieri 229:9981f62cdb1a 309 advFilterPolicy = WHITE_LIST_FOR_ONLY_SCAN;
Andrea Palmieri 229:9981f62cdb1a 310 break;
Andrea Palmieri 229:9981f62cdb1a 311 case ADV_POLICY_FILTER_CONN_REQS:
Andrea Palmieri 229:9981f62cdb1a 312 advFilterPolicy = WHITE_LIST_FOR_ONLY_CONN;
Andrea Palmieri 229:9981f62cdb1a 313 break;
Andrea Palmieri 229:9981f62cdb1a 314 case ADV_POLICY_FILTER_ALL_REQS:
Andrea Palmieri 229:9981f62cdb1a 315 advFilterPolicy = WHITE_LIST_FOR_ALL;
Andrea Palmieri 229:9981f62cdb1a 316 break;
Andrea Palmieri 229:9981f62cdb1a 317 default:
Andrea Palmieri 229:9981f62cdb1a 318 advFilterPolicy = NO_WHITE_LIST_USE;
Andrea Palmieri 229:9981f62cdb1a 319 break;
Andrea Palmieri 229:9981f62cdb1a 320 }
Andrea Palmieri 229:9981f62cdb1a 321
Andrea Palmieri 228:25368f053411 322 /* Check the ADV type before setting scan response data */
Andrea Palmieri 228:25368f053411 323 if (params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED ||
Andrea Palmieri 228:25368f053411 324 params.getAdvertisingType() == GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED) {
Andrea Palmieri 228:25368f053411 325
Andrea Palmieri 228:25368f053411 326 /* set scan response data */
Vincent Coubard 270:ca649990a830 327 PRINTF(" setting scan response data (_scanResponseLen=%u)\n", _scanResponse.getPayloadLen());
Vincent Coubard 270:ca649990a830 328 ret = hci_le_set_scan_resp_data(_scanResponse.getPayloadLen(), _scanResponse.getPayload());
Andrea Palmieri 228:25368f053411 329
Andrea Palmieri 228:25368f053411 330 if(BLE_STATUS_SUCCESS!=ret) {
Andrea Palmieri 228:25368f053411 331 PRINTF(" error while setting scan response data (ret=0x%x)\n", ret);
Andrea Palmieri 228:25368f053411 332 switch (ret) {
Andrea Palmieri 228:25368f053411 333 case BLE_STATUS_TIMEOUT:
Andrea Palmieri 228:25368f053411 334 return BLE_STACK_BUSY;
Andrea Palmieri 228:25368f053411 335 default:
Andrea Palmieri 228:25368f053411 336 return BLE_ERROR_UNSPECIFIED;
Andrea Palmieri 228:25368f053411 337 }
Andrea Palmieri 187:2e517d3ddd71 338 }
Andrea Palmieri 228:25368f053411 339 } else {
Andrea Palmieri 228:25368f053411 340 hci_le_set_scan_resp_data(0, NULL);
Andrea Palmieri 187:2e517d3ddd71 341 }
Wolfgang Betz 130:770ce14d3d15 342
Andrea Palmieri 232:aead10288880 343 setAdvParameters();
Andrea Palmieri 232:aead10288880 344 PRINTF("advInterval=%d advType=%d\n\r", advInterval, params.getAdvertisingType());
Wolfgang Betz 130:770ce14d3d15 345
Vincent Coubard 270:ca649990a830 346 err = hci_le_set_advertising_data(_advData.getPayloadLen(), _advData.getPayload());
Vincent Coubard 270:ca649990a830 347
Vincent Coubard 270:ca649990a830 348 if (err) {
Vincent Coubard 270:ca649990a830 349 PRINTF("error while setting the payload\r\n");
Vincent Coubard 270:ca649990a830 350 return BLE_ERROR_UNSPECIFIED;
Vincent Coubard 270:ca649990a830 351 }
Vincent Coubard 270:ca649990a830 352
Vincent Coubard 255:97adb68decd4 353 tBDAddr dummy_addr = { 0 };
Vincent Coubard 255:97adb68decd4 354 uint16_t advIntervalMin = advInterval == GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MAX ? advInterval - 1 : advInterval;
Vincent Coubard 255:97adb68decd4 355 uint16_t advIntervalMax = advIntervalMin + 1;
Vincent Coubard 255:97adb68decd4 356
Vincent Coubard 270:ca649990a830 357 err = hci_le_set_advertising_parameters(
Vincent Coubard 255:97adb68decd4 358 advIntervalMin,
Vincent Coubard 255:97adb68decd4 359 advIntervalMax,
Vincent Coubard 255:97adb68decd4 360 params.getAdvertisingType(),
Vincent Coubard 255:97adb68decd4 361 addr_type,
Vincent Coubard 255:97adb68decd4 362 0x00,
Vincent Coubard 255:97adb68decd4 363 dummy_addr,
Vincent Coubard 255:97adb68decd4 364 /* all channels */ 7,
Vincent Coubard 255:97adb68decd4 365 advFilterPolicy
Vincent Coubard 255:97adb68decd4 366 );
Vincent Coubard 255:97adb68decd4 367
Vincent Coubard 255:97adb68decd4 368 if (err) {
Vincent Coubard 259:323f588e5f57 369 PRINTF("impossible to set advertising parameters\n\r");
Vincent Coubard 259:323f588e5f57 370 PRINTF("advInterval min: %u, advInterval max: %u\n\r", advInterval, advInterval + 1);
Vincent Coubard 259:323f588e5f57 371 PRINTF("advType: %u, advFilterPolicy: %u\n\r", params.getAdvertisingType(), advFilterPolicy);
Vincent Coubard 255:97adb68decd4 372 return BLE_ERROR_INVALID_PARAM;
Vincent Coubard 255:97adb68decd4 373 }
Vincent Coubard 255:97adb68decd4 374
Vincent Coubard 255:97adb68decd4 375 err = hci_le_set_advertise_enable(0x01);
Vincent Coubard 255:97adb68decd4 376 if (err) {
Vincent Coubard 255:97adb68decd4 377 PRINTF("impossible to start advertising\n\r");
Vincent Coubard 255:97adb68decd4 378 return BLE_ERROR_UNSPECIFIED;
Vincent Coubard 255:97adb68decd4 379 }
Vincent Coubard 255:97adb68decd4 380
Vincent Coubard 255:97adb68decd4 381 state.advertising = 1;
Wolfgang Betz 130:770ce14d3d15 382
Vincent Coubard 255:97adb68decd4 383 AdvToFlag = false;
Vincent Coubard 255:97adb68decd4 384 if(params.getTimeout() != 0) {
Vincent Coubard 255:97adb68decd4 385 PRINTF("!!! attaching to!!!\n");
Vincent Coubard 255:97adb68decd4 386 #ifdef AST_FOR_MBED_OS
Vincent Coubard 255:97adb68decd4 387 minar::Scheduler::postCallback(advTimeoutCB).delay(minar::milliseconds(params.getTimeout() * 1000));
Vincent Coubard 255:97adb68decd4 388 #else
Vincent Coubard 255:97adb68decd4 389 advTimeout.attach(advTimeoutCB, params.getTimeout() * 1000);
Vincent Coubard 255:97adb68decd4 390 #endif
Vincent Coubard 255:97adb68decd4 391 }
Vincent Coubard 255:97adb68decd4 392
Vincent Coubard 255:97adb68decd4 393 return BLE_ERROR_NONE;
Vincent Coubard 255:97adb68decd4 394
Wolfgang Betz 130:770ce14d3d15 395 }
Wolfgang Betz 130:770ce14d3d15 396
Andrea Palmieri 238:b6454c839f42 397
Wolfgang Betz 130:770ce14d3d15 398 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 399 /*!
Wolfgang Betz 130:770ce14d3d15 400 @brief Stops the BLE HW and disconnects from any devices
Wolfgang Betz 130:770ce14d3d15 401
Wolfgang Betz 130:770ce14d3d15 402 @returns ble_error_t
Wolfgang Betz 130:770ce14d3d15 403
Wolfgang Betz 130:770ce14d3d15 404 @retval BLE_ERROR_NONE
Wolfgang Betz 130:770ce14d3d15 405 Everything executed properly
Wolfgang Betz 130:770ce14d3d15 406
Wolfgang Betz 130:770ce14d3d15 407 @section EXAMPLE
Wolfgang Betz 130:770ce14d3d15 408
Wolfgang Betz 130:770ce14d3d15 409 @code
Wolfgang Betz 130:770ce14d3d15 410
Wolfgang Betz 130:770ce14d3d15 411 @endcode
Wolfgang Betz 130:770ce14d3d15 412 */
Wolfgang Betz 130:770ce14d3d15 413 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 414 ble_error_t BlueNRGGap::stopAdvertising(void)
Wolfgang Betz 130:770ce14d3d15 415 {
Andrea Palmieri 229:9981f62cdb1a 416
Wolfgang Betz 130:770ce14d3d15 417 if(state.advertising == 1) {
Vincent Coubard 255:97adb68decd4 418
Vincent Coubard 255:97adb68decd4 419 int err = hci_le_set_advertise_enable(0);
Vincent Coubard 255:97adb68decd4 420 if (err) {
Vincent Coubard 255:97adb68decd4 421 return BLE_ERROR_OPERATION_NOT_PERMITTED;
Wolfgang Betz 130:770ce14d3d15 422 }
Vincent Coubard 255:97adb68decd4 423
Wolfgang Betz 132:51056160fa4a 424 PRINTF("Advertisement stopped!!\n\r") ;
Wolfgang Betz 130:770ce14d3d15 425 //Set GapState_t::advertising state
Wolfgang Betz 130:770ce14d3d15 426 state.advertising = 0;
Wolfgang Betz 130:770ce14d3d15 427 }
Vincent Coubard 255:97adb68decd4 428
Wolfgang Betz 130:770ce14d3d15 429 return BLE_ERROR_NONE;
Wolfgang Betz 130:770ce14d3d15 430 }
Wolfgang Betz 130:770ce14d3d15 431
Wolfgang Betz 130:770ce14d3d15 432 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 433 /*!
Wolfgang Betz 130:770ce14d3d15 434 @brief Disconnects if we are connected to a central device
Wolfgang Betz 130:770ce14d3d15 435
Wolfgang Betz 130:770ce14d3d15 436 @param[in] reason
Wolfgang Betz 130:770ce14d3d15 437 Disconnection Reason
Vincent Coubard 255:97adb68decd4 438
Wolfgang Betz 130:770ce14d3d15 439 @returns ble_error_t
Wolfgang Betz 130:770ce14d3d15 440
Wolfgang Betz 130:770ce14d3d15 441 @retval BLE_ERROR_NONE
Wolfgang Betz 130:770ce14d3d15 442 Everything executed properly
Wolfgang Betz 130:770ce14d3d15 443
Wolfgang Betz 130:770ce14d3d15 444 @section EXAMPLE
Wolfgang Betz 130:770ce14d3d15 445
Wolfgang Betz 130:770ce14d3d15 446 @code
Wolfgang Betz 130:770ce14d3d15 447
Wolfgang Betz 130:770ce14d3d15 448 @endcode
Wolfgang Betz 130:770ce14d3d15 449 */
Wolfgang Betz 130:770ce14d3d15 450 /**************************************************************************/
Andrea Palmieri 239:8e93d6e26c55 451 ble_error_t BlueNRGGap::disconnect(Handle_t connectionHandle, Gap::DisconnectionReason_t reason)
Wolfgang Betz 130:770ce14d3d15 452 {
Andrea Palmieri 239:8e93d6e26c55 453 tBleStatus ret;
Andrea Palmieri 142:adf1567d3900 454
Andrea Palmieri 239:8e93d6e26c55 455 ret = aci_gap_terminate(connectionHandle, reason);
Wolfgang Betz 130:770ce14d3d15 456
Andrea Palmieri 239:8e93d6e26c55 457 if (BLE_STATUS_SUCCESS != ret){
Andrea Palmieri 239:8e93d6e26c55 458 PRINTF("Error in GAP termination (ret=0x%x)!!\n\r", ret) ;
Andrea Palmieri 239:8e93d6e26c55 459 switch (ret) {
Andrea Palmieri 239:8e93d6e26c55 460 case ERR_COMMAND_DISALLOWED:
Andrea Palmieri 239:8e93d6e26c55 461 return BLE_ERROR_OPERATION_NOT_PERMITTED;
Andrea Palmieri 239:8e93d6e26c55 462 case BLE_STATUS_TIMEOUT:
Andrea Palmieri 239:8e93d6e26c55 463 return BLE_STACK_BUSY;
Andrea Palmieri 239:8e93d6e26c55 464 default:
Andrea Palmieri 239:8e93d6e26c55 465 return BLE_ERROR_UNSPECIFIED;
Wolfgang Betz 130:770ce14d3d15 466 }
Wolfgang Betz 130:770ce14d3d15 467 }
Vincent Coubard 255:97adb68decd4 468
Wolfgang Betz 130:770ce14d3d15 469 return BLE_ERROR_NONE;
Wolfgang Betz 130:770ce14d3d15 470 }
Wolfgang Betz 130:770ce14d3d15 471
Wolfgang Betz 130:770ce14d3d15 472 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 473 /*!
Wolfgang Betz 130:770ce14d3d15 474 @brief Disconnects if we are connected to a central device
Wolfgang Betz 130:770ce14d3d15 475
Wolfgang Betz 130:770ce14d3d15 476 @param[in] reason
Wolfgang Betz 130:770ce14d3d15 477 Disconnection Reason
Vincent Coubard 255:97adb68decd4 478
Wolfgang Betz 130:770ce14d3d15 479 @returns ble_error_t
Wolfgang Betz 130:770ce14d3d15 480
Wolfgang Betz 130:770ce14d3d15 481 @retval BLE_ERROR_NONE
Wolfgang Betz 130:770ce14d3d15 482 Everything executed properly
Wolfgang Betz 130:770ce14d3d15 483
Wolfgang Betz 130:770ce14d3d15 484 @section EXAMPLE
Wolfgang Betz 130:770ce14d3d15 485
Wolfgang Betz 130:770ce14d3d15 486 @code
Wolfgang Betz 130:770ce14d3d15 487
Wolfgang Betz 130:770ce14d3d15 488 @endcode
Wolfgang Betz 130:770ce14d3d15 489 */
Wolfgang Betz 130:770ce14d3d15 490 /**************************************************************************/
Andrea Palmieri 239:8e93d6e26c55 491 ble_error_t BlueNRGGap::disconnect(Gap::DisconnectionReason_t reason)
Wolfgang Betz 130:770ce14d3d15 492 {
Andrea Palmieri 239:8e93d6e26c55 493 return disconnect(m_connectionHandle, reason);
Wolfgang Betz 130:770ce14d3d15 494 }
Wolfgang Betz 130:770ce14d3d15 495
Wolfgang Betz 130:770ce14d3d15 496 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 497 /*!
Wolfgang Betz 130:770ce14d3d15 498 @brief Sets the 16-bit connection handle
Vincent Coubard 255:97adb68decd4 499
Andrea Palmieri 239:8e93d6e26c55 500 @param[in] conn_handle
Wolfgang Betz 130:770ce14d3d15 501 Connection Handle which is set in the Gap Instance
Vincent Coubard 255:97adb68decd4 502
Wolfgang Betz 130:770ce14d3d15 503 @returns void
Wolfgang Betz 130:770ce14d3d15 504 */
Wolfgang Betz 130:770ce14d3d15 505 /**************************************************************************/
Andrea Palmieri 239:8e93d6e26c55 506 void BlueNRGGap::setConnectionHandle(uint16_t conn_handle)
Wolfgang Betz 130:770ce14d3d15 507 {
Andrea Palmieri 239:8e93d6e26c55 508 m_connectionHandle = conn_handle;
Wolfgang Betz 130:770ce14d3d15 509 }
Wolfgang Betz 130:770ce14d3d15 510
Wolfgang Betz 130:770ce14d3d15 511 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 512 /*!
Wolfgang Betz 130:770ce14d3d15 513 @brief Gets the 16-bit connection handle
Vincent Coubard 255:97adb68decd4 514
Wolfgang Betz 130:770ce14d3d15 515 @param[in] void
Vincent Coubard 255:97adb68decd4 516
Wolfgang Betz 130:770ce14d3d15 517 @returns uint16_t
Wolfgang Betz 130:770ce14d3d15 518 Connection Handle of the Gap Instance
Wolfgang Betz 130:770ce14d3d15 519 */
Wolfgang Betz 130:770ce14d3d15 520 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 521 uint16_t BlueNRGGap::getConnectionHandle(void)
Wolfgang Betz 130:770ce14d3d15 522 {
Wolfgang Betz 130:770ce14d3d15 523 return m_connectionHandle;
Wolfgang Betz 130:770ce14d3d15 524 }
Wolfgang Betz 130:770ce14d3d15 525
Wolfgang Betz 130:770ce14d3d15 526 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 527 /*!
Wolfgang Betz 130:770ce14d3d15 528 @brief Sets the BLE device address. SetAddress will reset the BLE
Wolfgang Betz 130:770ce14d3d15 529 device and re-initialize BTLE. Will not start advertising.
Wolfgang Betz 130:770ce14d3d15 530
Wolfgang Betz 130:770ce14d3d15 531 @param[in] type
Wolfgang Betz 130:770ce14d3d15 532 Type of Address
Vincent Coubard 255:97adb68decd4 533
Wolfgang Betz 130:770ce14d3d15 534 @param[in] address[6]
Wolfgang Betz 130:770ce14d3d15 535 Value of the Address to be set
Vincent Coubard 255:97adb68decd4 536
Wolfgang Betz 130:770ce14d3d15 537 @returns ble_error_t
Wolfgang Betz 130:770ce14d3d15 538
Wolfgang Betz 130:770ce14d3d15 539 @section EXAMPLE
Wolfgang Betz 130:770ce14d3d15 540
Wolfgang Betz 130:770ce14d3d15 541 @code
Wolfgang Betz 130:770ce14d3d15 542
Wolfgang Betz 130:770ce14d3d15 543 @endcode
Wolfgang Betz 130:770ce14d3d15 544 */
Wolfgang Betz 130:770ce14d3d15 545 /**************************************************************************/
Andrea Palmieri 239:8e93d6e26c55 546 ble_error_t BlueNRGGap::setAddress(AddressType_t type, const BLEProtocol::AddressBytes_t address)
Wolfgang Betz 130:770ce14d3d15 547 {
Andrea Palmieri 210:08c4c85ca679 548 if (type > BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE) {
Wolfgang Betz 130:770ce14d3d15 549 return BLE_ERROR_PARAM_OUT_OF_RANGE;
Wolfgang Betz 130:770ce14d3d15 550 }
Vincent Coubard 255:97adb68decd4 551
Vincent Coubard 268:c0a1e03c5736 552 if(type == BLEProtocol::AddressType::PUBLIC){
Vincent Coubard 268:c0a1e03c5736 553 tBleStatus ret = aci_hal_write_config_data(
Vincent Coubard 268:c0a1e03c5736 554 CONFIG_DATA_PUBADDR_OFFSET,
Vincent Coubard 268:c0a1e03c5736 555 CONFIG_DATA_PUBADDR_LEN,
Vincent Coubard 268:c0a1e03c5736 556 address
Vincent Coubard 268:c0a1e03c5736 557 );
Andrea Palmieri 229:9981f62cdb1a 558 if(ret != BLE_STATUS_SUCCESS) {
Andrea Palmieri 239:8e93d6e26c55 559 return BLE_ERROR_OPERATION_NOT_PERMITTED;
Andrea Palmieri 229:9981f62cdb1a 560 }
Vincent Coubard 268:c0a1e03c5736 561 } else if (type == BLEProtocol::AddressType::RANDOM_STATIC) {
Vincent Coubard 268:c0a1e03c5736 562 // ensure that the random static address is well formed
Vincent Coubard 268:c0a1e03c5736 563 if ((address[5] & 0xC0) != 0xC0) {
Vincent Coubard 268:c0a1e03c5736 564 return BLE_ERROR_PARAM_OUT_OF_RANGE;
Vincent Coubard 268:c0a1e03c5736 565 }
Vincent Coubard 268:c0a1e03c5736 566
Vincent Coubard 268:c0a1e03c5736 567 // thanks to const correctness of the API ...
Vincent Coubard 268:c0a1e03c5736 568 tBDAddr random_address = { 0 };
Vincent Coubard 268:c0a1e03c5736 569 memcpy(random_address, address, sizeof(random_address));
Vincent Coubard 268:c0a1e03c5736 570 int err = hci_le_set_random_address(random_address);
Vincent Coubard 268:c0a1e03c5736 571 if (err) {
Vincent Coubard 268:c0a1e03c5736 572 return BLE_ERROR_OPERATION_NOT_PERMITTED;
Vincent Coubard 268:c0a1e03c5736 573 }
Vincent Coubard 268:c0a1e03c5736 574
Vincent Coubard 268:c0a1e03c5736 575 // It is not possible to get the bluetooth address when it is set
Vincent Coubard 268:c0a1e03c5736 576 // store it locally in class data member
Vincent Coubard 268:c0a1e03c5736 577 memcpy(bdaddr, address, sizeof(bdaddr));
Andrea Palmieri 239:8e93d6e26c55 578 } else {
Vincent Coubard 268:c0a1e03c5736 579 // FIXME random addresses are not supported yet
Vincent Coubard 268:c0a1e03c5736 580 // BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE
Vincent Coubard 268:c0a1e03c5736 581 // BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE
Vincent Coubard 268:c0a1e03c5736 582 return BLE_ERROR_NOT_IMPLEMENTED;
Wolfgang Betz 130:770ce14d3d15 583 }
Vincent Coubard 255:97adb68decd4 584
Vincent Coubard 268:c0a1e03c5736 585 // if we're here then the address was correctly set
Vincent Coubard 268:c0a1e03c5736 586 // commit it inside the addr_type
Vincent Coubard 268:c0a1e03c5736 587 addr_type = type;
Vincent Coubard 268:c0a1e03c5736 588 isSetAddress = true;
Wolfgang Betz 130:770ce14d3d15 589 return BLE_ERROR_NONE;
Wolfgang Betz 130:770ce14d3d15 590 }
Andrea Palmieri 229:9981f62cdb1a 591
Wolfgang Betz 130:770ce14d3d15 592 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 593 /*!
Wolfgang Betz 130:770ce14d3d15 594 @brief Returns boolean if the address of the device has been set
Wolfgang Betz 130:770ce14d3d15 595 or not
Vincent Coubard 255:97adb68decd4 596
Wolfgang Betz 130:770ce14d3d15 597 @returns bool
Wolfgang Betz 130:770ce14d3d15 598
Wolfgang Betz 130:770ce14d3d15 599 @section EXAMPLE
Wolfgang Betz 130:770ce14d3d15 600
Wolfgang Betz 130:770ce14d3d15 601 @code
Wolfgang Betz 130:770ce14d3d15 602
Wolfgang Betz 130:770ce14d3d15 603 @endcode
Wolfgang Betz 130:770ce14d3d15 604 */
Wolfgang Betz 130:770ce14d3d15 605 /**************************************************************************/
Vincent Coubard 255:97adb68decd4 606 bool BlueNRGGap::getIsSetAddress()
Wolfgang Betz 130:770ce14d3d15 607 {
Vincent Coubard 255:97adb68decd4 608 return isSetAddress;
Wolfgang Betz 130:770ce14d3d15 609 }
Wolfgang Betz 130:770ce14d3d15 610
Wolfgang Betz 130:770ce14d3d15 611 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 612 /*!
Wolfgang Betz 130:770ce14d3d15 613 @brief Returns the address of the device if set
Wolfgang Betz 130:770ce14d3d15 614
Wolfgang Betz 130:770ce14d3d15 615 @returns Pointer to the address if Address is set else NULL
Wolfgang Betz 130:770ce14d3d15 616
Wolfgang Betz 130:770ce14d3d15 617 @section EXAMPLE
Wolfgang Betz 130:770ce14d3d15 618
Wolfgang Betz 130:770ce14d3d15 619 @code
Wolfgang Betz 130:770ce14d3d15 620
Wolfgang Betz 130:770ce14d3d15 621 @endcode
Wolfgang Betz 130:770ce14d3d15 622 */
Wolfgang Betz 130:770ce14d3d15 623 /**************************************************************************/
Vincent Coubard 265:46333d70cf81 624 ble_error_t BlueNRGGap::getAddress(BLEProtocol::AddressType_t *typeP, BLEProtocol::AddressBytes_t address)
Wolfgang Betz 130:770ce14d3d15 625 {
Andrea Palmieri 229:9981f62cdb1a 626 uint8_t bdaddr[BDADDR_SIZE];
Andrea Palmieri 229:9981f62cdb1a 627 uint8_t data_len_out;
Andrea Palmieri 229:9981f62cdb1a 628
Vincent Coubard 268:c0a1e03c5736 629 // precondition, check that pointers in input are valid
Vincent Coubard 268:c0a1e03c5736 630 if (typeP == NULL || address == NULL) {
Vincent Coubard 268:c0a1e03c5736 631 return BLE_ERROR_INVALID_PARAM;
Andrea Palmieri 228:25368f053411 632 }
Andrea Palmieri 228:25368f053411 633
Vincent Coubard 268:c0a1e03c5736 634 if (addr_type == BLEProtocol::AddressType::PUBLIC) {
Vincent Coubard 268:c0a1e03c5736 635 tBleStatus ret = aci_hal_read_config_data(CONFIG_DATA_PUBADDR_OFFSET, BDADDR_SIZE, &data_len_out, bdaddr);
Vincent Coubard 268:c0a1e03c5736 636 if(ret != BLE_STATUS_SUCCESS || data_len_out != BDADDR_SIZE) {
Vincent Coubard 268:c0a1e03c5736 637 return BLE_ERROR_UNSPECIFIED;
Vincent Coubard 268:c0a1e03c5736 638 }
Vincent Coubard 268:c0a1e03c5736 639 } else if (addr_type == BLEProtocol::AddressType::RANDOM_STATIC) {
Vincent Coubard 268:c0a1e03c5736 640 // FIXME hci_read_bd_addr and
Vincent Coubard 268:c0a1e03c5736 641 // aci_hal_read_config_data CONFIG_DATA_RANDOM_ADDRESS_IDB05A1
Vincent Coubard 268:c0a1e03c5736 642 // does not work, use the address stored in class data member
Vincent Coubard 268:c0a1e03c5736 643 memcpy(bdaddr, this->bdaddr, sizeof(bdaddr));
Vincent Coubard 268:c0a1e03c5736 644 } else {
Vincent Coubard 268:c0a1e03c5736 645 // FIXME: should be implemented with privacy features
Vincent Coubard 268:c0a1e03c5736 646 // BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE
Vincent Coubard 268:c0a1e03c5736 647 // BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE
Vincent Coubard 268:c0a1e03c5736 648 return BLE_ERROR_NOT_IMPLEMENTED;
Andrea Palmieri 229:9981f62cdb1a 649 }
Andrea Palmieri 229:9981f62cdb1a 650
Vincent Coubard 268:c0a1e03c5736 651 *typeP = addr_type;
Vincent Coubard 268:c0a1e03c5736 652 memcpy(address, bdaddr, BDADDR_SIZE);
Vincent Coubard 255:97adb68decd4 653
Wolfgang Betz 130:770ce14d3d15 654 return BLE_ERROR_NONE;
Wolfgang Betz 130:770ce14d3d15 655 }
Wolfgang Betz 130:770ce14d3d15 656
Wolfgang Betz 130:770ce14d3d15 657 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 658 /*!
Wolfgang Betz 130:770ce14d3d15 659 @brief obtains preferred connection params
Wolfgang Betz 130:770ce14d3d15 660
Wolfgang Betz 130:770ce14d3d15 661 @returns ble_error_t
Wolfgang Betz 130:770ce14d3d15 662
Wolfgang Betz 130:770ce14d3d15 663 @section EXAMPLE
Wolfgang Betz 130:770ce14d3d15 664
Wolfgang Betz 130:770ce14d3d15 665 @code
Wolfgang Betz 130:770ce14d3d15 666
Wolfgang Betz 130:770ce14d3d15 667 @endcode
Wolfgang Betz 130:770ce14d3d15 668 */
Wolfgang Betz 130:770ce14d3d15 669 /**************************************************************************/
Vincent Coubard 255:97adb68decd4 670 ble_error_t BlueNRGGap::getPreferredConnectionParams(ConnectionParams_t *params)
Wolfgang Betz 130:770ce14d3d15 671 {
Vincent Coubard 266:b49e28134d83 672 static const size_t parameter_size = 2;
Vincent Coubard 266:b49e28134d83 673
Vincent Coubard 266:b49e28134d83 674 if (!g_preferred_connection_parameters_char_handle) {
Vincent Coubard 266:b49e28134d83 675 return BLE_ERROR_OPERATION_NOT_PERMITTED;
Vincent Coubard 266:b49e28134d83 676 }
Vincent Coubard 266:b49e28134d83 677
Vincent Coubard 266:b49e28134d83 678 // Peripheral preferred connection parameters are an array of 4 uint16_t
Vincent Coubard 266:b49e28134d83 679 uint8_t parameters_packed[parameter_size * 4];
Vincent Coubard 266:b49e28134d83 680 uint16_t bytes_read = 0;
Andrea Palmieri 142:adf1567d3900 681
Vincent Coubard 266:b49e28134d83 682 tBleStatus err = aci_gatt_read_handle_value(
Vincent Coubard 266:b49e28134d83 683 g_preferred_connection_parameters_char_handle + BlueNRGGattServer::CHAR_VALUE_HANDLE,
Vincent Coubard 266:b49e28134d83 684 sizeof(parameters_packed),
Vincent Coubard 266:b49e28134d83 685 &bytes_read,
Vincent Coubard 266:b49e28134d83 686 parameters_packed
Vincent Coubard 266:b49e28134d83 687 );
Vincent Coubard 266:b49e28134d83 688
Vincent Coubard 266:b49e28134d83 689 PRINTF("getPreferredConnectionParams err=0x%02x (bytes_read=%u)\n\r", err, bytes_read);
Vincent Coubard 266:b49e28134d83 690
Vincent Coubard 266:b49e28134d83 691 // check that the read succeed and the result have the expected length
Vincent Coubard 266:b49e28134d83 692 if (err || bytes_read != sizeof(parameters_packed)) {
Vincent Coubard 266:b49e28134d83 693 return BLE_ERROR_UNSPECIFIED;
Vincent Coubard 266:b49e28134d83 694 }
Vincent Coubard 266:b49e28134d83 695
Vincent Coubard 266:b49e28134d83 696 // memcpy field by field
Vincent Coubard 266:b49e28134d83 697 memcpy(&params->minConnectionInterval, parameters_packed, parameter_size);
Vincent Coubard 266:b49e28134d83 698 memcpy(&params->maxConnectionInterval, &parameters_packed[parameter_size], parameter_size);
Vincent Coubard 266:b49e28134d83 699 memcpy(&params->slaveLatency, &parameters_packed[2 * parameter_size], parameter_size);
Vincent Coubard 266:b49e28134d83 700 memcpy(&params->connectionSupervisionTimeout, &parameters_packed[3 * parameter_size], parameter_size);
Vincent Coubard 266:b49e28134d83 701
Vincent Coubard 266:b49e28134d83 702 return BLE_ERROR_NONE;
Wolfgang Betz 130:770ce14d3d15 703 }
Wolfgang Betz 130:770ce14d3d15 704
Wolfgang Betz 130:770ce14d3d15 705
Wolfgang Betz 130:770ce14d3d15 706 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 707 /*!
Wolfgang Betz 130:770ce14d3d15 708 @brief sets preferred connection params
Wolfgang Betz 130:770ce14d3d15 709
Wolfgang Betz 130:770ce14d3d15 710 @returns ble_error_t
Wolfgang Betz 130:770ce14d3d15 711
Wolfgang Betz 130:770ce14d3d15 712 @section EXAMPLE
Wolfgang Betz 130:770ce14d3d15 713
Wolfgang Betz 130:770ce14d3d15 714 @code
Wolfgang Betz 130:770ce14d3d15 715
Wolfgang Betz 130:770ce14d3d15 716 @endcode
Wolfgang Betz 130:770ce14d3d15 717 */
Wolfgang Betz 130:770ce14d3d15 718 /**************************************************************************/
Vincent Coubard 255:97adb68decd4 719 ble_error_t BlueNRGGap::setPreferredConnectionParams(const ConnectionParams_t *params)
Wolfgang Betz 130:770ce14d3d15 720 {
Vincent Coubard 266:b49e28134d83 721 static const size_t parameter_size = 2;
Vincent Coubard 266:b49e28134d83 722 uint8_t parameters_packed[parameter_size * 4];
Vincent Coubard 266:b49e28134d83 723
Vincent Coubard 266:b49e28134d83 724 // ensure that parameters are correct
Vincent Coubard 266:b49e28134d83 725 // see BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part C]
Vincent Coubard 266:b49e28134d83 726 // section 12.3 PERIPHERAL PREFERRED CONNECTION PARAMETERS CHARACTERISTIC
Vincent Coubard 266:b49e28134d83 727 if (((0x0006 > params->minConnectionInterval) || (params->minConnectionInterval > 0x0C80)) &&
Vincent Coubard 266:b49e28134d83 728 params->minConnectionInterval != 0xFFFF) {
Vincent Coubard 266:b49e28134d83 729 return BLE_ERROR_PARAM_OUT_OF_RANGE;
Vincent Coubard 266:b49e28134d83 730 }
Vincent Coubard 266:b49e28134d83 731
Vincent Coubard 266:b49e28134d83 732 if (((params->minConnectionInterval > params->maxConnectionInterval) || (params->maxConnectionInterval > 0x0C80)) &&
Vincent Coubard 266:b49e28134d83 733 params->maxConnectionInterval != 0xFFFF) {
Vincent Coubard 266:b49e28134d83 734 return BLE_ERROR_PARAM_OUT_OF_RANGE;
Vincent Coubard 266:b49e28134d83 735 }
Vincent Coubard 266:b49e28134d83 736
Vincent Coubard 266:b49e28134d83 737 if (params->slaveLatency > 0x01F3) {
Vincent Coubard 266:b49e28134d83 738 return BLE_ERROR_PARAM_OUT_OF_RANGE;
Vincent Coubard 266:b49e28134d83 739 }
Vincent Coubard 266:b49e28134d83 740
Vincent Coubard 266:b49e28134d83 741 if (((0x000A > params->connectionSupervisionTimeout) || (params->connectionSupervisionTimeout > 0x0C80)) &&
Vincent Coubard 266:b49e28134d83 742 params->connectionSupervisionTimeout != 0xFFFF) {
Vincent Coubard 266:b49e28134d83 743 return BLE_ERROR_PARAM_OUT_OF_RANGE;
Vincent Coubard 266:b49e28134d83 744 }
Andrea Palmieri 142:adf1567d3900 745
Vincent Coubard 266:b49e28134d83 746 // copy the parameters inside the byte array
Vincent Coubard 266:b49e28134d83 747 memcpy(parameters_packed, &params->minConnectionInterval, parameter_size);
Vincent Coubard 266:b49e28134d83 748 memcpy(&parameters_packed[parameter_size], &params->maxConnectionInterval, parameter_size);
Vincent Coubard 266:b49e28134d83 749 memcpy(&parameters_packed[2 * parameter_size], &params->slaveLatency, parameter_size);
Vincent Coubard 266:b49e28134d83 750 memcpy(&parameters_packed[3 * parameter_size], &params->connectionSupervisionTimeout, parameter_size);
Vincent Coubard 266:b49e28134d83 751
Vincent Coubard 266:b49e28134d83 752 tBleStatus err = aci_gatt_update_char_value(
Vincent Coubard 266:b49e28134d83 753 g_gap_service_handle,
Vincent Coubard 266:b49e28134d83 754 g_preferred_connection_parameters_char_handle,
Vincent Coubard 266:b49e28134d83 755 /* offset */ 0,
Vincent Coubard 266:b49e28134d83 756 sizeof(parameters_packed),
Vincent Coubard 266:b49e28134d83 757 parameters_packed
Vincent Coubard 266:b49e28134d83 758 );
Vincent Coubard 266:b49e28134d83 759
Vincent Coubard 266:b49e28134d83 760 if (err) {
Vincent Coubard 266:b49e28134d83 761 PRINTF("setPreferredConnectionParams failed (err=0x%x)!!\n\r", err) ;
Vincent Coubard 266:b49e28134d83 762 switch (err) {
Vincent Coubard 266:b49e28134d83 763 case BLE_STATUS_INVALID_HANDLE:
Vincent Coubard 266:b49e28134d83 764 case BLE_STATUS_INVALID_PARAMETER:
Vincent Coubard 266:b49e28134d83 765 return BLE_ERROR_INVALID_PARAM;
Vincent Coubard 266:b49e28134d83 766 case BLE_STATUS_INSUFFICIENT_RESOURCES:
Vincent Coubard 266:b49e28134d83 767 return BLE_ERROR_NO_MEM;
Vincent Coubard 266:b49e28134d83 768 case BLE_STATUS_TIMEOUT:
Vincent Coubard 266:b49e28134d83 769 return BLE_STACK_BUSY;
Vincent Coubard 266:b49e28134d83 770 default:
Vincent Coubard 266:b49e28134d83 771 return BLE_ERROR_UNSPECIFIED;
Vincent Coubard 266:b49e28134d83 772 }
Vincent Coubard 266:b49e28134d83 773 }
Vincent Coubard 266:b49e28134d83 774
Vincent Coubard 266:b49e28134d83 775 return BLE_ERROR_NONE;
Wolfgang Betz 130:770ce14d3d15 776 }
Wolfgang Betz 130:770ce14d3d15 777
Wolfgang Betz 130:770ce14d3d15 778 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 779 /*!
Wolfgang Betz 130:770ce14d3d15 780 @brief updates preferred connection params
Wolfgang Betz 130:770ce14d3d15 781
Wolfgang Betz 130:770ce14d3d15 782 @returns ble_error_t
Wolfgang Betz 130:770ce14d3d15 783
Wolfgang Betz 130:770ce14d3d15 784 @section EXAMPLE
Wolfgang Betz 130:770ce14d3d15 785
Wolfgang Betz 130:770ce14d3d15 786 @code
Wolfgang Betz 130:770ce14d3d15 787
Wolfgang Betz 130:770ce14d3d15 788 @endcode
Wolfgang Betz 130:770ce14d3d15 789 */
Wolfgang Betz 130:770ce14d3d15 790 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 791 ble_error_t BlueNRGGap::updateConnectionParams(Handle_t handle, const ConnectionParams_t *params)
Wolfgang Betz 130:770ce14d3d15 792 {
Vincent Coubard 272:4639da7705e1 793 tBleStatus ret = BLE_STATUS_SUCCESS;
Vincent Coubard 272:4639da7705e1 794
Vincent Coubard 272:4639da7705e1 795 if(gapRole == Gap::CENTRAL) {
Vincent Coubard 272:4639da7705e1 796 ret = aci_gap_start_connection_update(handle,
Vincent Coubard 272:4639da7705e1 797 params->minConnectionInterval,
Vincent Coubard 272:4639da7705e1 798 params->maxConnectionInterval,
Vincent Coubard 272:4639da7705e1 799 params->slaveLatency,
Vincent Coubard 272:4639da7705e1 800 params->connectionSupervisionTimeout,
Vincent Coubard 272:4639da7705e1 801 CONN_L1, CONN_L2);
Vincent Coubard 272:4639da7705e1 802 } else {
Vincent Coubard 272:4639da7705e1 803 ret = aci_l2cap_connection_parameter_update_request(handle,
Vincent Coubard 272:4639da7705e1 804 params->minConnectionInterval,
Vincent Coubard 272:4639da7705e1 805 params->maxConnectionInterval,
Vincent Coubard 272:4639da7705e1 806 params->slaveLatency,
Vincent Coubard 272:4639da7705e1 807 params->connectionSupervisionTimeout);
Vincent Coubard 272:4639da7705e1 808 }
Vincent Coubard 272:4639da7705e1 809
Vincent Coubard 272:4639da7705e1 810 if (BLE_STATUS_SUCCESS != ret){
Vincent Coubard 272:4639da7705e1 811 PRINTF("updateConnectionParams failed (ret=0x%x)!!\n\r", ret) ;
Vincent Coubard 272:4639da7705e1 812 switch (ret) {
Vincent Coubard 272:4639da7705e1 813 case ERR_INVALID_HCI_CMD_PARAMS:
Vincent Coubard 272:4639da7705e1 814 case BLE_STATUS_INVALID_PARAMETER:
Vincent Coubard 272:4639da7705e1 815 return BLE_ERROR_INVALID_PARAM;
Vincent Coubard 272:4639da7705e1 816 case ERR_COMMAND_DISALLOWED:
Vincent Coubard 272:4639da7705e1 817 case BLE_STATUS_NOT_ALLOWED:
Vincent Coubard 272:4639da7705e1 818 return BLE_ERROR_OPERATION_NOT_PERMITTED;
Vincent Coubard 272:4639da7705e1 819 default:
Vincent Coubard 272:4639da7705e1 820 return BLE_ERROR_UNSPECIFIED;
Vincent Coubard 272:4639da7705e1 821 }
Vincent Coubard 272:4639da7705e1 822 }
Andrea Palmieri 142:adf1567d3900 823
Wolfgang Betz 130:770ce14d3d15 824 return BLE_ERROR_NONE;
Wolfgang Betz 130:770ce14d3d15 825 }
Wolfgang Betz 130:770ce14d3d15 826
Wolfgang Betz 130:770ce14d3d15 827 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 828 /*!
Vincent Coubard 255:97adb68decd4 829 @brief Sets the Device Name Characteristic
Wolfgang Betz 130:770ce14d3d15 830
Wolfgang Betz 130:770ce14d3d15 831 @param[in] deviceName
Wolfgang Betz 130:770ce14d3d15 832 pointer to device name to be set
Wolfgang Betz 130:770ce14d3d15 833
Wolfgang Betz 130:770ce14d3d15 834 @returns ble_error_t
Wolfgang Betz 130:770ce14d3d15 835
Wolfgang Betz 130:770ce14d3d15 836 @retval BLE_ERROR_NONE
Wolfgang Betz 130:770ce14d3d15 837 Everything executed properly
Wolfgang Betz 130:770ce14d3d15 838
Wolfgang Betz 130:770ce14d3d15 839 @section EXAMPLE
Wolfgang Betz 130:770ce14d3d15 840
Wolfgang Betz 130:770ce14d3d15 841 @code
Wolfgang Betz 130:770ce14d3d15 842
Wolfgang Betz 130:770ce14d3d15 843 @endcode
Wolfgang Betz 130:770ce14d3d15 844 */
Wolfgang Betz 130:770ce14d3d15 845 /**************************************************************************/
Vincent Coubard 255:97adb68decd4 846 ble_error_t BlueNRGGap::setDeviceName(const uint8_t *deviceName)
Wolfgang Betz 130:770ce14d3d15 847 {
Andrea Palmieri 187:2e517d3ddd71 848 tBleStatus ret;
Vincent Coubard 255:97adb68decd4 849 uint8_t nameLen = 0;
Vincent Coubard 255:97adb68decd4 850
Andrea Palmieri 228:25368f053411 851 nameLen = strlen((const char*)deviceName);
Andrea Palmieri 228:25368f053411 852 PRINTF("DeviceName Size=%d\n\r", nameLen);
Andrea Palmieri 228:25368f053411 853
Andrea Palmieri 222:37a7e289ee3d 854 ret = aci_gatt_update_char_value(g_gap_service_handle,
Andrea Palmieri 222:37a7e289ee3d 855 g_device_name_char_handle,
Andrea Palmieri 222:37a7e289ee3d 856 0,
Andrea Palmieri 222:37a7e289ee3d 857 nameLen,
Andrea Palmieri 228:25368f053411 858 deviceName);
Andrea Palmieri 187:2e517d3ddd71 859
Andrea Palmieri 187:2e517d3ddd71 860 if (BLE_STATUS_SUCCESS != ret){
Andrea Palmieri 187:2e517d3ddd71 861 PRINTF("device set name failed (ret=0x%x)!!\n\r", ret) ;
Andrea Palmieri 187:2e517d3ddd71 862 switch (ret) {
Andrea Palmieri 187:2e517d3ddd71 863 case BLE_STATUS_INVALID_HANDLE:
Andrea Palmieri 187:2e517d3ddd71 864 case BLE_STATUS_INVALID_PARAMETER:
Andrea Palmieri 187:2e517d3ddd71 865 return BLE_ERROR_INVALID_PARAM;
Andrea Palmieri 187:2e517d3ddd71 866 case BLE_STATUS_INSUFFICIENT_RESOURCES:
Andrea Palmieri 187:2e517d3ddd71 867 return BLE_ERROR_NO_MEM;
Andrea Palmieri 187:2e517d3ddd71 868 case BLE_STATUS_TIMEOUT:
Andrea Palmieri 187:2e517d3ddd71 869 return BLE_STACK_BUSY;
Andrea Palmieri 187:2e517d3ddd71 870 default:
Andrea Palmieri 187:2e517d3ddd71 871 return BLE_ERROR_UNSPECIFIED;
Andrea Palmieri 187:2e517d3ddd71 872 }
Wolfgang Betz 130:770ce14d3d15 873 }
Wolfgang Betz 130:770ce14d3d15 874
Wolfgang Betz 130:770ce14d3d15 875 return BLE_ERROR_NONE;
Wolfgang Betz 130:770ce14d3d15 876 }
Wolfgang Betz 130:770ce14d3d15 877
Wolfgang Betz 130:770ce14d3d15 878 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 879 /*!
Vincent Coubard 255:97adb68decd4 880 @brief Gets the Device Name Characteristic
Wolfgang Betz 130:770ce14d3d15 881
Wolfgang Betz 130:770ce14d3d15 882 @param[in] deviceName
Vincent Coubard 255:97adb68decd4 883 pointer to device name
Wolfgang Betz 130:770ce14d3d15 884
Wolfgang Betz 130:770ce14d3d15 885 @param[in] lengthP
Vincent Coubard 255:97adb68decd4 886 pointer to device name length
Wolfgang Betz 130:770ce14d3d15 887
Wolfgang Betz 130:770ce14d3d15 888 @returns ble_error_t
Wolfgang Betz 130:770ce14d3d15 889
Wolfgang Betz 130:770ce14d3d15 890 @retval BLE_ERROR_NONE
Wolfgang Betz 130:770ce14d3d15 891 Everything executed properly
Wolfgang Betz 130:770ce14d3d15 892
Wolfgang Betz 130:770ce14d3d15 893 @section EXAMPLE
Wolfgang Betz 130:770ce14d3d15 894
Wolfgang Betz 130:770ce14d3d15 895 @code
Wolfgang Betz 130:770ce14d3d15 896
Wolfgang Betz 130:770ce14d3d15 897 @endcode
Wolfgang Betz 130:770ce14d3d15 898 */
Wolfgang Betz 130:770ce14d3d15 899 /**************************************************************************/
Andrea Palmieri 228:25368f053411 900 ble_error_t BlueNRGGap::getDeviceName(uint8_t *deviceName, unsigned *lengthP)
Andrea Palmieri 228:25368f053411 901 {
Andrea Palmieri 228:25368f053411 902 tBleStatus ret;
Andrea Palmieri 228:25368f053411 903
Andrea Palmieri 229:9981f62cdb1a 904 ret = aci_gatt_read_handle_value(g_device_name_char_handle+BlueNRGGattServer::CHAR_VALUE_HANDLE,
Andrea Palmieri 228:25368f053411 905 *lengthP,
Andrea Palmieri 228:25368f053411 906 (uint16_t *)lengthP,
Andrea Palmieri 228:25368f053411 907 deviceName);
Andrea Palmieri 228:25368f053411 908 PRINTF("getDeviceName ret=0x%02x (lengthP=%d)\n\r", ret, *lengthP);
Andrea Palmieri 228:25368f053411 909 if (ret == BLE_STATUS_SUCCESS) {
Andrea Palmieri 228:25368f053411 910 return BLE_ERROR_NONE;
Andrea Palmieri 228:25368f053411 911 } else {
Andrea Palmieri 228:25368f053411 912 return BLE_ERROR_PARAM_OUT_OF_RANGE;
Andrea Palmieri 228:25368f053411 913 }
Wolfgang Betz 130:770ce14d3d15 914 }
Wolfgang Betz 130:770ce14d3d15 915
Wolfgang Betz 130:770ce14d3d15 916 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 917 /*!
Vincent Coubard 255:97adb68decd4 918 @brief Sets the Device Appearance Characteristic
Wolfgang Betz 130:770ce14d3d15 919
Wolfgang Betz 130:770ce14d3d15 920 @param[in] appearance
Vincent Coubard 255:97adb68decd4 921 device appearance
Wolfgang Betz 130:770ce14d3d15 922
Wolfgang Betz 130:770ce14d3d15 923 @returns ble_error_t
Wolfgang Betz 130:770ce14d3d15 924
Wolfgang Betz 130:770ce14d3d15 925 @retval BLE_ERROR_NONE
Wolfgang Betz 130:770ce14d3d15 926 Everything executed properly
Wolfgang Betz 130:770ce14d3d15 927
Wolfgang Betz 130:770ce14d3d15 928 @section EXAMPLE
Wolfgang Betz 130:770ce14d3d15 929
Wolfgang Betz 130:770ce14d3d15 930 @code
Wolfgang Betz 130:770ce14d3d15 931
Wolfgang Betz 130:770ce14d3d15 932 @endcode
Wolfgang Betz 130:770ce14d3d15 933 */
Wolfgang Betz 130:770ce14d3d15 934 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 935 ble_error_t BlueNRGGap::setAppearance(GapAdvertisingData::Appearance appearance)
Wolfgang Betz 130:770ce14d3d15 936 {
Andrea Palmieri 187:2e517d3ddd71 937 tBleStatus ret;
Andrea Palmieri 228:25368f053411 938 uint8_t deviceAppearance[2];
Andrea Palmieri 187:2e517d3ddd71 939
Vincent Coubard 255:97adb68decd4 940 STORE_LE_16(deviceAppearance, appearance);
Vincent Coubard 253:9665a6f8bbdb 941 PRINTF("setAppearance= 0x%x 0x%x\n\r", deviceAppearance[1], deviceAppearance[0]);
Vincent Coubard 255:97adb68decd4 942
Andrea Palmieri 228:25368f053411 943 ret = aci_gatt_update_char_value(g_gap_service_handle,
Andrea Palmieri 228:25368f053411 944 g_appearance_char_handle,
Andrea Palmieri 228:25368f053411 945 0, 2, (uint8_t *)deviceAppearance);
Andrea Palmieri 187:2e517d3ddd71 946 if (BLE_STATUS_SUCCESS == ret){
Andrea Palmieri 187:2e517d3ddd71 947 return BLE_ERROR_NONE;
Andrea Palmieri 187:2e517d3ddd71 948 }
Andrea Palmieri 187:2e517d3ddd71 949
Andrea Palmieri 217:23870c55b07e 950 PRINTF("setAppearance failed (ret=0x%x)!!\n\r", ret);
Andrea Palmieri 187:2e517d3ddd71 951 switch (ret) {
Andrea Palmieri 187:2e517d3ddd71 952 case BLE_STATUS_INVALID_HANDLE:
Andrea Palmieri 187:2e517d3ddd71 953 case BLE_STATUS_INVALID_PARAMETER:
Andrea Palmieri 187:2e517d3ddd71 954 return BLE_ERROR_INVALID_PARAM;
Andrea Palmieri 187:2e517d3ddd71 955 case BLE_STATUS_INSUFFICIENT_RESOURCES:
Andrea Palmieri 187:2e517d3ddd71 956 return BLE_ERROR_NO_MEM;
Andrea Palmieri 187:2e517d3ddd71 957 case BLE_STATUS_TIMEOUT:
Andrea Palmieri 187:2e517d3ddd71 958 return BLE_STACK_BUSY;
Andrea Palmieri 187:2e517d3ddd71 959 default:
Andrea Palmieri 187:2e517d3ddd71 960 return BLE_ERROR_UNSPECIFIED;
Andrea Palmieri 187:2e517d3ddd71 961 }
Wolfgang Betz 130:770ce14d3d15 962 }
Wolfgang Betz 130:770ce14d3d15 963
Wolfgang Betz 130:770ce14d3d15 964 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 965 /*!
Wolfgang Betz 130:770ce14d3d15 966 @brief Gets the Device Appearance Characteristic
Wolfgang Betz 130:770ce14d3d15 967
Wolfgang Betz 130:770ce14d3d15 968 @param[in] appearance
Vincent Coubard 255:97adb68decd4 969 pointer to device appearance value
Wolfgang Betz 130:770ce14d3d15 970
Wolfgang Betz 130:770ce14d3d15 971 @returns ble_error_t
Wolfgang Betz 130:770ce14d3d15 972
Wolfgang Betz 130:770ce14d3d15 973 @retval BLE_ERROR_NONE
Wolfgang Betz 130:770ce14d3d15 974 Everything executed properly
Wolfgang Betz 130:770ce14d3d15 975
Wolfgang Betz 130:770ce14d3d15 976 @section EXAMPLE
Wolfgang Betz 130:770ce14d3d15 977
Wolfgang Betz 130:770ce14d3d15 978 @code
Wolfgang Betz 130:770ce14d3d15 979
Wolfgang Betz 130:770ce14d3d15 980 @endcode
Wolfgang Betz 130:770ce14d3d15 981 */
Wolfgang Betz 130:770ce14d3d15 982 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 983 ble_error_t BlueNRGGap::getAppearance(GapAdvertisingData::Appearance *appearanceP)
Wolfgang Betz 130:770ce14d3d15 984 {
Andrea Palmieri 228:25368f053411 985 tBleStatus ret;
Andrea Palmieri 228:25368f053411 986 uint16_t lengthP = 2;
Andrea Palmieri 228:25368f053411 987
Andrea Palmieri 229:9981f62cdb1a 988 ret = aci_gatt_read_handle_value(g_appearance_char_handle+BlueNRGGattServer::CHAR_VALUE_HANDLE,
Andrea Palmieri 228:25368f053411 989 lengthP,
Andrea Palmieri 228:25368f053411 990 &lengthP,
Andrea Palmieri 228:25368f053411 991 (uint8_t*)appearanceP);
Andrea Palmieri 228:25368f053411 992 PRINTF("getAppearance ret=0x%02x (lengthP=%d)\n\r", ret, lengthP);
Andrea Palmieri 228:25368f053411 993 if (ret == BLE_STATUS_SUCCESS) {
Andrea Palmieri 228:25368f053411 994 return BLE_ERROR_NONE;
Andrea Palmieri 228:25368f053411 995 } else {
Andrea Palmieri 228:25368f053411 996 return BLE_ERROR_PARAM_OUT_OF_RANGE;
Andrea Palmieri 228:25368f053411 997 }
Andrea Palmieri 228:25368f053411 998
Wolfgang Betz 130:770ce14d3d15 999 }
Wolfgang Betz 130:770ce14d3d15 1000
Andrea Palmieri 160:174387d53809 1001 GapScanningParams* BlueNRGGap::getScanningParams(void)
Andrea Palmieri 160:174387d53809 1002 {
Andrea Palmieri 160:174387d53809 1003 return &_scanningParams;
Andrea Palmieri 160:174387d53809 1004 }
Andrea Palmieri 160:174387d53809 1005
Wolfgang Betz 165:3576598c0889 1006 static void makeConnection(void)
Wolfgang Betz 162:667f97a4db7f 1007 {
Wolfgang Betz 165:3576598c0889 1008 BlueNRGGap::getInstance().createConnection();
Wolfgang Betz 162:667f97a4db7f 1009 }
Wolfgang Betz 162:667f97a4db7f 1010
Wolfgang Betz 132:51056160fa4a 1011 void BlueNRGGap::Discovery_CB(Reason_t reason,
Wolfgang Betz 132:51056160fa4a 1012 uint8_t adv_type,
Andrea Palmieri 229:9981f62cdb1a 1013 uint8_t addr_type,
Wolfgang Betz 132:51056160fa4a 1014 uint8_t *addr,
Wolfgang Betz 132:51056160fa4a 1015 uint8_t *data_length,
Wolfgang Betz 132:51056160fa4a 1016 uint8_t *data,
Wolfgang Betz 132:51056160fa4a 1017 uint8_t *RSSI)
Wolfgang Betz 132:51056160fa4a 1018 {
Wolfgang Betz 132:51056160fa4a 1019 switch (reason) {
Wolfgang Betz 132:51056160fa4a 1020 case DEVICE_FOUND:
Wolfgang Betz 132:51056160fa4a 1021 {
Wolfgang Betz 132:51056160fa4a 1022 GapAdvertisingParams::AdvertisingType_t type;
Wolfgang Betz 132:51056160fa4a 1023 bool isScanResponse = false;
Andrea Palmieri 229:9981f62cdb1a 1024
Andrea Palmieri 229:9981f62cdb1a 1025 /*
Andrea Palmieri 229:9981f62cdb1a 1026 * Whitelisting (scan policy):
Andrea Palmieri 229:9981f62cdb1a 1027 * SCAN_POLICY_FILTER_ALL_ADV (ADV packets only from devs in the White List) &&
Andrea Palmieri 229:9981f62cdb1a 1028 * Private Random Address
Andrea Palmieri 229:9981f62cdb1a 1029 * => scan_results = FALSE
Andrea Palmieri 229:9981f62cdb1a 1030 * FIXME: the Security Manager should be implemented
Andrea Palmieri 229:9981f62cdb1a 1031 */
Andrea Palmieri 229:9981f62cdb1a 1032 ScanningPolicyMode_t mode = getScanningPolicyMode();
Andrea Palmieri 229:9981f62cdb1a 1033 PRINTF("mode=%u addr_type=%u\n\r", mode, addr_type);
Andrea Palmieri 229:9981f62cdb1a 1034 if(mode == Gap::SCAN_POLICY_FILTER_ALL_ADV ||
Andrea Palmieri 229:9981f62cdb1a 1035 (addr_type == RESOLVABLE_PRIVATE_ADDR ||
Andrea Palmieri 229:9981f62cdb1a 1036 addr_type == NON_RESOLVABLE_PRIVATE_ADDR)) {
Andrea Palmieri 229:9981f62cdb1a 1037 return;
Andrea Palmieri 229:9981f62cdb1a 1038 }
Andrea Palmieri 229:9981f62cdb1a 1039
Wolfgang Betz 132:51056160fa4a 1040 switch(adv_type) {
Wolfgang Betz 132:51056160fa4a 1041 case ADV_IND:
Wolfgang Betz 132:51056160fa4a 1042 type = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED;
Wolfgang Betz 132:51056160fa4a 1043 break;
Wolfgang Betz 132:51056160fa4a 1044 case ADV_DIRECT_IND:
Wolfgang Betz 132:51056160fa4a 1045 type = GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED;
Wolfgang Betz 132:51056160fa4a 1046 break;
Wolfgang Betz 132:51056160fa4a 1047 case ADV_SCAN_IND:
Wolfgang Betz 132:51056160fa4a 1048 case SCAN_RSP:
Wolfgang Betz 132:51056160fa4a 1049 type = GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED;
Wolfgang Betz 132:51056160fa4a 1050 isScanResponse = true;
Wolfgang Betz 132:51056160fa4a 1051 break;
Wolfgang Betz 132:51056160fa4a 1052 case ADV_NONCONN_IND:
Wolfgang Betz 132:51056160fa4a 1053 type = GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED;
Andrea Palmieri 142:adf1567d3900 1054 break;
Andrea Palmieri 142:adf1567d3900 1055 default:
Andrea Palmieri 142:adf1567d3900 1056 type = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED;
Wolfgang Betz 132:51056160fa4a 1057 }
Vincent Coubard 255:97adb68decd4 1058
Andrea Palmieri 217:23870c55b07e 1059 PRINTF("data_length=%d adv peerAddr[%02x %02x %02x %02x %02x %02x] \r\n",
Andrea Palmieri 217:23870c55b07e 1060 *data_length, addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
Andrea Palmieri 238:b6454c839f42 1061 if(!_connecting) {
Andrea Palmieri 238:b6454c839f42 1062 processAdvertisementReport(addr, *RSSI, isScanResponse, type, *data_length, data);
Andrea Palmieri 238:b6454c839f42 1063 }
Andrea Palmieri 160:174387d53809 1064 PRINTF("!!!After processAdvertisementReport\n\r");
Wolfgang Betz 132:51056160fa4a 1065 }
Wolfgang Betz 132:51056160fa4a 1066 break;
Vincent Coubard 255:97adb68decd4 1067
Wolfgang Betz 132:51056160fa4a 1068 case DISCOVERY_COMPLETE:
Wolfgang Betz 132:51056160fa4a 1069 // The discovery is complete. If this is due to a stop scanning (i.e., the device
Wolfgang Betz 132:51056160fa4a 1070 // we are interested in has been found) and a connection has been requested
Andrea Palmieri 229:9981f62cdb1a 1071 // then we start the device connection.
Andrea Palmieri 145:024a552e4715 1072 PRINTF("DISCOVERY_COMPLETE\n\r");
Wolfgang Betz 132:51056160fa4a 1073 _scanning = false;
Wolfgang Betz 132:51056160fa4a 1074
Wolfgang Betz 165:3576598c0889 1075 // Since the DISCOVERY_COMPLETE event can be received during the scanning interval,
Andrea Palmieri 229:9981f62cdb1a 1076 // we need to delay the starting of connection
Wolfgang Betz 165:3576598c0889 1077 uint16_t delay = 2*(_scanningParams.getInterval());
Wolfgang Betz 165:3576598c0889 1078
Andrea Palmieri 217:23870c55b07e 1079 #ifdef AST_FOR_MBED_OS
Wolfgang Betz 162:667f97a4db7f 1080 if(_connecting) {
Wolfgang Betz 165:3576598c0889 1081 minar::Scheduler::postCallback(makeConnection).delay(minar::milliseconds(delay));
Wolfgang Betz 132:51056160fa4a 1082 }
Andrea Palmieri 217:23870c55b07e 1083 #else
Andrea Palmieri 217:23870c55b07e 1084 Clock_Wait(delay);
Andrea Palmieri 217:23870c55b07e 1085 if(_connecting) {
Andrea Palmieri 217:23870c55b07e 1086 makeConnection();
Andrea Palmieri 217:23870c55b07e 1087 }
Andrea Palmieri 217:23870c55b07e 1088 #endif /* AST_FOR_MBED_OS */
Wolfgang Betz 132:51056160fa4a 1089
Wolfgang Betz 132:51056160fa4a 1090 break;
Wolfgang Betz 132:51056160fa4a 1091 }
Wolfgang Betz 132:51056160fa4a 1092 }
Wolfgang Betz 132:51056160fa4a 1093
Wolfgang Betz 132:51056160fa4a 1094 ble_error_t BlueNRGGap::startRadioScan(const GapScanningParams &scanningParams)
Wolfgang Betz 132:51056160fa4a 1095 {
Vincent Coubard 255:97adb68decd4 1096
Wolfgang Betz 165:3576598c0889 1097 tBleStatus ret = BLE_STATUS_SUCCESS;
Andrea Palmieri 222:37a7e289ee3d 1098
Andrea Palmieri 222:37a7e289ee3d 1099 // Stop ADV before scanning
Andrea Palmieri 223:36df860f7ffc 1100 /*
Andrea Palmieri 222:37a7e289ee3d 1101 if (state.advertising == 1) {
Andrea Palmieri 222:37a7e289ee3d 1102 stopAdvertising();
Andrea Palmieri 222:37a7e289ee3d 1103 }
Andrea Palmieri 223:36df860f7ffc 1104 */
Andrea Palmieri 222:37a7e289ee3d 1105
Andrea Palmieri 229:9981f62cdb1a 1106 /*
Andrea Palmieri 229:9981f62cdb1a 1107 * Whitelisting (scan policy):
Andrea Palmieri 229:9981f62cdb1a 1108 * SCAN_POLICY_FILTER_ALL_ADV (ADV packets only from devs in the White List) &&
Andrea Palmieri 229:9981f62cdb1a 1109 * White List is empty
Andrea Palmieri 229:9981f62cdb1a 1110 * => scan operation = FAILURE
Andrea Palmieri 229:9981f62cdb1a 1111 * FIXME: the Security Manager should be implemented
Andrea Palmieri 229:9981f62cdb1a 1112 */
Andrea Palmieri 229:9981f62cdb1a 1113 ScanningPolicyMode_t mode = getScanningPolicyMode();
Andrea Palmieri 229:9981f62cdb1a 1114 uint8_t whiteListSize = whitelistAddresses.size;
Andrea Palmieri 229:9981f62cdb1a 1115 if(whiteListSize == 0 && mode == Gap::SCAN_POLICY_FILTER_ALL_ADV) {
Andrea Palmieri 229:9981f62cdb1a 1116 return BLE_ERROR_OPERATION_NOT_PERMITTED;
Andrea Palmieri 229:9981f62cdb1a 1117 }
Andrea Palmieri 229:9981f62cdb1a 1118
Andrea Palmieri 217:23870c55b07e 1119 ret = btleStartRadioScan(scanningParams.getActiveScanning(),
Andrea Palmieri 217:23870c55b07e 1120 scanningParams.getInterval(),
Andrea Palmieri 217:23870c55b07e 1121 scanningParams.getWindow(),
Andrea Palmieri 217:23870c55b07e 1122 addr_type);
Andrea Palmieri 217:23870c55b07e 1123
Andrea Palmieri 229:9981f62cdb1a 1124 PRINTF("Scanning...\n\r");
Andrea Palmieri 229:9981f62cdb1a 1125 PRINTF("scanningParams.getInterval()=%u[msec]\r\n",(scanningParams.getInterval()*625)/1000);
Andrea Palmieri 229:9981f62cdb1a 1126 PRINTF("scanningParams.getWindow()=%u[msec]\r\n",(scanningParams.getWindow()*625)/1000);
Andrea Palmieri 229:9981f62cdb1a 1127 //PRINTF("_advParams.getInterval()=%u\r\n",_advParams.getInterval());
Andrea Palmieri 229:9981f62cdb1a 1128 //PRINTF("CONN_P1=%u\r\n",(unsigned)CONN_P1);
Andrea Palmieri 229:9981f62cdb1a 1129 //PRINTF("CONN_P2=%u\r\n",(unsigned)CONN_P2);
Andrea Palmieri 217:23870c55b07e 1130 if (BLE_STATUS_SUCCESS == ret){
Andrea Palmieri 217:23870c55b07e 1131 PRINTF("Observation Procedure Started\n");
Andrea Palmieri 217:23870c55b07e 1132 _scanning = true;
Andrea Palmieri 217:23870c55b07e 1133 return BLE_ERROR_NONE;
Andrea Palmieri 145:024a552e4715 1134 }
Andrea Palmieri 217:23870c55b07e 1135
Andrea Palmieri 217:23870c55b07e 1136 // Observer role is not supported by X-NUCLEO-IDB04A1, return BLE_ERROR_NOT_IMPLEMENTED
Andrea Palmieri 217:23870c55b07e 1137 switch (ret) {
Andrea Palmieri 217:23870c55b07e 1138 case BLE_STATUS_INVALID_CID:
Andrea Palmieri 229:9981f62cdb1a 1139 PRINTF("Observation Procedure not implemented!!!\n\r");
Andrea Palmieri 217:23870c55b07e 1140 return BLE_ERROR_NOT_IMPLEMENTED;
Andrea Palmieri 217:23870c55b07e 1141 default:
Andrea Palmieri 229:9981f62cdb1a 1142 PRINTF("Observation Procedure failed (0x%02X)\n\r", ret);
Andrea Palmieri 217:23870c55b07e 1143 return BLE_ERROR_UNSPECIFIED;
Wolfgang Betz 132:51056160fa4a 1144 }
Andrea Palmieri 217:23870c55b07e 1145
Wolfgang Betz 130:770ce14d3d15 1146 }
Wolfgang Betz 130:770ce14d3d15 1147
Wolfgang Betz 130:770ce14d3d15 1148 ble_error_t BlueNRGGap::stopScan() {
Wolfgang Betz 165:3576598c0889 1149 tBleStatus ret = BLE_STATUS_SUCCESS;
Andrea Palmieri 229:9981f62cdb1a 1150
Andrea Palmieri 229:9981f62cdb1a 1151 PRINTF("stopScan\n\r");
Andrea Palmieri 217:23870c55b07e 1152 ret = aci_gap_terminate_gap_procedure(GAP_OBSERVATION_PROC);
Vincent Coubard 255:97adb68decd4 1153
Wolfgang Betz 132:51056160fa4a 1154 if (ret != BLE_STATUS_SUCCESS) {
Andrea Palmieri 238:b6454c839f42 1155 PRINTF("GAP Terminate Gap Procedure failed(ret=0x%x)\n", ret);
Vincent Coubard 255:97adb68decd4 1156 return BLE_ERROR_UNSPECIFIED;
Wolfgang Betz 132:51056160fa4a 1157 } else {
Wolfgang Betz 132:51056160fa4a 1158 PRINTF("Discovery Procedure Terminated\n");
Vincent Coubard 255:97adb68decd4 1159 return BLE_ERROR_NONE;
Wolfgang Betz 132:51056160fa4a 1160 }
Wolfgang Betz 130:770ce14d3d15 1161 }
Wolfgang Betz 130:770ce14d3d15 1162
Wolfgang Betz 130:770ce14d3d15 1163 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 1164 /*!
Wolfgang Betz 130:770ce14d3d15 1165 @brief set Tx power level
Wolfgang Betz 130:770ce14d3d15 1166 @param[in] txPower Transmission Power level
Wolfgang Betz 130:770ce14d3d15 1167 @returns ble_error_t
Wolfgang Betz 130:770ce14d3d15 1168 */
Wolfgang Betz 130:770ce14d3d15 1169 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 1170 ble_error_t BlueNRGGap::setTxPower(int8_t txPower)
Wolfgang Betz 130:770ce14d3d15 1171 {
Wolfgang Betz 130:770ce14d3d15 1172 tBleStatus ret;
Vincent Coubard 255:97adb68decd4 1173
Wolfgang Betz 130:770ce14d3d15 1174 int8_t enHighPower = 0;
Andrea Palmieri 201:a9bc2e8b01d7 1175 int8_t paLevel = 0;
Andrea Palmieri 201:a9bc2e8b01d7 1176
Andrea Palmieri 228:25368f053411 1177 ret = getHighPowerAndPALevelValue(txPower, enHighPower, paLevel);
Andrea Palmieri 228:25368f053411 1178 if(ret!=BLE_STATUS_SUCCESS) {
Andrea Palmieri 228:25368f053411 1179 return BLE_ERROR_PARAM_OUT_OF_RANGE;
Andrea Palmieri 228:25368f053411 1180 }
Andrea Palmieri 201:a9bc2e8b01d7 1181
Vincent Coubard 255:97adb68decd4 1182 PRINTF("enHighPower=%d, paLevel=%d\n\r", enHighPower, paLevel);
Wolfgang Betz 130:770ce14d3d15 1183 ret = aci_hal_set_tx_power_level(enHighPower, paLevel);
Wolfgang Betz 130:770ce14d3d15 1184 if(ret!=BLE_STATUS_SUCCESS) {
Andrea Palmieri 228:25368f053411 1185 return BLE_ERROR_PARAM_OUT_OF_RANGE;
Wolfgang Betz 130:770ce14d3d15 1186 }
Andrea Palmieri 201:a9bc2e8b01d7 1187
Wolfgang Betz 130:770ce14d3d15 1188 return BLE_ERROR_NONE;
Wolfgang Betz 130:770ce14d3d15 1189 }
Wolfgang Betz 130:770ce14d3d15 1190
Wolfgang Betz 130:770ce14d3d15 1191 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 1192 /*!
Wolfgang Betz 130:770ce14d3d15 1193 @brief get permitted Tx power values
Wolfgang Betz 130:770ce14d3d15 1194 @param[in] values pointer to pointer to permitted power values
Vincent Coubard 255:97adb68decd4 1195 @param[in] num number of values
Wolfgang Betz 130:770ce14d3d15 1196 */
Wolfgang Betz 130:770ce14d3d15 1197 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 1198 void BlueNRGGap::getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP) {
Wolfgang Betz 130:770ce14d3d15 1199 static const int8_t permittedTxValues[] = {
Andrea Palmieri 229:9981f62cdb1a 1200 -18, -15, -14, -12, -11, -9, -8, -6, -5, -2, 0, 2, 4, 5, 8
Wolfgang Betz 130:770ce14d3d15 1201 };
Wolfgang Betz 130:770ce14d3d15 1202
Wolfgang Betz 130:770ce14d3d15 1203 *valueArrayPP = permittedTxValues;
Wolfgang Betz 130:770ce14d3d15 1204 *countP = sizeof(permittedTxValues) / sizeof(int8_t);
Wolfgang Betz 130:770ce14d3d15 1205 }
Wolfgang Betz 132:51056160fa4a 1206
Andrea Palmieri 229:9981f62cdb1a 1207 /**************************************************************************/
Andrea Palmieri 229:9981f62cdb1a 1208 /*!
Andrea Palmieri 232:aead10288880 1209 @brief Set advertising parameters according to the current state
Andrea Palmieri 232:aead10288880 1210 Parameters value is set taking into account guidelines of the BlueNRG
Andrea Palmieri 232:aead10288880 1211 time slots allocation
Andrea Palmieri 232:aead10288880 1212 */
Andrea Palmieri 232:aead10288880 1213 /**************************************************************************/
Andrea Palmieri 232:aead10288880 1214 void BlueNRGGap::setAdvParameters(void)
Andrea Palmieri 232:aead10288880 1215 {
Andrea Palmieri 232:aead10288880 1216 uint32_t advIntMS;
Andrea Palmieri 232:aead10288880 1217
Andrea Palmieri 232:aead10288880 1218 if(state.connected == 1) {
Andrea Palmieri 232:aead10288880 1219 advIntMS = (conn_min_interval*1.25)-GUARD_INT;
Andrea Palmieri 232:aead10288880 1220 advInterval = _advParams.MSEC_TO_ADVERTISEMENT_DURATION_UNITS(advIntMS);
Vincent Coubard 256:146bb175ce80 1221
Vincent Coubard 259:323f588e5f57 1222 PRINTF("conn_min_interval is equal to %u\r\n", conn_min_interval);
Andrea Palmieri 232:aead10288880 1223 } else {
Andrea Palmieri 232:aead10288880 1224 advInterval = _advParams.getIntervalInADVUnits();
Andrea Palmieri 232:aead10288880 1225 }
Andrea Palmieri 232:aead10288880 1226 }
Andrea Palmieri 232:aead10288880 1227
Andrea Palmieri 232:aead10288880 1228 /**************************************************************************/
Andrea Palmieri 232:aead10288880 1229 /*!
Andrea Palmieri 229:9981f62cdb1a 1230 @brief Set connection parameters according to the current state (ADV and/or SCAN)
Andrea Palmieri 229:9981f62cdb1a 1231 Parameters value is set taking into account guidelines of the BlueNRG
Andrea Palmieri 229:9981f62cdb1a 1232 time slots allocation
Andrea Palmieri 229:9981f62cdb1a 1233 */
Andrea Palmieri 229:9981f62cdb1a 1234 /**************************************************************************/
Andrea Palmieri 229:9981f62cdb1a 1235 void BlueNRGGap::setConnectionParameters(void)
Andrea Palmieri 229:9981f62cdb1a 1236 {
Andrea Palmieri 229:9981f62cdb1a 1237 if (state.advertising == 1) {
Andrea Palmieri 229:9981f62cdb1a 1238
Andrea Palmieri 232:aead10288880 1239 if (_scanningParams.getInterval() < advInterval) {
Andrea Palmieri 232:aead10288880 1240 PRINTF("state.adv=1 scanInterval<advInterval\r\n");
Andrea Palmieri 232:aead10288880 1241 scanInterval = advInterval;
Andrea Palmieri 232:aead10288880 1242 scanWindow = advInterval;
Andrea Palmieri 229:9981f62cdb1a 1243 } else {
Andrea Palmieri 232:aead10288880 1244 PRINTF("state.adv=1 scanInterval>=advInterval\r\n");
Andrea Palmieri 229:9981f62cdb1a 1245 scanInterval = _scanningParams.getInterval();
Andrea Palmieri 229:9981f62cdb1a 1246 scanWindow = _scanningParams.getWindow();
Andrea Palmieri 229:9981f62cdb1a 1247 }
Andrea Palmieri 234:3f6bba52b307 1248
Andrea Palmieri 234:3f6bba52b307 1249 if(advInterval>(MAX_INT_CONN-(GUARD_INT/1.25))) { //(4000-GUARD_INT)ms
Andrea Palmieri 234:3f6bba52b307 1250 conn_min_interval = MAX_INT_CONN;
Andrea Palmieri 234:3f6bba52b307 1251 conn_max_interval = MAX_INT_CONN;
Andrea Palmieri 234:3f6bba52b307 1252 } else {
Andrea Palmieri 234:3f6bba52b307 1253 conn_min_interval = (_advParams.ADVERTISEMENT_DURATION_UNITS_TO_MS(advInterval)+GUARD_INT)/1.25;
Andrea Palmieri 234:3f6bba52b307 1254 conn_max_interval = (_advParams.ADVERTISEMENT_DURATION_UNITS_TO_MS(advInterval)+GUARD_INT)/1.25;
Andrea Palmieri 234:3f6bba52b307 1255 }
Andrea Palmieri 229:9981f62cdb1a 1256
Andrea Palmieri 229:9981f62cdb1a 1257 } else {
Andrea Palmieri 229:9981f62cdb1a 1258
Andrea Palmieri 232:aead10288880 1259 PRINTF("state.adv = 0\r\n");
Andrea Palmieri 232:aead10288880 1260
Andrea Palmieri 229:9981f62cdb1a 1261 scanInterval = _scanningParams.getInterval();
Andrea Palmieri 229:9981f62cdb1a 1262 scanWindow = _scanningParams.getWindow();
Andrea Palmieri 234:3f6bba52b307 1263 if(SCAN_DURATION_UNITS_TO_MSEC(scanInterval)>(MAX_INT_CONN*1.25) ||
Andrea Palmieri 234:3f6bba52b307 1264 SCAN_DURATION_UNITS_TO_MSEC(scanInterval)<(MIN_INT_CONN*1.25)) { //(4000)ms || (7.5)ms
Andrea Palmieri 234:3f6bba52b307 1265 conn_min_interval = DEF_INT_CONN;
Andrea Palmieri 234:3f6bba52b307 1266 conn_max_interval = DEF_INT_CONN;
Andrea Palmieri 234:3f6bba52b307 1267 } else {
Andrea Palmieri 234:3f6bba52b307 1268 conn_min_interval = SCAN_DURATION_UNITS_TO_MSEC(scanInterval)/1.25;
Andrea Palmieri 234:3f6bba52b307 1269 conn_max_interval = SCAN_DURATION_UNITS_TO_MSEC(scanInterval)/1.25;
Andrea Palmieri 234:3f6bba52b307 1270 }
Andrea Palmieri 229:9981f62cdb1a 1271 }
Andrea Palmieri 229:9981f62cdb1a 1272 PRINTF("scanInterval=%u[msec]\r\n",SCAN_DURATION_UNITS_TO_MSEC(scanInterval));
Andrea Palmieri 229:9981f62cdb1a 1273 PRINTF("scanWindow()=%u[msec]\r\n",SCAN_DURATION_UNITS_TO_MSEC(scanWindow));
Andrea Palmieri 234:3f6bba52b307 1274 PRINTF("conn_min_interval=%u[msec]\r\n",(unsigned)(conn_min_interval*1.25));
Andrea Palmieri 234:3f6bba52b307 1275 PRINTF("conn_max_interval=%u[msec]\r\n",(unsigned)(conn_max_interval*1.25));
Andrea Palmieri 229:9981f62cdb1a 1276
Andrea Palmieri 229:9981f62cdb1a 1277 }
Andrea Palmieri 229:9981f62cdb1a 1278
Andrea Palmieri 181:749071129d2e 1279 ble_error_t BlueNRGGap::createConnection ()
Wolfgang Betz 132:51056160fa4a 1280 {
Wolfgang Betz 132:51056160fa4a 1281 tBleStatus ret;
Andrea Palmieri 229:9981f62cdb1a 1282
Andrea Palmieri 229:9981f62cdb1a 1283 /*
Andrea Palmieri 229:9981f62cdb1a 1284 Before creating connection, set parameters according
Andrea Palmieri 229:9981f62cdb1a 1285 to previous or current procedure (ADV and/or SCAN)
Andrea Palmieri 229:9981f62cdb1a 1286 */
Andrea Palmieri 229:9981f62cdb1a 1287 setConnectionParameters();
Andrea Palmieri 229:9981f62cdb1a 1288
Wolfgang Betz 132:51056160fa4a 1289 /*
Vincent Coubard 255:97adb68decd4 1290 Scan_Interval, Scan_Window, Peer_Address_Type, Peer_Address, Own_Address_Type, Conn_Interval_Min,
Vincent Coubard 255:97adb68decd4 1291 Conn_Interval_Max, Conn_Latency, Supervision_Timeout, Conn_Len_Min, Conn_Len_Max
Wolfgang Betz 132:51056160fa4a 1292 */
Andrea Palmieri 229:9981f62cdb1a 1293 ret = aci_gap_create_connection(scanInterval,
Andrea Palmieri 229:9981f62cdb1a 1294 scanWindow,
Andrea Palmieri 229:9981f62cdb1a 1295 _peerAddrType,
Wolfgang Betz 163:4c008b1089e9 1296 (unsigned char*)_peerAddr,
Andrea Palmieri 229:9981f62cdb1a 1297 addr_type,
Andrea Palmieri 229:9981f62cdb1a 1298 conn_min_interval, conn_max_interval, 0,
Andrea Palmieri 238:b6454c839f42 1299 SUPERV_TIMEOUT, CONN_L1, CONN_L1);
Wolfgang Betz 165:3576598c0889 1300
Andrea Palmieri 238:b6454c839f42 1301 //_connecting = false;
Vincent Coubard 255:97adb68decd4 1302
Wolfgang Betz 163:4c008b1089e9 1303 if (ret != BLE_STATUS_SUCCESS) {
Andrea Palmieri 229:9981f62cdb1a 1304 PRINTF("Error while starting connection (ret=0x%02X).\n\r", ret);
Wolfgang Betz 132:51056160fa4a 1305 return BLE_ERROR_UNSPECIFIED;
Wolfgang Betz 132:51056160fa4a 1306 } else {
Wolfgang Betz 132:51056160fa4a 1307 PRINTF("Connection started.\n");
Andrea Palmieri 238:b6454c839f42 1308 _connecting = false;
Wolfgang Betz 132:51056160fa4a 1309 return BLE_ERROR_NONE;
Wolfgang Betz 132:51056160fa4a 1310 }
Wolfgang Betz 132:51056160fa4a 1311 }
Wolfgang Betz 132:51056160fa4a 1312
Wolfgang Betz 132:51056160fa4a 1313 ble_error_t BlueNRGGap::connect (const Gap::Address_t peerAddr,
Wolfgang Betz 132:51056160fa4a 1314 Gap::AddressType_t peerAddrType,
Wolfgang Betz 132:51056160fa4a 1315 const ConnectionParams_t *connectionParams,
Wolfgang Betz 132:51056160fa4a 1316 const GapScanningParams *scanParams)
Wolfgang Betz 132:51056160fa4a 1317 {
Andrea Palmieri 142:adf1567d3900 1318 /* avoid compiler warnings about unused variables */
Andrea Palmieri 142:adf1567d3900 1319 (void)connectionParams;
Vincent Coubard 272:4639da7705e1 1320
Vincent Coubard 272:4639da7705e1 1321 setScanParams(scanParams->getInterval(),
Vincent Coubard 272:4639da7705e1 1322 scanParams->getWindow(),
Vincent Coubard 272:4639da7705e1 1323 scanParams->getTimeout(),
Vincent Coubard 272:4639da7705e1 1324 scanParams->getActiveScanning()
Vincent Coubard 272:4639da7705e1 1325 );
Andrea Palmieri 142:adf1567d3900 1326
Andrea Palmieri 217:23870c55b07e 1327 // Save the peer address
Wolfgang Betz 132:51056160fa4a 1328 for(int i=0; i<BDADDR_SIZE; i++) {
Wolfgang Betz 132:51056160fa4a 1329 _peerAddr[i] = peerAddr[i];
Wolfgang Betz 132:51056160fa4a 1330 }
Andrea Palmieri 229:9981f62cdb1a 1331 _peerAddrType = peerAddrType;
Wolfgang Betz 132:51056160fa4a 1332
Andrea Palmieri 181:749071129d2e 1333 _connecting = true;
Wolfgang Betz 132:51056160fa4a 1334
Wolfgang Betz 132:51056160fa4a 1335 if(_scanning) {
Wolfgang Betz 132:51056160fa4a 1336 stopScan();
Wolfgang Betz 132:51056160fa4a 1337 } else {
Wolfgang Betz 165:3576598c0889 1338 PRINTF("Calling createConnection from connect()\n\r");
Wolfgang Betz 165:3576598c0889 1339 return createConnection();
Wolfgang Betz 132:51056160fa4a 1340 }
Vincent Coubard 255:97adb68decd4 1341
Wolfgang Betz 132:51056160fa4a 1342 return BLE_ERROR_NONE;
Wolfgang Betz 132:51056160fa4a 1343 }
Andrea Palmieri 229:9981f62cdb1a 1344
Andrea Palmieri 229:9981f62cdb1a 1345 /**************************************************************************/
Andrea Palmieri 229:9981f62cdb1a 1346 /*!
Andrea Palmieri 229:9981f62cdb1a 1347 @brief Set the advertising policy filter mode that will be used in
Andrea Palmieri 229:9981f62cdb1a 1348 the next call to startAdvertising().
Andrea Palmieri 229:9981f62cdb1a 1349
Andrea Palmieri 229:9981f62cdb1a 1350 @returns \ref ble_errror_t
Andrea Palmieri 229:9981f62cdb1a 1351
Andrea Palmieri 229:9981f62cdb1a 1352 @retval BLE_ERROR_NONE
Andrea Palmieri 229:9981f62cdb1a 1353 Everything executed properly.
Andrea Palmieri 229:9981f62cdb1a 1354
Andrea Palmieri 229:9981f62cdb1a 1355 BLE_ERROR_NOT_IMPLEMENTED
Andrea Palmieri 229:9981f62cdb1a 1356 This feature is currently note implemented.
Andrea Palmieri 229:9981f62cdb1a 1357 */
Andrea Palmieri 229:9981f62cdb1a 1358 /**************************************************************************/
Andrea Palmieri 229:9981f62cdb1a 1359 ble_error_t BlueNRGGap::setAdvertisingPolicyMode(Gap::AdvertisingPolicyMode_t mode)
Andrea Palmieri 229:9981f62cdb1a 1360 {
Andrea Palmieri 229:9981f62cdb1a 1361 advertisingPolicyMode = mode;
Andrea Palmieri 229:9981f62cdb1a 1362
Andrea Palmieri 229:9981f62cdb1a 1363 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 1364 }
Andrea Palmieri 229:9981f62cdb1a 1365
Andrea Palmieri 229:9981f62cdb1a 1366 /**************************************************************************/
Andrea Palmieri 229:9981f62cdb1a 1367 /*!
Andrea Palmieri 229:9981f62cdb1a 1368 @brief Set the scanning policy filter mode that will be used in
Andrea Palmieri 229:9981f62cdb1a 1369 the next call to startAdvertising().
Andrea Palmieri 229:9981f62cdb1a 1370
Andrea Palmieri 229:9981f62cdb1a 1371 @returns \ref ble_errror_t
Andrea Palmieri 229:9981f62cdb1a 1372
Andrea Palmieri 229:9981f62cdb1a 1373 @retval BLE_ERROR_NONE
Andrea Palmieri 229:9981f62cdb1a 1374 Everything executed properly.
Andrea Palmieri 229:9981f62cdb1a 1375
Andrea Palmieri 229:9981f62cdb1a 1376 BLE_ERROR_NOT_IMPLEMENTED
Andrea Palmieri 229:9981f62cdb1a 1377 This feature is currently note implemented.
Andrea Palmieri 229:9981f62cdb1a 1378 */
Andrea Palmieri 229:9981f62cdb1a 1379 /**************************************************************************/
Andrea Palmieri 229:9981f62cdb1a 1380 ble_error_t BlueNRGGap::setScanningPolicyMode(Gap::ScanningPolicyMode_t mode)
Andrea Palmieri 229:9981f62cdb1a 1381 {
Andrea Palmieri 229:9981f62cdb1a 1382 scanningPolicyMode = mode;
Andrea Palmieri 229:9981f62cdb1a 1383
Andrea Palmieri 229:9981f62cdb1a 1384 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 1385 }
Andrea Palmieri 229:9981f62cdb1a 1386
Andrea Palmieri 229:9981f62cdb1a 1387 /**************************************************************************/
Andrea Palmieri 229:9981f62cdb1a 1388 /*!
Andrea Palmieri 229:9981f62cdb1a 1389 @brief Get the current advertising policy filter mode.
Andrea Palmieri 229:9981f62cdb1a 1390
Andrea Palmieri 229:9981f62cdb1a 1391 @returns The advertising policy filter mode.
Andrea Palmieri 229:9981f62cdb1a 1392 */
Andrea Palmieri 229:9981f62cdb1a 1393 /**************************************************************************/
Andrea Palmieri 229:9981f62cdb1a 1394 Gap::AdvertisingPolicyMode_t BlueNRGGap::getAdvertisingPolicyMode(void) const
Andrea Palmieri 229:9981f62cdb1a 1395 {
Andrea Palmieri 229:9981f62cdb1a 1396 return advertisingPolicyMode;
Andrea Palmieri 229:9981f62cdb1a 1397 }
Andrea Palmieri 229:9981f62cdb1a 1398
Andrea Palmieri 229:9981f62cdb1a 1399 /**************************************************************************/
Andrea Palmieri 229:9981f62cdb1a 1400 /*!
Andrea Palmieri 229:9981f62cdb1a 1401 @brief Get the current scanning policy filter mode.
Andrea Palmieri 229:9981f62cdb1a 1402
Andrea Palmieri 229:9981f62cdb1a 1403 @returns The scanning policy filter mode.
Andrea Palmieri 229:9981f62cdb1a 1404
Andrea Palmieri 229:9981f62cdb1a 1405 */
Andrea Palmieri 229:9981f62cdb1a 1406 /**************************************************************************/
Andrea Palmieri 229:9981f62cdb1a 1407 Gap::ScanningPolicyMode_t BlueNRGGap::getScanningPolicyMode(void) const
Andrea Palmieri 229:9981f62cdb1a 1408 {
Andrea Palmieri 229:9981f62cdb1a 1409 return scanningPolicyMode;
Andrea Palmieri 229:9981f62cdb1a 1410 }
Andrea Palmieri 229:9981f62cdb1a 1411
Andrea Palmieri 229:9981f62cdb1a 1412 /**************************************************************************/
Andrea Palmieri 229:9981f62cdb1a 1413 /*!
Andrea Palmieri 229:9981f62cdb1a 1414 @brief Clear BlueNRGGap's state.
Andrea Palmieri 229:9981f62cdb1a 1415
Andrea Palmieri 229:9981f62cdb1a 1416 @returns ble_error_t
Andrea Palmieri 229:9981f62cdb1a 1417
Andrea Palmieri 229:9981f62cdb1a 1418 @retval BLE_ERROR_NONE
Andrea Palmieri 229:9981f62cdb1a 1419 Everything executed properly
Andrea Palmieri 229:9981f62cdb1a 1420 */
Andrea Palmieri 229:9981f62cdb1a 1421 /**************************************************************************/
Andrea Palmieri 229:9981f62cdb1a 1422 ble_error_t BlueNRGGap::reset(void)
Andrea Palmieri 229:9981f62cdb1a 1423 {
Andrea Palmieri 229:9981f62cdb1a 1424 /* Clear all state that is from the parent, including private members */
Andrea Palmieri 229:9981f62cdb1a 1425 if (Gap::reset() != BLE_ERROR_NONE) {
Andrea Palmieri 229:9981f62cdb1a 1426 return BLE_ERROR_INVALID_STATE;
Andrea Palmieri 229:9981f62cdb1a 1427 }
Andrea Palmieri 229:9981f62cdb1a 1428
Andrea Palmieri 229:9981f62cdb1a 1429 /* Clear derived class members */
Andrea Palmieri 229:9981f62cdb1a 1430 m_connectionHandle = BLE_CONN_HANDLE_INVALID;
Andrea Palmieri 229:9981f62cdb1a 1431
Andrea Palmieri 229:9981f62cdb1a 1432 /* Set the whitelist policy filter modes to IGNORE_WHITELIST */
Andrea Palmieri 229:9981f62cdb1a 1433 advertisingPolicyMode = Gap::ADV_POLICY_IGNORE_WHITELIST;
Andrea Palmieri 229:9981f62cdb1a 1434 scanningPolicyMode = Gap::SCAN_POLICY_IGNORE_WHITELIST;
Andrea Palmieri 229:9981f62cdb1a 1435
Andrea Palmieri 229:9981f62cdb1a 1436 return BLE_ERROR_NONE;
Vincent Coubard 256:146bb175ce80 1437 }
Vincent Coubard 256:146bb175ce80 1438
Vincent Coubard 256:146bb175ce80 1439 void BlueNRGGap::setConnectionInterval(uint16_t interval) {
Vincent Coubard 256:146bb175ce80 1440 conn_min_interval = interval;
Vincent Coubard 256:146bb175ce80 1441 conn_max_interval = interval;
Vincent Coubard 272:4639da7705e1 1442 }
Vincent Coubard 272:4639da7705e1 1443
Vincent Coubard 272:4639da7705e1 1444 void BlueNRGGap::setGapRole(Role_t role)
Vincent Coubard 272:4639da7705e1 1445 {
Vincent Coubard 272:4639da7705e1 1446 gapRole = role;
Vincent Coubard 302:ed6f74ab78f9 1447 }