High level Bluetooth Low Energy API and radio abstraction layer

Dependencies:   nRF51822

Dependents:   LinkNode_LIS3DH

Fork of BLE_API by Bluetooth Low Energy

Files at this revision

API Documentation at this revision

Comitter:
rgrover1
Date:
Fri Jun 19 15:52:07 2015 +0100
Parent:
530:00800f9ffbfb
Child:
532:a709cfc1500d
Commit message:
Synchronized with git rev e74eb3b4
Author: Rohit Grover
moved GAP related members out of BLE and into GAP

Changed in this revision

common/GapScanningParams.cpp Show annotated file Show diff for this revision Revisions of this file
public/BLE.h Show annotated file Show diff for this revision Revisions of this file
public/Gap.h Show annotated file Show diff for this revision Revisions of this file
public/GapAdvertisingData.h Show annotated file Show diff for this revision Revisions of this file
public/GapScanningParams.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/GapScanningParams.cpp	Fri Jun 19 15:52:07 2015 +0100
@@ -0,0 +1,75 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Gap.h"
+#include "GapScanningParams.h"
+
+GapScanningParams::GapScanningParams(uint16_t interval, uint16_t window, uint16_t timeout, bool activeScanning) :
+    _interval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(interval)),
+    _window(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(window)),
+    _timeout(timeout),
+    _activeScanning(activeScanning) {
+    /* stay within limits */
+    if (_interval < SCAN_INTERVAL_MIN) {
+        _interval = SCAN_INTERVAL_MIN;
+    }
+    if (_interval > SCAN_INTERVAL_MAX) {
+        _interval = SCAN_INTERVAL_MAX;
+    }
+    if (_window < SCAN_WINDOW_MIN) {
+        _window = SCAN_WINDOW_MIN;
+    }
+    if (_window > SCAN_WINDOW_MAX) {
+        _window = SCAN_WINDOW_MAX;
+    }
+}
+
+ble_error_t
+GapScanningParams::setInterval(uint16_t newIntervalInMS)
+{
+    uint16_t newInterval = Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(newIntervalInMS);
+    if ((newInterval >= SCAN_INTERVAL_MIN) && (newInterval < SCAN_INTERVAL_MAX)) {
+        _interval = newInterval;
+        return BLE_ERROR_NONE;
+    }
+
+    return BLE_ERROR_PARAM_OUT_OF_RANGE;
+}
+
+ble_error_t
+GapScanningParams::setWindow(uint16_t newWindowInMS)
+{
+    uint16_t newWindow = Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(newWindowInMS);
+    if ((newWindow >= SCAN_WINDOW_MIN) && (newWindow < SCAN_WINDOW_MAX)) {
+        _window   = newWindow;
+        return BLE_ERROR_NONE;
+    }
+
+    return BLE_ERROR_PARAM_OUT_OF_RANGE;
+}
+
+ble_error_t
+GapScanningParams::setTimeout(uint16_t newTimeout)
+{
+    _timeout  = newTimeout;
+    return BLE_ERROR_NONE;
+}
+
+void
+GapScanningParams::setActiveScanning(bool activeScanning)
+{
+    _activeScanning = activeScanning;
+}
\ No newline at end of file
--- a/public/BLE.h	Fri Jun 19 15:52:07 2015 +0100
+++ b/public/BLE.h	Fri Jun 19 15:52:07 2015 +0100
@@ -23,11 +23,6 @@
 #include "GattClient.h"
 #include "BLEInstanceBase.h"
 
-#include "GapAdvertisingData.h"
-#include "GapAdvertisingParams.h"
-#include "GapScanningParams.h"
-
-
 /**
  * The base class used to abstract away BLE capable radio transceivers or SOCs,
  * to enable this BLE API to work with any radio transparently.
@@ -55,6 +50,7 @@
      */
     ble_error_t shutdown(void);
 
+    /* Accessors to GAP. Please refer to Gap.h for GAP related functionality. */
     const Gap &gap() const {
         return transport->getGap();
     }
@@ -62,8 +58,8 @@
         return transport->getGap();
     }
 
+public:
     /* GAP specific APIs */
-public:
     /**
      * Set the BTLE MAC address and type.
      * @return BLE_ERROR_NONE on success.
@@ -719,23 +715,12 @@
     void terminateServiceDiscovery(void);
 
 public:
-    BLE() : transport(createBLEInstance()), advParams(), advPayload(), scanningParams(), scanResponse(), needToSetAdvPayload(true) {
-        advPayload.clear();
-        scanResponse.clear();
+    BLE() : transport(createBLEInstance()) {
+        /* empty */
     }
 
 private:
     BLEInstanceBase *const transport; /* the device specific backend */
-
-    GapAdvertisingParams advParams;
-    GapAdvertisingData   advPayload;
-    GapScanningParams    scanningParams;
-    GapAdvertisingData   scanResponse;
-
-    /* Accumulation of AD structures in the advertisement payload should
-     * eventually result in a call to the target's setAdvertisingData() before
-     * the server begins advertising. This flag marks the status of the pending update.*/
-    bool                 needToSetAdvPayload;
 };
 
 typedef BLE BLEDevice; /* DEPRECATED. This type alias is retained for the sake of compatibilty with older
@@ -753,26 +738,26 @@
 inline ble_error_t
 BLE::shutdown(void)
 {
-    clearAdvertisingPayload();
+    gap().getAdvPayload().clear();
     return transport->shutdown();
 }
 
 inline ble_error_t
 BLE::setAddress(Gap::AddressType_t type, const Gap::Address_t address)
 {
-    return transport->getGap().setAddress(type, address);
+    return gap().setAddress(type, address);
 }
 
 inline ble_error_t
 BLE::getAddress(Gap::AddressType_t *typeP, Gap::Address_t address)
 {
-    return transport->getGap().getAddress(typeP, address);
+    return gap().getAddress(typeP, address);
 }
 
 inline void
 BLE::setAdvertisingType(GapAdvertisingParams::AdvertisingType advType)
 {
-    advParams.setAdvertisingType(advType);
+    gap().getAdvParams().setAdvertisingType(advType);
 }
 
 inline void
@@ -783,112 +768,103 @@
     } else if (interval < getMinAdvertisingInterval()) {
         interval = getMinAdvertisingInterval();
     }
-    advParams.setInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(interval));
+    gap().getAdvParams().setInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(interval));
 }
 
 inline uint16_t
 BLE::getMinAdvertisingInterval(void) const {
-    return transport->getGap().getMinAdvertisingInterval();
+    return gap().getMinAdvertisingInterval();
 }
 
 inline uint16_t
 BLE::getMinNonConnectableAdvertisingInterval(void) const {
-    return transport->getGap().getMinNonConnectableAdvertisingInterval();
+    return gap().getMinNonConnectableAdvertisingInterval();
 }
 
 inline uint16_t
 BLE::getMaxAdvertisingInterval(void) const {
-    return transport->getGap().getMaxAdvertisingInterval();
+    return gap().getMaxAdvertisingInterval();
 }
 
 inline void
 BLE::setAdvertisingTimeout(uint16_t timeout)
 {
-    advParams.setTimeout(timeout);
+    gap().getAdvParams().setTimeout(timeout);
 }
 
 inline void
 BLE::setAdvertisingParams(const GapAdvertisingParams &newAdvParams)
 {
-    advParams = newAdvParams;
+    gap().setAdvParams(newAdvParams);
 }
 
 inline const GapAdvertisingParams &
 BLE::getAdvertisingParams(void) const
 {
-    return advParams;
+    return gap().getAdvParams();
 }
 
 inline void
 BLE::clearAdvertisingPayload(void)
 {
-    needToSetAdvPayload = true;
-    advPayload.clear();
+    gap().getAdvPayload().clear();
 }
 
 inline ble_error_t
 BLE::accumulateAdvertisingPayload(uint8_t flags)
 {
-    needToSetAdvPayload = true;
-    return advPayload.addFlags(flags);
+    return gap().getAdvPayload().addFlags(flags);
 }
 
 inline ble_error_t
 BLE::accumulateAdvertisingPayload(GapAdvertisingData::Appearance app)
 {
-    needToSetAdvPayload = true;
-    transport->getGap().setAppearance(app);
-    return advPayload.addAppearance(app);
+    gap().setAppearance(app);
+    return gap().getAdvPayload().addAppearance(app);
 }
 
 inline ble_error_t
 BLE::accumulateAdvertisingPayloadTxPower(int8_t txPower)
 {
-    needToSetAdvPayload = true;
-    return advPayload.addTxPower(txPower);
+    return gap().getAdvPayload().addTxPower(txPower);
 }
 
 inline ble_error_t
 BLE::accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len)
 {
-    needToSetAdvPayload = true;
     if (type == GapAdvertisingData::COMPLETE_LOCAL_NAME) {
-        transport->getGap().setDeviceName(data);
+        gap().setDeviceName(data);
     }
-    return advPayload.addData(type, data, len);
+    return gap().getAdvPayload().addData(type, data, len);
 }
 
 inline ble_error_t
 BLE::accumulateScanResponse(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len)
 {
-    needToSetAdvPayload = true;
-    return scanResponse.addData(type, data, len);
+    return gap().getScanResponse().addData(type, data, len);
 }
 
 inline void
 BLE::clearScanResponse(void)
 {
-    needToSetAdvPayload = true;
-    scanResponse.clear();
+    gap().getScanResponse().clear();
 }
 
 inline ble_error_t
 BLE::setAdvertisingPayload(void) {
-    needToSetAdvPayload = false;
-    return transport->getGap().setAdvertisingData(advPayload, scanResponse);
+    return gap().setAdvertisingData();
 }
 
 inline ble_error_t
 BLE::setAdvertisingData(const GapAdvertisingData& newPayload)
 {
-    advPayload = newPayload;
-
+    gap().getAdvPayload() = newPayload;
     return setAdvertisingPayload();
 }
 
 inline const GapAdvertisingData &
 BLE::getAdvertisingData(void) const {
-    return advPayload;
+    return gap().getAdvPayload();
 }
 
 inline ble_error_t
@@ -898,28 +874,26 @@
     if ((rc = transport->getGattServer().initializeGATTDatabase()) != BLE_ERROR_NONE) {
         return rc;
     }
-    if (needToSetAdvPayload) {
-        if ((rc = setAdvertisingPayload()) != BLE_ERROR_NONE) {
-            return rc;
-        }
+    if ((rc = setAdvertisingPayload()) != BLE_ERROR_NONE) {
+        return rc;
     }
 
-    return transport->getGap().startAdvertising(advParams);
+    return gap().startAdvertising();
 }
 
 inline ble_error_t
 BLE::stopAdvertising(void)
 {
-    return transport->getGap().stopAdvertising();
+    return gap().stopAdvertising();
 }
 
 inline ble_error_t
 BLE::setScanParams(uint16_t interval, uint16_t window, uint16_t timeout, bool activeScanning) {
     ble_error_t rc;
-    if (((rc = scanningParams.setInterval(interval)) == BLE_ERROR_NONE) &&
-        ((rc = scanningParams.setWindow(window))     == BLE_ERROR_NONE) &&
-        ((rc = scanningParams.setTimeout(timeout))   == BLE_ERROR_NONE)) {
-        scanningParams.setActiveScanning(activeScanning);
+    if (((rc = gap().getScanningParams().setInterval(interval)) == BLE_ERROR_NONE) &&
+        ((rc = gap().getScanningParams().setWindow(window))     == BLE_ERROR_NONE) &&
+        ((rc = gap().getScanningParams().setTimeout(timeout))   == BLE_ERROR_NONE)) {
+        gap().getScanningParams().setActiveScanning(activeScanning);
         return BLE_ERROR_NONE;
     }
 
@@ -928,38 +902,38 @@
 
 inline ble_error_t
 BLE::setScanInterval(uint16_t interval) {
-    return scanningParams.setInterval(interval);
+    return gap().getScanningParams().setInterval(interval);
 }
 
 inline ble_error_t
 BLE::setScanWindow(uint16_t window) {
-    return scanningParams.setWindow(window);
+    return gap().getScanningParams().setWindow(window);
 }
 
 inline ble_error_t
 BLE::setScanTimeout(uint16_t timeout) {
-    return scanningParams.setTimeout(timeout);
+    return gap().getScanningParams().setTimeout(timeout);
 }
 
 inline void
 BLE::setActiveScan(bool activeScanning) {
-    return scanningParams.setActiveScanning(activeScanning);
+    return gap().getScanningParams().setActiveScanning(activeScanning);
 }
 
 inline ble_error_t
 BLE::startScan(void (*callback)(const Gap::AdvertisementCallbackParams_t *params)) {
-    return transport->getGap().startScan(scanningParams, callback);
+    return gap().startScan(callback);
 }
 
 template<typename T>
 inline ble_error_t
 BLE::startScan(T *object, void (T::*memberCallback)(const Gap::AdvertisementCallbackParams_t *params)) {
-    return transport->getGap().startScan(scanningParams, object, memberCallback);
+    return gap().startScan(scanningParams, object, memberCallback);
 }
 
 inline ble_error_t
 BLE::stopScan(void) {
-    return transport->getGap().stopScan();
+    return gap().stopScan();
 }
 
 inline ble_error_t
@@ -967,37 +941,37 @@
              Gap::AddressType_t             peerAddrType,
              const Gap::ConnectionParams_t *connectionParams,
              const GapScanningParams       *scanParams) {
-    return transport->getGap().connect(peerAddr, peerAddrType, connectionParams, scanParams);
+    return gap().connect(peerAddr, peerAddrType, connectionParams, scanParams);
 }
 
 inline ble_error_t
 BLE::disconnect(Gap::DisconnectionReason_t reason)
 {
-    return transport->getGap().disconnect(reason);
+    return gap().disconnect(reason);
 }
 
 inline void
 BLE::onTimeout(Gap::EventCallback_t timeoutCallback)
 {
-    transport->getGap().setOnTimeout(timeoutCallback);
+    gap().setOnTimeout(timeoutCallback);
 }
 
 inline void
 BLE::onConnection(Gap::ConnectionEventCallback_t connectionCallback)
 {
-    transport->getGap().setOnConnection(connectionCallback);
+    gap().setOnConnection(connectionCallback);
 }
 
 inline void
 BLE::onDisconnection(Gap::DisconnectionEventCallback_t disconnectionCallback)
 {
-    transport->getGap().setOnDisconnection(disconnectionCallback);
+    gap().setOnDisconnection(disconnectionCallback);
 }
 
 template<typename T>
 inline void
 BLE::addToDisconnectionCallChain(T *tptr, void (T::*mptr)(void)) {
-    transport->getGap().addToDisconnectionCallChain(tptr, mptr);
+    gap().addToDisconnectionCallChain(tptr, mptr);
 }
 
 inline void
@@ -1051,7 +1025,7 @@
 inline void
 BLE::onRadioNotification(Gap::RadioNotificationEventCallback_t callback)
 {
-    transport->getGap().setOnRadioNotification(callback);
+    gap().setOnRadioNotification(callback);
 }
 
 inline ble_error_t
@@ -1063,7 +1037,7 @@
 inline Gap::GapState_t
 BLE::getGapState(void) const
 {
-    return transport->getGap().getState();
+    return gap().getState();
 }
 
 inline ble_error_t
@@ -1106,18 +1080,18 @@
 inline ble_error_t
 BLE::getPreferredConnectionParams(Gap::ConnectionParams_t *params)
 {
-    return transport->getGap().getPreferredConnectionParams(params);
+    return gap().getPreferredConnectionParams(params);
 }
 
 inline ble_error_t
 BLE::setPreferredConnectionParams(const Gap::ConnectionParams_t *params)
 {
-    return transport->getGap().setPreferredConnectionParams(params);
+    return gap().setPreferredConnectionParams(params);
 }
 
 inline ble_error_t
 BLE::updateConnectionParams(Gap::Handle_t handle, const Gap::ConnectionParams_t *params) {
-    return transport->getGap().updateConnectionParams(handle, params);
+    return gap().updateConnectionParams(handle, params);
 }
 
 inline const char *
@@ -1129,37 +1103,37 @@
 inline ble_error_t
 BLE::setDeviceName(const uint8_t *deviceName)
 {
-    return transport->getGap().setDeviceName(deviceName);
+    return gap().setDeviceName(deviceName);
 }
 
 inline ble_error_t
 BLE::getDeviceName(uint8_t *deviceName, unsigned *lengthP)
 {
-    return transport->getGap().getDeviceName(deviceName, lengthP);
+    return gap().getDeviceName(deviceName, lengthP);
 }
 
 inline ble_error_t
 BLE::setAppearance(uint16_t appearance)
 {
-    return transport->getGap().setAppearance(appearance);
+    return gap().setAppearance(appearance);
 }
 
 inline ble_error_t
 BLE::getAppearance(uint16_t *appearanceP)
 {
-    return transport->getGap().getAppearance(appearanceP);
+    return gap().getAppearance(appearanceP);
 }
 
 inline ble_error_t
 BLE::setTxPower(int8_t txPower)
 {
-    return transport->getGap().setTxPower(txPower);
+    return gap().setTxPower(txPower);
 }
 
 inline void
 BLE::getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP)
 {
-    transport->getGap().getPermittedTxPowerValues(valueArrayPP, countP);
+    gap().getPermittedTxPowerValues(valueArrayPP, countP);
 }
 
 inline ble_error_t
@@ -1174,43 +1148,43 @@
 inline void
 BLE::onSecuritySetupInitiated(Gap::SecuritySetupInitiatedCallback_t callback)
 {
-    transport->getGap().setOnSecuritySetupInitiated(callback);
+    gap().setOnSecuritySetupInitiated(callback);
 }
 
 inline void
 BLE::onSecuritySetupCompleted(Gap::SecuritySetupCompletedCallback_t callback)
 {
-    transport->getGap().setOnSecuritySetupCompleted(callback);
+    gap().setOnSecuritySetupCompleted(callback);
 }
 
 inline void
 BLE::onLinkSecured(Gap::LinkSecuredCallback_t callback)
 {
-    transport->getGap().setOnLinkSecured(callback);
+    gap().setOnLinkSecured(callback);
 }
 
 inline void
 BLE::onSecurityContextStored(Gap::HandleSpecificEvent_t callback)
 {
-    transport->getGap().setOnSecurityContextStored(callback);
+    gap().setOnSecurityContextStored(callback);
 }
 
 inline void
 BLE::onPasskeyDisplay(Gap::PasskeyDisplayCallback_t callback)
 {
-    return transport->getGap().setOnPasskeyDisplay(callback);
+    return gap().setOnPasskeyDisplay(callback);
 }
 
 inline ble_error_t
 BLE::getLinkSecurity(Gap::Handle_t connectionHandle, Gap::LinkSecurityStatus_t *securityStatusP)
 {
-    return transport->getGap().getLinkSecurity(connectionHandle, securityStatusP);
+    return gap().getLinkSecurity(connectionHandle, securityStatusP);
 }
 
 inline ble_error_t
 BLE::purgeAllBondingState(void)
 {
-    return transport->getGap().purgeAllBondingState();
+    return gap().purgeAllBondingState();
 }
 
 inline ble_error_t
--- a/public/Gap.h	Fri Jun 19 15:52:07 2015 +0100
+++ b/public/Gap.h	Fri Jun 19 15:52:07 2015 +0100
@@ -17,6 +17,9 @@
 #ifndef __GAP_H__
 #define __GAP_H__
 
+#include "GapAdvertisingData.h"
+#include "GapAdvertisingParams.h"
+#include "GapScanningParams.h"
 #include "GapEvents.h"
 #include "CallChain.h"
 #include "FunctionPointerWithContext.h"
@@ -199,10 +202,8 @@
 
 public:
     /* These functions must be defined in the sub-class */
-    virtual ble_error_t setAddress(AddressType_t type,  const Address_t address)                  = 0;
+    virtual ble_error_t setAddress(AddressType_t type,  const Address_t address)                   = 0;
     virtual ble_error_t getAddress(AddressType_t *typeP, Address_t address)                        = 0;
-    virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &) = 0;
-    virtual ble_error_t startAdvertising(const GapAdvertisingParams &)                             = 0;
     virtual ble_error_t stopAdvertising(void)                                                      = 0;
     virtual ble_error_t stopScan()                                                                 = 0;
     virtual uint16_t    getMinAdvertisingInterval(void) const                                      = 0;
@@ -228,7 +229,25 @@
     virtual ble_error_t setTxPower(int8_t txPower)                            = 0;
     virtual void        getPermittedTxPowerValues(const int8_t **, size_t *)  = 0;
 
-    ble_error_t startScan(const GapScanningParams &scanningParams, void (*callback)(const AdvertisementCallbackParams_t *params)) {
+    ble_error_t startAdvertising(void) {
+        return startAdvertising(advParams);
+    }
+
+    ble_error_t setAdvertisingData(void) {
+        if (needToSetAdvPayload) {
+            needToSetAdvPayload = false;
+            return setAdvertisingData(advPayload, scanResponse);
+        }
+
+        return BLE_ERROR_NONE;
+    }
+
+private:
+    virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &) = 0;
+    virtual ble_error_t startAdvertising(const GapAdvertisingParams &)                             = 0;
+
+public:
+    ble_error_t startScan(void (*callback)(const AdvertisementCallbackParams_t *params)) {
         ble_error_t err = BLE_ERROR_NONE;
         if (callback) {
             if ((err = startRadioScan(scanningParams)) == BLE_ERROR_NONE) {
@@ -240,7 +259,7 @@
     }
 
     template<typename T>
-    ble_error_t startScan(const GapScanningParams &scanningParams, T *object, void (T::*callbackMember)(const AdvertisementCallbackParams_t *params)) {
+    ble_error_t startScan(T *object, void (T::*callbackMember)(const AdvertisementCallbackParams_t *params)) {
         ble_error_t err = BLE_ERROR_NONE;
         if (object && callbackMember) {
             if ((err = startRadioScan(scanningParams)) == BLE_ERROR_NONE) {
@@ -315,6 +334,39 @@
     template<typename T>
     void addToDisconnectionCallChain(T *tptr, void (T::*mptr)(void)) {disconnectionCallChain.add(tptr, mptr);}
 
+    GapAdvertisingParams &getAdvParams(void) {
+        return advParams;
+    }
+    const GapAdvertisingParams &getAdvParams(void) const {
+        return advParams;
+    }
+    void setAdvParams(const GapAdvertisingParams &newParams) {
+        advParams = newParams;
+    }
+
+    GapAdvertisingData &getAdvPayload(void) {
+        needToSetAdvPayload = true;
+        return advPayload;
+    }
+    const GapAdvertisingData &getAdvPayload(void) const {
+        return advPayload;
+    }
+
+    GapAdvertisingData &getScanResponse(void) {
+        needToSetAdvPayload = true;
+        return scanResponse;
+    }
+    const GapAdvertisingData &getScanResponse(void) const {
+        return scanResponse;
+    }
+
+    GapScanningParams &getScanningParams(void) {
+        return scanningParams;
+    }
+    const GapScanningParams &getScanningParams(void) const {
+        return scanningParams;
+    }
+
 public:
     GapState_t getState(void) const {
         return state;
@@ -322,6 +374,11 @@
 
 protected:
     Gap() :
+        advParams(),
+        advPayload(),
+        needToSetAdvPayload(true),
+        scanningParams(),
+        scanResponse(),
         state(),
         onTimeout(NULL),
         onConnection(NULL),
@@ -334,7 +391,8 @@
         onPasskeyDisplay(),
         onAdvertisementReport(),
         disconnectionCallChain() {
-        /* empty */
+        advPayload.clear();
+        scanResponse.clear();
     }
 
 public:
@@ -420,6 +478,16 @@
     }
 
 protected:
+    GapAdvertisingParams             advParams;
+    GapAdvertisingData               advPayload;
+    /* Accumulation of AD structures in the advertisement payload should
+     * eventually result in a call to the target's setAdvertisingData() before
+     * the server begins advertising. This flag marks the status of the pending update.*/
+    bool                             needToSetAdvPayload;
+
+    GapScanningParams                scanningParams;
+    GapAdvertisingData               scanResponse;
+
     GapState_t                       state;
 
 protected:
--- a/public/GapAdvertisingData.h	Fri Jun 19 15:52:07 2015 +0100
+++ b/public/GapAdvertisingData.h	Fri Jun 19 15:52:07 2015 +0100
@@ -17,6 +17,7 @@
 #ifndef __GAP_ADVERTISING_DATA_H__
 #define __GAP_ADVERTISING_DATA_H__
 
+#include <stdint.h>
 #include <string.h>
 
 #include "blecommon.h"
--- a/public/GapScanningParams.h	Fri Jun 19 15:52:07 2015 +0100
+++ b/public/GapScanningParams.h	Fri Jun 19 15:52:07 2015 +0100
@@ -17,8 +17,6 @@
 #ifndef __GAP_SCANNING_PARAMS_H__
 #define __GAP_SCANNING_PARAMS_H__
 
-#include "Gap.h"
-
 class GapScanningParams {
 public:
     static const unsigned SCAN_INTERVAL_MIN = 0x0004; /**< Minimum Scan interval in 625 us units, i.e. 2.5 ms. */
@@ -29,56 +27,18 @@
     static const unsigned SCAN_TIMEOUT_MAX  = 0xFFFF; /**< Maximum Scan timeout in seconds. */
 
 public:
-    GapScanningParams(uint16_t interval = SCAN_INTERVAL_MAX,
-                      uint16_t window   = SCAN_WINDOW_MAX,
-                      uint16_t timeout  = 0,
-                      bool     activeScanning = false) : _interval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(interval)),
-                                                         _window(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(window)),
-                                                         _timeout(timeout),
-                                                         _activeScanning(activeScanning) {
-        /* stay within limits */
-        if (_interval < SCAN_INTERVAL_MIN) {
-            _interval = SCAN_INTERVAL_MIN;
-        }
-        if (_interval > SCAN_INTERVAL_MAX) {
-            _interval = SCAN_INTERVAL_MAX;
-        }
-        if (_window < SCAN_WINDOW_MIN) {
-            _window = SCAN_WINDOW_MIN;
-        }
-        if (_window > SCAN_WINDOW_MAX) {
-            _window = SCAN_WINDOW_MAX;
-        }
-    }
+    GapScanningParams(uint16_t interval       = SCAN_INTERVAL_MAX,
+                      uint16_t window         = SCAN_WINDOW_MAX,
+                      uint16_t timeout        = 0,
+                      bool     activeScanning = false);
 
-    ble_error_t setInterval(uint16_t newIntervalInMS) {
-        uint16_t newInterval = Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(newIntervalInMS);
-        if ((newInterval >= SCAN_INTERVAL_MIN) && (newInterval < SCAN_INTERVAL_MAX)) {
-            _interval = newInterval;
-            return BLE_ERROR_NONE;
-        }
+    ble_error_t setInterval(uint16_t newIntervalInMS);
 
-        return BLE_ERROR_PARAM_OUT_OF_RANGE;
-    }
+    ble_error_t setWindow(uint16_t newWindowInMS);
 
-    ble_error_t setWindow(uint16_t newWindowInMS)     {
-        uint16_t newWindow = Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(newWindowInMS);
-        if ((newWindow >= SCAN_WINDOW_MIN) && (newWindow < SCAN_WINDOW_MAX)) {
-            _window   = newWindow;
-            return BLE_ERROR_NONE;
-        }
+    ble_error_t setTimeout(uint16_t newTimeout);
 
-        return BLE_ERROR_PARAM_OUT_OF_RANGE;
-    }
-
-    ble_error_t setTimeout(uint16_t newTimeout)   {
-        _timeout  = newTimeout;
-        return BLE_ERROR_NONE;
-    }
-
-    void setActiveScanning(bool activeScanning) {
-        _activeScanning = activeScanning;
-    }
+    void        setActiveScanning(bool activeScanning);
 
 public:
     /* @Note: The following return durations in units of 0.625 ms */