Junichi Katsu / nRF51822

Dependencies:   nrf51-sdk

Dependents:   microbit-dal

Fork of nRF51822 by Lancaster University

Files at this revision

API Documentation at this revision

Comitter:
LancasterUniversity
Date:
Wed Apr 06 22:39:17 2016 +0100
Parent:
615:65ea2acfc6a2
Child:
618:b63fd32be38a
Commit message:
Synchronized with git rev 67d0ac73
Author: Joe Finney
microbit: Update to indicate when system attributes require intialisation

Changed in this revision

BSD-3clause-Nordic.txt Show diff for this revision Revisions of this file
LICENSE Show annotated file Show diff for this revision Revisions of this file
bootloader/softdevice_nrf51822_licence_agreement.txt Show annotated file Show diff for this revision Revisions of this file
module.json Show annotated file Show diff for this revision Revisions of this file
softdevice_nrf51822_licence_agreement.txt Show annotated file Show diff for this revision Revisions of this file
source/btle/btle.cpp Show annotated file Show diff for this revision Revisions of this file
source/btle/btle.h Show annotated file Show diff for this revision Revisions of this file
source/btle/btle_discovery.cpp Show annotated file Show diff for this revision Revisions of this file
source/btle/btle_security.cpp Show annotated file Show diff for this revision Revisions of this file
source/btle/btle_security.h Show annotated file Show diff for this revision Revisions of this file
source/btle/custom/custom_helper.cpp Show annotated file Show diff for this revision Revisions of this file
source/btle/custom/custom_helper.h Show annotated file Show diff for this revision Revisions of this file
source/nRF5xCharacteristicDescriptorDiscoverer.cpp Show annotated file Show diff for this revision Revisions of this file
source/nRF5xCharacteristicDescriptorDiscoverer.h Show annotated file Show diff for this revision Revisions of this file
source/nRF5xDiscoveredCharacteristic.h Show annotated file Show diff for this revision Revisions of this file
source/nRF5xGap.cpp Show annotated file Show diff for this revision Revisions of this file
source/nRF5xGap.h Show annotated file Show diff for this revision Revisions of this file
source/nRF5xGattClient.cpp Show annotated file Show diff for this revision Revisions of this file
source/nRF5xGattClient.h Show annotated file Show diff for this revision Revisions of this file
source/nRF5xGattServer.cpp Show annotated file Show diff for this revision Revisions of this file
source/nRF5xGattServer.h Show annotated file Show diff for this revision Revisions of this file
source/nRF5xSecurityManager.cpp Show diff for this revision Revisions of this file
source/nRF5xSecurityManager.h Show annotated file Show diff for this revision Revisions of this file
source/nRF5xServiceDiscovery.cpp Show annotated file Show diff for this revision Revisions of this file
source/nRF5xServiceDiscovery.h Show annotated file Show diff for this revision Revisions of this file
source/nRF5xn.cpp Show annotated file Show diff for this revision Revisions of this file
source/nRF5xn.h Show annotated file Show diff for this revision Revisions of this file
source/nordic-sdk/components/ble/ble_radio_notification/ble_radio_notification.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/ble/ble_radio_notification/ble_radio_notification.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/ble/ble_services/ble_dfu/ble_dfu.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/ble/ble_services/ble_dfu/ble_dfu.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/ble/common/ble_advdata.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/ble/common/ble_advdata.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/ble/common/ble_advdata_parser.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/ble/common/ble_advdata_parser.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/ble/common/ble_conn_params.cpp Show diff for this revision Revisions of this file
source/nordic-sdk/components/ble/common/ble_conn_params.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/ble/common/ble_date_time.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/ble/common/ble_sensor_location.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/ble/common/ble_srv_common.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/ble/common/ble_srv_common.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/ble/device_manager/config/device_manager_cnfg.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/ble/device_manager/device_manager.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/ble/device_manager/device_manager_peripheral.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/drivers_nrf/ble_flash/ble_flash.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/drivers_nrf/ble_flash/ble_flash.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/drivers_nrf/hal/compiler_abstraction.h Show annotated file Show diff for this revision Revisions of this file
source/nordic-sdk/components/drivers_nrf/hal/nrf.h Show annotated file Show diff for this revision Revisions of this file
source/nordic-sdk/components/drivers_nrf/hal/nrf51.h Show annotated file Show diff for this revision Revisions of this file
source/nordic-sdk/components/drivers_nrf/hal/nrf51_bitfields.h Show annotated file Show diff for this revision Revisions of this file
source/nordic-sdk/components/drivers_nrf/hal/nrf51_deprecated.h Show annotated file Show diff for this revision Revisions of this file
source/nordic-sdk/components/drivers_nrf/hal/nrf_delay.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/drivers_nrf/hal/nrf_ecb.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/drivers_nrf/hal/nrf_ecb.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/drivers_nrf/hal/nrf_gpio.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/drivers_nrf/hal/nrf_gpiote.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/drivers_nrf/hal/nrf_nvmc.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/drivers_nrf/hal/nrf_nvmc.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/drivers_nrf/hal/nrf_temp.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/drivers_nrf/pstorage/config/pstorage_platform.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/drivers_nrf/pstorage/pstorage.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/drivers_nrf/pstorage/pstorage.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/bootloader_dfu/bootloader.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/bootloader_dfu/bootloader_types.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/bootloader_dfu/bootloader_util.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/bootloader_dfu/bootloader_util_arm.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/bootloader_dfu/dfu.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/bootloader_dfu/dfu_bank_internal.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/bootloader_dfu/dfu_ble_svc.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/bootloader_dfu/dfu_ble_svc_internal.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/bootloader_dfu/dfu_init.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/bootloader_dfu/dfu_init_template.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/bootloader_dfu/dfu_transport.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/bootloader_dfu/dfu_types.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/bootloader_dfu/experimental/dfu_app_handler.c Show annotated file Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/bootloader_dfu/experimental/dfu_app_handler.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/bootloader_dfu/hci_transport/hci_mem_pool_internal.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/crc16/crc16.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/hci/hci_mem_pool.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/hci/hci_mem_pool.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/scheduler/app_scheduler.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/util/app_error.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/util/app_util_platform.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/util/app_util_platform.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/util/common.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/util/nordic_common.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/util/nrf_assert.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/util/nrf_assert.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/util/sdk_common.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/util/sdk_errors.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/libraries/util/sdk_os.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/softdevice/common/softdevice_handler/ant_stack_handler_types.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/softdevice/common/softdevice_handler/ble_stack_handler_types.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/softdevice/common/softdevice_handler/softdevice_handler.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/softdevice/common/softdevice_handler/softdevice_handler.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/softdevice/common/softdevice_handler/softdevice_handler_appsh.c Show diff for this revision Revisions of this file
source/nordic-sdk/components/softdevice/common/softdevice_handler/softdevice_handler_appsh.h Show diff for this revision Revisions of this file
source/nordic-sdk/components/softdevice/s130/doc/ble_api.dox Show diff for this revision Revisions of this file
source/nordic-sdk/components/softdevice/s130/include/ble_gap.h Show annotated file Show diff for this revision Revisions of this file
source/nordic-sdk/components/softdevice/s130/include/ble_gattc.h Show annotated file Show diff for this revision Revisions of this file
source/nordic-sdk/components/softdevice/s130/include/ble_gatts.h Show annotated file Show diff for this revision Revisions of this file
source/nordic-sdk/components/softdevice/s130/include/ble_hci.h Show annotated file Show diff for this revision Revisions of this file
source/nordic-sdk/components/softdevice/s130/include/ble_l2cap.h Show annotated file Show diff for this revision Revisions of this file
source/nordic-sdk/components/softdevice/s130/include/ble_types.h Show annotated file Show diff for this revision Revisions of this file
source/nordic-sdk/components/softdevice/s130/include/nrf_error.h Show annotated file Show diff for this revision Revisions of this file
source/nordic-sdk/components/softdevice/s130/include/nrf_sdm.h Show annotated file Show diff for this revision Revisions of this file
source/nordic-sdk/components/softdevice/s130/include/nrf_soc.h Show annotated file Show diff for this revision Revisions of this file
source/nordic-sdk/components/softdevice/s130/include/nrf_svc.h Show annotated file Show diff for this revision Revisions of this file
source/nordic-sdk/components/softdevice/s130/include/softdevice_assert.h Show annotated file Show diff for this revision Revisions of this file
source/projectconfig.h Show annotated file Show diff for this revision Revisions of this file
source/supress-warnings.cmake Show annotated file Show diff for this revision Revisions of this file
--- a/BSD-3clause-Nordic.txt	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
\ No newline at end of file
--- a/LICENSE	Wed Apr 06 22:38:43 2016 +0100
+++ b/LICENSE	Wed Apr 06 22:39:17 2016 +0100
@@ -1,6 +1,6 @@
-Many of the files in this module have been inherited from the Nordic SDK for
-nRF51822; they come with a BSD-like license offered by Nordic for use in mbed.
-Some other files come from the mbed SDK, and are licensed under Apache-2.0.
-Unless specifically indicated otherwise in a file, files are licensed
-under the Apache 2.0 license, as can be found in: apache-2.0.txt.
-The BSD-like Nordic license can be found in BSD-3clause-Nordic.txt
\ No newline at end of file
+This module contains softdevice which comes with The Nordic Softdevice License Agreement,
+a BSD-like licence for binary distributions, offered by Nordic for use in mbed. Some
+other files come from the mbed SDK, and are licensed under Apache-2.0. Unless
+specifically indicated otherwise in a file, files are licensed under the
+Apache 2.0 license, as can be found in: apache-2.0.txt. The Nordic Semiconductor Softdevice
+License Agreement can be found in softdevice_nrf51822_licence_agreement.txt.
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bootloader/softdevice_nrf51822_licence_agreement.txt	Wed Apr 06 22:39:17 2016 +0100
@@ -0,0 +1,30 @@
+/*
+ * S110/S120/S130 License Agreement
+ *
+ * Copyright (c) 2015, Nordic Semiconductor ASA, All rights reserved.
+ *
+ * Redistribution. Redistribution and use in binary form, without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * • Redistributions must reproduce the above copyright notice and the following
+ *   disclaimer in the documentation and/or other materials provided with the
+ *   distribution.
+ * • Neither the name of the copyright holder nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ * • No reverse engineering, decompilation, or disassembly of this software is
+ *   permitted.
+ *
+ * DISCLAIMER.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * /
\ No newline at end of file
--- a/module.json	Wed Apr 06 22:38:43 2016 +0100
+++ b/module.json	Wed Apr 06 22:39:17 2016 +0100
@@ -1,6 +1,6 @@
 {
   "name": "ble-nrf51822",
-  "version": "2.0.2",
+  "version": "2.5.0",
   "description": "Nordic stack and drivers for the mbed BLE API.",
   "keywords": [
     "Bluetooth",
@@ -18,32 +18,19 @@
     {
       "url": "https://spdx.org/licenses/Apache-2.0",
       "type": "Apache-2.0"
+    },
+    {
+      "type": "LicenseRef-softdevice_nrf51822_licence_agreement.txt"
     }
   ],
   "dependencies": {
-    "ble": "^2.0.0"
+    "ble": "^2.3.0",
+    "nrf51-sdk": "^2.1.0"
   },
   "extraIncludes": [
     "source/btle",
     "source/btle/custom",
-    "source/common",
-    "source/nordic-sdk/components",
-    "source/nordic-sdk/components/libraries/util",
-    "source/nordic-sdk/components/libraries/hci",
-    "source/nordic-sdk/components/libraries/bootloader_dfu",
-    "source/nordic-sdk/components/libraries/bootloader_dfu/hci_transport",
-    "source/nordic-sdk/components/libraries/bootloader_dfu/experimental",
-    "source/nordic-sdk/components/softdevice/s130/include",
-    "source/nordic-sdk/components/softdevice/common/softdevice_handler",
-    "source/nordic-sdk/components/drivers_nrf/hal",
-    "source/nordic-sdk/components/drivers_nrf/ble_flash",
-    "source/nordic-sdk/components/drivers_nrf/pstorage",
-    "source/nordic-sdk/components/drivers_nrf/pstorage/config",
-    "source/nordic-sdk/components/ble/ble_radio_notification",
-    "source/nordic-sdk/components/ble/ble_services/ble_dfu",
-    "source/nordic-sdk/components/ble/common",
-    "source/nordic-sdk/components/ble/device_manager",
-    "source/nordic-sdk/components/ble/device_manager/config"
+    "source/common"
   ],
   "targetDependencies": {}
 }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/softdevice_nrf51822_licence_agreement.txt	Wed Apr 06 22:39:17 2016 +0100
@@ -0,0 +1,30 @@
+/*
+ * S110/S120/S130 License Agreement
+ *
+ * Copyright (c) 2015, Nordic Semiconductor ASA, All rights reserved.
+ *
+ * Redistribution. Redistribution and use in binary form, without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * • Redistributions must reproduce the above copyright notice and the following
+ *   disclaimer in the documentation and/or other materials provided with the
+ *   distribution.
+ * • Neither the name of the copyright holder nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ * • No reverse engineering, decompilation, or disassembly of this software is
+ *   permitted.
+ *
+ * DISCLAIMER.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * /
\ No newline at end of file
--- a/source/btle/btle.cpp	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/btle/btle.cpp	Wed Apr 06 22:39:17 2016 +0100
@@ -19,7 +19,6 @@
 
 #include "btle.h"
 
-#include "ble_stack_handler_types.h"
 #include "ble_flash.h"
 #include "ble_conn_params.h"
 
@@ -27,23 +26,28 @@
 #include "btle_advertising.h"
 #include "custom/custom_helper.h"
 
-#include "softdevice_handler.h"
-#include "pstorage.h"
+#include "ble/GapEvents.h"
+#include "nRF5xn.h"
 
-#include "ble/GapEvents.h"
-#include "nRF5xGap.h"
-#include "nRF5xGattServer.h"
-#include "nRF5xSecurityManager.h"
-
+extern "C" {
+#include "pstorage.h"
 #include "device_manager.h"
+#include "softdevice_handler.h"
+#include "ble_stack_handler_types.h"
+}
 
 #include "ble_hci.h"
 #include "btle_discovery.h"
 
+#include "nRF5xGattClient.h"
+#include "nRF5xServiceDiscovery.h"
+#include "nRF5xCharacteristicDescriptorDiscoverer.h"
+
 extern "C" void assert_nrf_callback(uint16_t line_num, const uint8_t *p_file_name);
 void            app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t *p_file_name);
 
 static void btle_handler(ble_evt_t *p_ble_evt);
+static uint32_t gatt_table_size = BLE_GATTS_ATTR_TAB_SIZE_DEFAULT;
 
 static void sys_evt_dispatch(uint32_t sys_evt)
 {
@@ -74,6 +78,18 @@
     return NRF_SUCCESS;
 }
 
+error_t
+btle_set_gatt_table_size(uint32_t size)
+{
+    if (size >= BLE_GATTS_ATTR_TAB_SIZE_MIN)
+    {
+        gatt_table_size = size;
+        return ERROR_NONE;
+    }
+
+    return ERROR_INVALID_PARAM;
+}
+
 error_t btle_init(void)
 {
     nrf_clock_lfclksrc_t clockSource;
@@ -101,7 +117,8 @@
     static const bool IS_SRVC_CHANGED_CHARACT_PRESENT = true;
     ble_enable_params_t enableParams = {
         .gatts_enable_params = {
-            .service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT
+            .service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT,
+            .attr_tab_size = gatt_table_size
         }
     };
     if (sd_ble_enable(&enableParams) != NRF_SUCCESS) {
@@ -119,9 +136,7 @@
     ASSERT_STATUS( softdevice_ble_evt_handler_set(btle_handler));
     ASSERT_STATUS( softdevice_sys_evt_handler_set(sys_evt_dispatch));
 
-    btle_gap_init();
-
-    return ERROR_NONE;
+    return btle_gap_init();
 }
 
 static void btle_handler(ble_evt_t *p_ble_evt)
@@ -137,6 +152,11 @@
     bleGattcEventHandler(p_ble_evt);
 #endif
 
+    nRF5xn               &ble             = nRF5xn::Instance(BLE::DEFAULT_INSTANCE);
+    nRF5xGap             &gap             = (nRF5xGap &) ble.getGap();
+    nRF5xGattServer      &gattServer      = (nRF5xGattServer &) ble.getGattServer();
+    nRF5xSecurityManager &securityManager = (nRF5xSecurityManager &) ble.getSecurityManager();
+
     /* Custom event handler */
     switch (p_ble_evt->header.evt_id) {
         case BLE_GAP_EVT_CONNECTED: {
@@ -147,14 +167,14 @@
 #else
             Gap::Role_t role = static_cast<Gap::Role_t>(p_ble_evt->evt.gap_evt.params.connected.role);
 #endif
-            nRF5xGap::getInstance().setConnectionHandle(handle);
+            gap.setConnectionHandle(handle);
             const Gap::ConnectionParams_t *params = reinterpret_cast<Gap::ConnectionParams_t *>(&(p_ble_evt->evt.gap_evt.params.connected.conn_params));
             const ble_gap_addr_t *peer = &p_ble_evt->evt.gap_evt.params.connected.peer_addr;
             const ble_gap_addr_t *own  = &p_ble_evt->evt.gap_evt.params.connected.own_addr;
-            nRF5xGap::getInstance().processConnectionEvent(handle,
+            gap.processConnectionEvent(handle,
                                                            role,
-                                                           static_cast<Gap::AddressType_t>(peer->addr_type), peer->addr,
-                                                           static_cast<Gap::AddressType_t>(own->addr_type),  own->addr,
+                                                           static_cast<BLEProtocol::AddressType_t>(peer->addr_type), peer->addr,
+                                                           static_cast<BLEProtocol::AddressType_t>(own->addr_type),  own->addr,
                                                            params);
             break;
         }
@@ -163,7 +183,7 @@
             Gap::Handle_t handle = p_ble_evt->evt.gap_evt.conn_handle;
             // Since we are not in a connection and have not started advertising,
             // store bonds
-            nRF5xGap::getInstance().setConnectionHandle (BLE_CONN_HANDLE_INVALID);
+            gap.setConnectionHandle (BLE_CONN_HANDLE_INVALID);
 
             Gap::DisconnectionReason_t reason;
             switch (p_ble_evt->evt.gap_evt.params.disconnected.reason) {
@@ -182,16 +202,24 @@
                     reason = static_cast<Gap::DisconnectionReason_t>(p_ble_evt->evt.gap_evt.params.disconnected.reason);
                     break;
             }
-            nRF5xGap::getInstance().processDisconnectionEvent(handle, reason);
+
+            // Close all pending discoveries for this connection
+#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
+            nRF5xGattClient& gattClient = ble.getGattClient();
+            gattClient.characteristicDescriptorDiscoverer().terminate(handle, BLE_ERROR_INVALID_STATE);
+            gattClient.discovery().terminate(handle);
+#endif
+
+            gap.processDisconnectionEvent(handle, reason);
             break;
         }
 
         case BLE_GAP_EVT_PASSKEY_DISPLAY:
-            nRF5xSecurityManager::getInstance().processPasskeyDisplayEvent(p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->evt.gap_evt.params.passkey_display.passkey);
+            securityManager.processPasskeyDisplayEvent(p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->evt.gap_evt.params.passkey_display.passkey);
             break;
 
         case BLE_GAP_EVT_TIMEOUT:
-            nRF5xGap::getInstance().processTimeoutEvent(static_cast<Gap::TimeoutSource_t>(p_ble_evt->evt.gap_evt.params.timeout.src));
+            gap.processTimeoutEvent(static_cast<Gap::TimeoutSource_t>(p_ble_evt->evt.gap_evt.params.timeout.src));
             break;
 
         case BLE_GATTC_EVT_TIMEOUT:
@@ -203,12 +231,12 @@
 
         case BLE_GAP_EVT_ADV_REPORT: {
             const ble_gap_evt_adv_report_t *advReport = &p_ble_evt->evt.gap_evt.params.adv_report;
-            nRF5xGap::getInstance().processAdvertisementReport(advReport->peer_addr.addr,
-                                                               advReport->rssi,
-                                                               advReport->scan_rsp,
-                                                               static_cast<GapAdvertisingParams::AdvertisingType_t>(advReport->type),
-                                                               advReport->dlen,
-                                                               advReport->data);
+            gap.processAdvertisementReport(advReport->peer_addr.addr,
+                                           advReport->rssi,
+                                           advReport->scan_rsp,
+                                           static_cast<GapAdvertisingParams::AdvertisingType_t>(advReport->type),
+                                           advReport->dlen,
+                                           advReport->data);
             break;
         }
 
@@ -216,7 +244,7 @@
             break;
     }
 
-    nRF5xGattServer::getInstance().hwCallback(p_ble_evt);
+    gattServer.hwCallback(p_ble_evt);
 }
 
 /*! @brief      Callback when an error occurs inside the SoftDevice */
--- a/source/btle/btle.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/btle/btle.h	Wed Apr 06 22:39:17 2016 +0100
@@ -27,6 +27,7 @@
 #include "ble.h"
 
 error_t     btle_init(void);
+error_t     btle_set_gatt_table_size(uint32_t size);
 
 #ifdef __cplusplus
 }
--- a/source/btle/btle_discovery.cpp	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/btle/btle_discovery.cpp	Wed Apr 06 22:39:17 2016 +0100
@@ -15,12 +15,19 @@
  */
 
 #include "nRF5xServiceDiscovery.h"
+#include "nRF5xCharacteristicDescriptorDiscoverer.h"
 #include "nRF5xGattClient.h"
+#include "nRF5xn.h"
 
 #if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
 void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
 {
-    nRF5xServiceDiscovery &sdSingleton = nRF5xGattClient::getInstance().discovery;
+    nRF5xn                &ble         = nRF5xn::Instance(BLE::DEFAULT_INSTANCE);
+    nRF5xGap              &gap         = (nRF5xGap &) ble.getGap();
+    nRF5xGattClient       &gattClient  = (nRF5xGattClient &) ble.getGattClient();
+    nRF5xServiceDiscovery &sdSingleton = gattClient.discovery();
+    nRF5xCharacteristicDescriptorDiscoverer &characteristicDescriptorDiscoverer =
+        gattClient.characteristicDescriptorDiscoverer();
 
     switch (p_ble_evt->header.evt_id) {
         case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP:
@@ -44,7 +51,7 @@
 
                 case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND:
                 default:
-                    sdSingleton.terminateCharacteristicDiscovery();
+                    sdSingleton.terminateCharacteristicDiscovery(BLE_ERROR_NONE);
                     break;
             }
             break;
@@ -63,7 +70,7 @@
                     .len        = p_ble_evt->evt.gattc_evt.params.read_rsp.len,
                     .data       = p_ble_evt->evt.gattc_evt.params.read_rsp.data,
                 };
-                nRF5xGattClient::getInstance().processReadResponse(&response);
+                gattClient.processReadResponse(&response);
             }
             break;
 
@@ -76,7 +83,7 @@
                     .len        = p_ble_evt->evt.gattc_evt.params.write_rsp.len,
                     .data       = p_ble_evt->evt.gattc_evt.params.write_rsp.data,
                 };
-                nRF5xGattClient::getInstance().processWriteResponse(&response);
+                gattClient.processWriteResponse(&response);
             }
             break;
 
@@ -88,9 +95,31 @@
                 params.len        = p_ble_evt->evt.gattc_evt.params.hvx.len;
                 params.data       = p_ble_evt->evt.gattc_evt.params.hvx.data;
 
-                nRF5xGattClient::getInstance().processHVXEvent(&params);
+                gattClient.processHVXEvent(&params);
             }
             break;
+
+        case BLE_GATTC_EVT_DESC_DISC_RSP: {
+            uint16_t conn_handle = p_ble_evt->evt.gattc_evt.conn_handle;
+            uint16_t status = p_ble_evt->evt.gattc_evt.gatt_status;
+            const ble_gattc_evt_desc_disc_rsp_t& discovered_descriptors = p_ble_evt->evt.gattc_evt.params.desc_disc_rsp;
+
+            switch(status) {
+                case BLE_GATT_STATUS_SUCCESS:
+                    characteristicDescriptorDiscoverer.process(
+                        conn_handle,
+                        discovered_descriptors
+                    );
+                    break;
+                case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND:
+                    // end of discovery
+                    characteristicDescriptorDiscoverer.terminate(conn_handle, BLE_ERROR_NONE);
+                    break;
+                default:
+                    characteristicDescriptorDiscoverer.terminate(conn_handle, BLE_ERROR_UNSPECIFIED);
+                    break;
+            }
+        }   break;
     }
 
     sdSingleton.progressCharacteristicDiscovery();
--- a/source/btle/btle_security.cpp	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/btle/btle_security.cpp	Wed Apr 06 22:39:17 2016 +0100
@@ -15,17 +15,42 @@
  */
 
 #include "btle.h"
-#include "pstorage.h"
+
+#include "nRF5xn.h"
 
-#include "nRF5xGap.h"
-#include "nRF5xSecurityManager.h"
+extern "C" {
+#include "pstorage.h"
+#include "device_manager.h"
+#include "id_manager.h"
+}
 
-#include "device_manager.h"
 #include "btle_security.h"
 
 static dm_application_instance_t applicationInstance;
+static bool                      initialized = false;
 static ret_code_t dm_handler(dm_handle_t const *p_handle, dm_event_t const *p_event, ret_code_t event_result);
 
+// default security parameters
+static ble_gap_sec_params_t securityParameters = {
+    .bond          = true,         /**< Perform bonding. */
+    .mitm          = true,         /**< Man In The Middle protection required. */
+    .io_caps       = SecurityManager::IO_CAPS_NONE, /**< IO capabilities, see @ref BLE_GAP_IO_CAPS. */
+    .oob           = 0,            /**< Out Of Band data available. */
+    .min_key_size  = 16,           /**< Minimum encryption key size in octets between 7 and 16. If 0 then not applicable in this instance. */
+    .max_key_size  = 16,           /**< Maximum encryption key size in octets between min_key_size and 16. */
+    .kdist_periph  = {
+      .enc  = 1,                   /**< Long Term Key and Master Identification. */
+      .id   = 1,                   /**< Identity Resolving Key and Identity Address Information. */
+      .sign = 1,                   /**< Connection Signature Resolving Key. */
+    },                             /**< Key distribution bitmap: keys that the peripheral device will distribute. */
+};
+
+bool
+btle_hasInitializedSecurity(void)
+{
+    return initialized;
+}
+
 ble_error_t
 btle_initializeSecurity(bool                                      enableBonding,
                         bool                                      requireMITM,
@@ -33,7 +58,6 @@
                         const SecurityManager::Passkey_t          passkey)
 {
     /* guard against multiple initializations */
-    static bool initialized = false;
     if (initialized) {
         return BLE_ERROR_NONE;
     }
@@ -68,22 +92,15 @@
         return BLE_ERROR_UNSPECIFIED;
     }
 
+    // update default security parameters with function call parameters
+    securityParameters.bond = enableBonding;
+    securityParameters.mitm = requireMITM;
+    securityParameters.io_caps = iocaps;
+
     const dm_application_param_t dm_param = {
         .evt_handler  = dm_handler,
         .service_type = DM_PROTOCOL_CNTXT_GATT_CLI_ID,
-        .sec_param    = {
-            .bond          = enableBonding,/**< Perform bonding. */
-            .mitm          = requireMITM,  /**< Man In The Middle protection required. */
-            .io_caps       = iocaps,       /**< IO capabilities, see @ref BLE_GAP_IO_CAPS. */
-            .oob           = 0,            /**< Out Of Band data available. */
-            .min_key_size  = 16,           /**< Minimum encryption key size in octets between 7 and 16. If 0 then not applicable in this instance. */
-            .max_key_size  = 16,           /**< Maximum encryption key size in octets between min_key_size and 16. */
-            .kdist_periph  = {
-              .enc  = 1,                     /**< Long Term Key and Master Identification. */
-              .id   = 1,                     /**< Identity Resolving Key and Identity Address Information. */
-              .sign = 1,                     /**< Connection Signature Resolving Key. */
-            },                             /**< Key distribution bitmap: keys that the peripheral device will distribute. */
-        }
+        .sec_param    = securityParameters
     };
 
     if ((rc = dm_register(&applicationInstance, &dm_param)) != NRF_SUCCESS) {
@@ -148,20 +165,65 @@
     return BLE_ERROR_NONE;
 }
 
+ble_error_t
+btle_setLinkSecurity(Gap::Handle_t connectionHandle, SecurityManager::SecurityMode_t securityMode)
+{
+    // use default and updated parameters as starting point
+    // and modify structure based on security mode.
+    ble_gap_sec_params_t params = securityParameters;
+
+    switch (securityMode) {
+        case SecurityManager::SECURITY_MODE_ENCRYPTION_OPEN_LINK:
+            /**< Require no protection, open link. */
+            securityParameters.bond = false;
+            securityParameters.mitm = false;
+            break;
+
+        case SecurityManager::SECURITY_MODE_ENCRYPTION_NO_MITM:
+            /**< Require encryption, but no MITM protection. */
+            securityParameters.bond = true;
+            securityParameters.mitm = false;
+            break;
+
+        // not yet implemented security modes
+        case SecurityManager::SECURITY_MODE_NO_ACCESS:
+        case SecurityManager::SECURITY_MODE_ENCRYPTION_WITH_MITM:
+            /**< Require encryption and MITM protection. */
+        case SecurityManager::SECURITY_MODE_SIGNED_NO_MITM:
+            /**< Require signing or encryption, but no MITM protection. */
+        case SecurityManager::SECURITY_MODE_SIGNED_WITH_MITM:
+            /**< Require signing or encryption, and MITM protection. */
+        default:
+            return BLE_ERROR_NOT_IMPLEMENTED;
+    }
+
+    // update security settings for given connection
+    uint32_t result = sd_ble_gap_authenticate(connectionHandle, &params);
+
+    if (result == NRF_SUCCESS) {
+        return BLE_ERROR_NONE;
+    } else {
+        return BLE_ERROR_UNSPECIFIED;
+    }
+}
+
 ret_code_t
 dm_handler(dm_handle_t const *p_handle, dm_event_t const *p_event, ret_code_t event_result)
 {
+    nRF5xn               &ble             = nRF5xn::Instance(BLE::DEFAULT_INSTANCE);
+    nRF5xSecurityManager &securityManager = (nRF5xSecurityManager &) ble.getSecurityManager();
+
     switch (p_event->event_id) {
         case DM_EVT_SECURITY_SETUP: /* started */ {
             const ble_gap_sec_params_t *peerParams = &p_event->event_param.p_gap_param->params.sec_params_request.peer_params;
-            nRF5xSecurityManager::getInstance().processSecuritySetupInitiatedEvent(p_event->event_param.p_gap_param->conn_handle,
+            securityManager.processSecuritySetupInitiatedEvent(p_event->event_param.p_gap_param->conn_handle,
                                                                                    peerParams->bond,
                                                                                    peerParams->mitm,
                                                                                    (SecurityManager::SecurityIOCapabilities_t)peerParams->io_caps);
             break;
         }
         case DM_EVT_SECURITY_SETUP_COMPLETE:
-            nRF5xSecurityManager::getInstance().
+            securityManager.
                 processSecuritySetupCompletedEvent(p_event->event_param.p_gap_param->conn_handle,
                                                    (SecurityManager::SecurityCompletionStatus_t)(p_event->event_param.p_gap_param->params.auth_status.auth_status));
             break;
@@ -195,15 +257,60 @@
                     break;
             }
 
-            nRF5xSecurityManager::getInstance().processLinkSecuredEvent(p_event->event_param.p_gap_param->conn_handle, resolvedSecurityMode);
+            securityManager.processLinkSecuredEvent(p_event->event_param.p_gap_param->conn_handle, resolvedSecurityMode);
             break;
         }
         case DM_EVT_DEVICE_CONTEXT_STORED:
-            nRF5xSecurityManager::getInstance().processSecurityContextStoredEvent(p_event->event_param.p_gap_param->conn_handle);
+            securityManager.processSecurityContextStoredEvent(p_event->event_param.p_gap_param->conn_handle);
             break;
         default:
             break;
     }
 
     return NRF_SUCCESS;
+}
+
+ble_error_t
+btle_createWhitelistFromBondTable(ble_gap_whitelist_t *p_whitelist)
+{
+    if (!btle_hasInitializedSecurity()) {
+        return BLE_ERROR_INITIALIZATION_INCOMPLETE;
+    }
+    ret_code_t err = dm_whitelist_create(&applicationInstance, p_whitelist);
+    if (err == NRF_SUCCESS) {
+        return BLE_ERROR_NONE;
+    } else if (err == NRF_ERROR_NULL) {
+        return BLE_ERROR_PARAM_OUT_OF_RANGE;
+    } else {
+        return BLE_ERROR_INVALID_STATE;
+    }
+}
+
+
+bool
+btle_matchAddressAndIrk(ble_gap_addr_t const * p_addr, ble_gap_irk_t const * p_irk)
+{
+    /*
+     * Use a helper function from the Nordic SDK to test whether the BLE
+     * address can be generated using the IRK.
+     */
+    return im_address_resolve(p_addr, p_irk);
+}
+
+void
+btle_generateResolvableAddress(const ble_gap_irk_t &irk, ble_gap_addr_t &address)
+{
+    /* Set type to resolvable */
+    address.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE;
+
+    /*
+     * Assign a random number to the most significant 3 bytes
+     * of the address.
+     */
+    address.addr[BLE_GAP_ADDR_LEN - 3] = 0x8E;
+    address.addr[BLE_GAP_ADDR_LEN - 2] = 0x4F;
+    address.addr[BLE_GAP_ADDR_LEN - 1] = 0x7C;
+
+    /* Calculate the hash and store it in the top half of the address */
+    ah(irk.irk, &address.addr[BLE_GAP_ADDR_LEN - 3], address.addr);
 }
\ No newline at end of file
--- a/source/btle/btle_security.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/btle/btle_security.h	Wed Apr 06 22:39:17 2016 +0100
@@ -21,6 +21,15 @@
 #include "ble/SecurityManager.h"
 
 /**
+ * Function to test whether the SecurityManager has been initialized.
+ * Possible by a call to @ref btle_initializeSecurity().
+ *
+ * @return True if the SecurityManager was previously initialized, false
+ *         otherwise.
+ */
+bool btle_hasInitializedSecurity(void);
+
+/**
  * Enable Nordic's Device Manager, which brings in functionality from the
  * stack's Security Manager. The Security Manager implements the actual
  * cryptographic algorithms and protocol exchanges that allow two devices to
@@ -48,11 +57,24 @@
  * @param[out] securityStatusP
  *               security status.
  *
- * @return BLE_SUCCESS Or appropriate error code indicating reason for failure.
+ * @return BLE_ERROR_NONE Or appropriate error code indicating reason for failure.
  */
 ble_error_t btle_getLinkSecurity(Gap::Handle_t connectionHandle, SecurityManager::LinkSecurityStatus_t *securityStatusP);
 
 /**
+ * Set the security mode on a connection. Useful for elevating the security mode
+ * once certain conditions are met, e.g., a particular service is found.
+ *
+ * @param[in]  connectionHandle
+ *               Handle to identify the connection.
+ * @param[in]  securityMode
+ *               security mode.
+ *
+ * @return BLE_ERROR_NONE Or appropriate error code indicating reason for failure.
+ */
+ble_error_t btle_setLinkSecurity(Gap::Handle_t connectionHandle, SecurityManager::SecurityMode_t securityMode);
+
+/**
  * Function for deleting all peer device context and all related bonding
  * information from the database.
  *
@@ -62,4 +84,45 @@
  */
 ble_error_t btle_purgeAllBondingState(void);
 
+/**
+ * Query the SoftDevice bond table to extract a whitelist containing the BLE
+ * addresses and IRKs of bonded devices.
+ *
+ * @param[in/out]  p_whitelist
+ *                  (on input) p_whitelist->addr_count and
+ *                  p_whitelist->irk_count specify the maximum number of
+ *                  addresses and IRKs added to the whitelist structure.
+ *                  (on output) *p_whitelist is a whitelist containing the
+ *                  addresses and IRKs of the bonded devices.
+ *
+ * @return BLE_ERROR_NONE Or appropriate error code indicating reason for failure.
+ */
+ble_error_t btle_createWhitelistFromBondTable(ble_gap_whitelist_t *p_whitelist);
+
+/**
+ * Function to test whether a BLE address is generated using an IRK.
+ *
+ * @param[in]   p_addr
+ *                  Pointer to a BLE address.
+ * @param[in]   p_irk
+ *                  Pointer to an IRK.
+ *
+ * @return True if p_addr can be generated using p_irk, false otherwise.
+ */
+bool btle_matchAddressAndIrk(ble_gap_addr_t const * p_addr, ble_gap_irk_t const * p_irk);
+
+/**
+ * Function to generate a private resolvable BLE address.
+ *
+ * @param[out]  p_addr
+ *                  The output address.
+ * @param[in]   p_irk
+ *                  A reference to a IRK.
+ *
+ * @note This function does not generate a secure address since the prand number in the
+ *       resolvable address is not truly random. Therefore, the output of this function
+ *       is only meant to be used by the application internally but never exported.
+ */
+void btle_generateResolvableAddress(const ble_gap_irk_t &irk, ble_gap_addr_t &address);
+
 #endif /* _BTLE_SECURITY_H_ */
\ No newline at end of file
--- a/source/btle/custom/custom_helper.cpp	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/btle/custom/custom_helper.cpp	Wed Apr 06 22:39:17 2016 +0100
@@ -148,9 +148,8 @@
     ble_uuid128_t base_uuid;
     uint8_t       uuid_type = 0;
 
-    /* Reverse the bytes since ble_uuid128_t is LSB */
     for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
-        base_uuid.uuid128[i] = p_uuid_base[UUID::LENGTH_OF_LONG_UUID - 1 - i];
+        base_uuid.uuid128[i] = p_uuid_base[i];
     }
 
     ASSERT_INT( ERROR_NONE, sd_ble_uuid_vs_add( &base_uuid, &uuid_type ), 0);
@@ -168,9 +167,8 @@
 {
     UUID::LongUUIDBytes_t uuid_base_le;
 
-    /* Reverse the bytes since ble_uuid128_t is LSB */
     for (uint8_t i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
-        uuid_base_le[i] = p_uuid_base[UUID::LENGTH_OF_LONG_UUID - 1 - i];
+        uuid_base_le[i] = p_uuid_base[i];
     }
 
     ASSERT_STATUS( sd_ble_uuid_decode(UUID::LENGTH_OF_LONG_UUID, uuid_base_le, p_uuid));
@@ -191,6 +189,8 @@
     @param[in]  char_props        The characteristic properties, as
                                   defined by ble_gatt_char_props_t
     @param[in]  max_length        The maximum length of this characeristic
+    @param[in]  has_variable_len  Whether the characteristic data has
+                                  variable length.
     @param[out] p_char_handle
 
     @returns
@@ -202,8 +202,9 @@
                                      uint8_t                   properties,
                                      SecurityManager::SecurityMode_t       requiredSecurity,
                                      uint8_t                  *p_data,
-                                     uint16_t                  min_length,
+                                     uint16_t                  length,
                                      uint16_t                  max_length,
+                                     bool                      has_variable_len,
                                      const uint8_t            *userDescriptionDescriptorValuePtr,
                                      uint16_t                  userDescriptionDescriptorValueLen,
                                      bool                      readAuthorization,
@@ -221,8 +222,27 @@
         memclr_( &cccd_md, sizeof(ble_gatts_attr_md_t));
         cccd_md.vloc = BLE_GATTS_VLOC_STACK;
         BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
-        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
-    }
+		switch (requiredSecurity) {
+			case SecurityManager::SECURITY_MODE_ENCRYPTION_OPEN_LINK :
+				BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
+				break;
+			case SecurityManager::SECURITY_MODE_ENCRYPTION_NO_MITM :
+				BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&cccd_md.write_perm);
+				break;
+			case SecurityManager::SECURITY_MODE_ENCRYPTION_WITH_MITM :
+				BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(&cccd_md.write_perm);
+				break;
+			case SecurityManager::SECURITY_MODE_SIGNED_NO_MITM :
+				BLE_GAP_CONN_SEC_MODE_SET_SIGNED_NO_MITM(&cccd_md.write_perm);
+				break;
+			case SecurityManager::SECURITY_MODE_SIGNED_WITH_MITM :
+				BLE_GAP_CONN_SEC_MODE_SET_SIGNED_WITH_MITM(&cccd_md.write_perm);
+				break;
+			default:
+				BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
+				break;
+		}
+	}
 
     ble_gatts_char_md_t char_md = {0};
 
@@ -242,7 +262,8 @@
     attr_md.wr_auth = writeAuthorization;
 
     attr_md.vloc = BLE_GATTS_VLOC_STACK;
-    attr_md.vlen = (min_length == max_length) ? 0 : 1;
+    /* Always set variable size */
+    attr_md.vlen = has_variable_len;
 
     if (char_props.read || char_props.notify || char_props.indicate) {
         switch (requiredSecurity) {
@@ -292,7 +313,7 @@
 
     attr_char_value.p_uuid    = p_uuid;
     attr_char_value.p_attr_md = &attr_md;
-    attr_char_value.init_len  = min_length;
+    attr_char_value.init_len  = length;
     attr_char_value.max_len   = max_length;
     attr_char_value.p_value   = p_data;
 
@@ -317,23 +338,27 @@
                                   since 1 is typically used by the primary
                                   service).
     @param[in]  max_length        The maximum length of this descriptor
+    @param[in]  has_variable_len  Whether the characteristic data has
+                                  variable length.
 
     @returns
     @retval     ERROR_NONE        Everything executed normally
 */
 /**************************************************************************/
 error_t custom_add_in_descriptor(uint16_t    char_handle,
-                                             ble_uuid_t *p_uuid,
-                                             uint8_t    *p_data,
-                                             uint16_t    min_length,
-                                             uint16_t    max_length,
-                                             uint16_t   *p_desc_handle)
+                                 ble_uuid_t *p_uuid,
+                                 uint8_t    *p_data,
+                                 uint16_t    length,
+                                 uint16_t    max_length,
+                                 bool        has_variable_len,
+                                 uint16_t   *p_desc_handle)
 {
     /* Descriptor metadata */
     ble_gatts_attr_md_t   desc_md = {0};
 
     desc_md.vloc = BLE_GATTS_VLOC_STACK;
-    desc_md.vlen = (min_length == max_length) ? 0 : 1;
+    /* Always set variable size */
+    desc_md.vlen = has_variable_len;
 
     /* Make it readable and writable */
     BLE_GAP_CONN_SEC_MODE_SET_OPEN(&desc_md.read_perm);
@@ -343,7 +368,7 @@
 
     attr_desc.p_uuid    = p_uuid;
     attr_desc.p_attr_md = &desc_md;
-    attr_desc.init_len  = min_length;
+    attr_desc.init_len  = length;
     attr_desc.max_len   = max_length;
     attr_desc.p_value   = p_data;
 
--- a/source/btle/custom/custom_helper.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/btle/custom/custom_helper.h	Wed Apr 06 22:39:17 2016 +0100
@@ -36,8 +36,9 @@
                                      uint8_t                   properties,
                                      SecurityManager::SecurityMode_t requiredSecurity,
                                      uint8_t                  *p_data,
-                                     uint16_t                  min_length,
+                                     uint16_t                  length,
                                      uint16_t                  max_length,
+                                     bool                      has_variable_len,
                                      const uint8_t            *userDescriptionDescriptorValuePtr,
                                      uint16_t                  userDescriptionDescriptorValueLen,
                                      bool                      readAuthorization,
@@ -47,8 +48,9 @@
 error_t custom_add_in_descriptor(uint16_t                      char_handle,
                                      ble_uuid_t               *p_uuid,
                                      uint8_t                  *p_data,
-                                     uint16_t                  min_length,
+                                     uint16_t                  length,
                                      uint16_t                  max_length,
+                                     bool                      has_variable_len,
                                      uint16_t                 *p_desc_handle);
 
 #ifdef __cplusplus
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/nRF5xCharacteristicDescriptorDiscoverer.cpp	Wed Apr 06 22:39:17 2016 +0100
@@ -0,0 +1,235 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2015 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 "nRF5xCharacteristicDescriptorDiscoverer.h"
+#include "ble_err.h"
+#include "ble/DiscoveredCharacteristicDescriptor.h"
+
+nRF5xCharacteristicDescriptorDiscoverer::nRF5xCharacteristicDescriptorDiscoverer() :
+    discoveryRunning() {
+    // nothing to do
+}
+
+nRF5xCharacteristicDescriptorDiscoverer::~nRF5xCharacteristicDescriptorDiscoverer() {
+    // nothing to do
+}
+
+ble_error_t nRF5xCharacteristicDescriptorDiscoverer::launch(
+    const DiscoveredCharacteristic& characteristic,
+    const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
+    const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback
+) {
+    Gap::Handle_t connHandle = characteristic.getConnectionHandle();
+    // it is ok to deduce that the start handle for descriptors is after
+    // the characteristic declaration and the characteristic value declaration
+    // see BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part G] (3.3)
+    Gap::Handle_t descriptorStartHandle = characteristic.getDeclHandle() + 2;
+    Gap::Handle_t descriptorEndHandle = characteristic.getLastHandle();
+
+    // check if there is any descriptor to discover
+    if (descriptorEndHandle < descriptorStartHandle) {
+        CharacteristicDescriptorDiscovery::TerminationCallbackParams_t termParams = {
+            characteristic,
+            BLE_ERROR_NONE
+        };
+        terminationCallback.call(&termParams);
+        return BLE_ERROR_NONE;
+    }
+
+    // check if we can run this discovery
+    if (isConnectionInUse(connHandle)) {
+        return BLE_STACK_BUSY;
+    }
+
+    // get a new discovery slot, if none are available, just return
+    Discovery* discovery = getAvailableDiscoverySlot();
+    if(discovery == NULL) {
+        return BLE_STACK_BUSY;
+    }
+
+    // try to launch the discovery
+    ble_error_t err = gattc_descriptors_discover(connHandle, descriptorStartHandle, descriptorEndHandle);
+    if(!err) {
+        // commit the new discovery to its slot
+        *discovery = Discovery(characteristic, discoveryCallback, terminationCallback);
+    }
+
+    return err;
+}
+
+bool nRF5xCharacteristicDescriptorDiscoverer::isActive(const DiscoveredCharacteristic& characteristic) const {
+    for(size_t i = 0; i < MAXIMUM_CONCURRENT_CONNECTIONS_COUNT; ++i) {
+        if(discoveryRunning[i].getCharacteristic() == characteristic) {
+            return true;
+        }
+    }
+    return false;
+}
+
+void nRF5xCharacteristicDescriptorDiscoverer::requestTerminate(const DiscoveredCharacteristic& characteristic) {
+    Discovery* discovery = findRunningDiscovery(characteristic);
+    if(discovery) {
+        // call terminate anyway
+        terminate(discovery, BLE_ERROR_NONE);
+    }
+}
+
+void nRF5xCharacteristicDescriptorDiscoverer::process(uint16_t connectionHandle, const ble_gattc_evt_desc_disc_rsp_t& descriptors) {
+    Discovery* discovery = findRunningDiscovery(connectionHandle);
+    // the discovery has been removed
+    if(!discovery) {
+        return;
+    }
+
+    for (uint16_t i = 0; i < descriptors.count; ++i) {
+        discovery->process(
+            descriptors.descs[i].handle, UUID(descriptors.descs[i].uuid.uuid)
+        );
+    }
+
+    // prepare the next discovery request (if needed)
+    uint16_t startHandle = descriptors.descs[descriptors.count - 1].handle + 1;
+    uint16_t endHandle = discovery->getCharacteristic().getLastHandle();
+
+    if(startHandle > endHandle) {
+        terminate(discovery, BLE_ERROR_NONE);
+        return;
+    }
+
+    ble_error_t err = gattc_descriptors_discover(connectionHandle, startHandle, endHandle);
+    if(err) {
+        terminate(discovery, err);
+        return;
+    }
+}
+
+void nRF5xCharacteristicDescriptorDiscoverer::terminate(uint16_t handle, ble_error_t err) {
+    Discovery* discovery = findRunningDiscovery(handle);
+    // the discovery has already been terminated
+    if(!discovery) {
+        return;
+    }
+
+    terminate(discovery, err);
+}
+
+void nRF5xCharacteristicDescriptorDiscoverer::terminate(Discovery* discovery, ble_error_t err) {
+    // temporary copy, user code can try to launch a new discovery in the onTerminate
+    // callback. So, this discovery should not appear in such case.
+    Discovery tmp = *discovery;
+    *discovery = Discovery();
+    tmp.terminate(err);
+}
+
+nRF5xCharacteristicDescriptorDiscoverer::Discovery*
+nRF5xCharacteristicDescriptorDiscoverer::findRunningDiscovery(const DiscoveredCharacteristic& characteristic) {
+    for(size_t i = 0; i < MAXIMUM_CONCURRENT_CONNECTIONS_COUNT; ++i) {
+        if((discoveryRunning[i].getCharacteristic() == characteristic) &&
+           (discoveryRunning[i].isEmpty() == false)) {
+            return &discoveryRunning[i];
+        }
+    }
+    return NULL;
+}
+
+nRF5xCharacteristicDescriptorDiscoverer::Discovery*
+nRF5xCharacteristicDescriptorDiscoverer::findRunningDiscovery(uint16_t handle) {
+    for(size_t i = 0; i < MAXIMUM_CONCURRENT_CONNECTIONS_COUNT; ++i) {
+        if((discoveryRunning[i].getCharacteristic().getConnectionHandle() == handle) &&
+           (discoveryRunning[i].isEmpty() == false)) {
+            return &discoveryRunning[i];
+        }
+    }
+    return NULL;
+}
+
+nRF5xCharacteristicDescriptorDiscoverer::Discovery*
+nRF5xCharacteristicDescriptorDiscoverer::getAvailableDiscoverySlot() {
+    for(size_t i = 0; i < MAXIMUM_CONCURRENT_CONNECTIONS_COUNT; ++i) {
+        if(discoveryRunning[i].isEmpty()) {
+            return &discoveryRunning[i];
+        }
+    }
+    return NULL;
+}
+
+bool nRF5xCharacteristicDescriptorDiscoverer::isConnectionInUse(uint16_t connHandle) {
+     return findRunningDiscovery(connHandle) != NULL;
+}
+
+ble_error_t nRF5xCharacteristicDescriptorDiscoverer::gattc_descriptors_discover(
+    uint16_t connection_handle, uint16_t start_handle, uint16_t end_handle) {
+
+    ble_gattc_handle_range_t discoveryRange = {
+        start_handle,
+        end_handle
+    };
+    uint32_t err = sd_ble_gattc_descriptors_discover(connection_handle, &discoveryRange);
+
+    switch(err) {
+        case NRF_SUCCESS:
+            return BLE_ERROR_NONE;
+        case BLE_ERROR_INVALID_CONN_HANDLE:
+            return BLE_ERROR_INVALID_PARAM;
+        case NRF_ERROR_INVALID_ADDR:
+            return BLE_ERROR_PARAM_OUT_OF_RANGE;
+        case NRF_ERROR_BUSY:
+            return BLE_STACK_BUSY;
+        default:
+            return BLE_ERROR_UNSPECIFIED;
+    }
+}
+
+// implementation of nRF5xCharacteristicDescriptorDiscoverer::Discovery
+
+nRF5xCharacteristicDescriptorDiscoverer::Discovery::Discovery() :
+    characteristic(), onDiscovery(), onTerminate() {
+}
+
+nRF5xCharacteristicDescriptorDiscoverer::Discovery::Discovery(
+    const DiscoveredCharacteristic& c, const DiscoveryCallback_t& dCb, const TerminationCallback_t& tCb) :
+    characteristic(c), onDiscovery(dCb), onTerminate(tCb) {
+}
+
+void nRF5xCharacteristicDescriptorDiscoverer::Discovery::process(
+    GattAttribute::Handle_t handle, const UUID& uuid) {
+    CharacteristicDescriptorDiscovery::DiscoveryCallbackParams_t params = {
+        characteristic,
+        DiscoveredCharacteristicDescriptor(
+            characteristic.getGattClient(),
+            characteristic.getConnectionHandle(),
+            handle,
+            uuid
+        )
+    };
+    onDiscovery.call(&params);
+}
+
+void nRF5xCharacteristicDescriptorDiscoverer::Discovery::terminate(ble_error_t err) {
+    CharacteristicDescriptorDiscovery::TerminationCallbackParams_t params = {
+        characteristic,
+        err
+    };
+
+    onTerminate.call(&params);
+}
+
+bool nRF5xCharacteristicDescriptorDiscoverer::Discovery::isEmpty() const {
+    return *this == Discovery();
+}
+
+const DiscoveredCharacteristic& nRF5xCharacteristicDescriptorDiscoverer::Discovery::getCharacteristic() const {
+    return characteristic;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/nRF5xCharacteristicDescriptorDiscoverer.h	Wed Apr 06 22:39:17 2016 +0100
@@ -0,0 +1,214 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2015 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.
+ */
+
+#ifndef __NRF_CHARACTERISTIC_DESCRIPTOR_DISCOVERY_H__
+#define __NRF_CHARACTERISTIC_DESCRIPTOR_DISCOVERY_H__
+
+#include "ble/Gap.h"
+#include "ble/DiscoveredCharacteristic.h"
+#include "ble/CharacteristicDescriptorDiscovery.h"
+#include "ble/GattClient.h"
+#include "ble_gattc.h"
+
+/**
+ * @brief Manage the discovery of Characteristic descriptors
+ * @details is a bridge between BLE API and Nordic stack regarding Characteristic
+ * Descriptor discovery. The BLE API can launch, monitor and ask for termination
+ * of a discovery. The Nordic stack will provide new descriptors and indicate when
+ * the discovery is done.
+ */
+class nRF5xCharacteristicDescriptorDiscoverer
+{
+    typedef CharacteristicDescriptorDiscovery::DiscoveryCallback_t DiscoveryCallback_t;
+    typedef CharacteristicDescriptorDiscovery::TerminationCallback_t TerminationCallback_t;
+
+public:
+    /**
+     * @brief Construct a new characteristic descriptor discoverer.
+     */
+    nRF5xCharacteristicDescriptorDiscoverer();
+
+    /**
+     * @brief Destroy a characteristic descriptor discoverer.
+     */
+    ~nRF5xCharacteristicDescriptorDiscoverer();
+
+    /**
+     * Launch a new characteristic descriptor discovery for a given DiscoveredCharacteristic.
+     * @param characteristic The characteristic owning the descriptors to discover.
+     * @param discoveryCallback The callback called when a descriptor is discovered.
+     * @param terminationCallback The callback called when the discovery process end.
+     * @return BLE_ERROR_NONE if characteristic descriptor discovery is launched successfully;
+     *         else an appropriate error.
+     * @note: this will be called by BLE API side.
+     */
+    ble_error_t launch(
+        const DiscoveredCharacteristic& characteristic,
+        const DiscoveryCallback_t& discoveryCallback,
+        const TerminationCallback_t& terminationCallback
+    );
+
+    /**
+     * @brief indicate if a characteristic descriptor discovery is active for a
+     * given DiscoveredCharacteristic.
+     * @param characteristic The characteristic for whom the descriptor might be
+     * currently discovered.
+     * @return true if descriptors of characteristic are discovered, false otherwise.
+     * @note: this will be called by BLE API side.
+     */
+    bool isActive(const DiscoveredCharacteristic& characteristic) const;
+
+    /**
+     * @brief request the termination of characteristic descriptor discovery
+     * for a give DiscoveredCharacteristic
+     * @param characteristic The characteristic for whom the descriptor discovery
+     * should be stopped.
+     * @note: this will be called by BLE API side.
+     */
+    void requestTerminate(const DiscoveredCharacteristic& characteristic);
+
+    /**
+     * @brief process descriptors discovered from the Nordic stack.
+     * @param connectionHandle The connection handle upon which descriptors has been
+     * discovered.
+     * @param descriptors Discovered descriptors.
+     * @note This will be called by the Nordic stack.
+     */
+    void process(uint16_t connectionHandle, const ble_gattc_evt_desc_disc_rsp_t& descriptors);
+
+    /**
+     * @brief Called by the Nordic stack when the discovery is over.
+     * @param The connection handle upon which the discovery process is done.
+     * @param err An error if the termination is due to an error.
+     */
+    void terminate(uint16_t connectionHandle, ble_error_t err);
+
+private:
+    // protection against copy construction and assignment
+    nRF5xCharacteristicDescriptorDiscoverer(const nRF5xCharacteristicDescriptorDiscoverer&);
+    nRF5xCharacteristicDescriptorDiscoverer& operator=(const nRF5xCharacteristicDescriptorDiscoverer&);
+
+    /**
+     * @brief Discovery process, it store the DiscoveredCharacteristic, the
+     * discovery callback and the termination callback.
+     */
+    class Discovery {
+    public:
+        /**
+         * @brief Construct an empty discovery, such can be considerate as a not running discovery.
+         * @note #isEmpty function will return true
+         */
+        Discovery();
+
+        /**
+         * @brief Construct a valid discovery process.
+         *
+         * @param c the characteristic from whom descriptors will be discovered.
+         * @param dCb The discovery callback called each time a descriptor is discovered.
+         * @param tCb The termination callback called when the discovery terminate.
+         *
+         * @note #isEmpty function will return false
+         */
+        Discovery(const DiscoveredCharacteristic& c, const DiscoveryCallback_t& dCb, const TerminationCallback_t& tCb);
+
+        /**
+         * @brief Process the discovery of a descriptor.
+         *
+         * @param handle The attribute handle of the descriptor found
+         * @param uuid The UUID of the descriptor found.
+         */
+        void process(GattAttribute::Handle_t handle, const UUID& uuid);
+
+        /**
+         * @brief Terminate the discovery process.
+         *
+         * @param err Error associate with the termination
+         * @note after this call #isEmpty function will return true.
+         */
+        void terminate(ble_error_t err);
+
+        /**
+         * @brief check if the discovery process is empty or not. Empty discovery are
+         * not running.
+         *
+         * @detail Discovery are empty after:
+         *     - a default construction
+         *     - a copy construction form a default constructed
+         *     - an assignment from a default constructed Discovery
+         * @return true if the Discovery is empty and false otherwise.
+         */
+        bool isEmpty() const;
+
+        /**
+         * @brief return the characteristic from whom descriptors are discovered.
+         * @return the characteristic from whom descriptors are discovered.
+         */
+        const DiscoveredCharacteristic& getCharacteristic() const;
+
+        /**
+         * @brief equal to operator, test if two discovery process are equal
+         *
+         * @param lhs left hand side of the expression
+         * @param rhs right hand side of the expression
+         * @return true if lhs == rhs
+         */
+        friend bool operator==(const Discovery& lhs, const Discovery& rhs) {
+            return lhs.characteristic == rhs.characteristic &&
+                   lhs.onDiscovery == rhs.onDiscovery &&
+                   lhs.onTerminate == rhs.onTerminate;
+        }
+
+        /**
+         * @brief not equal to operator, test if two discovery process are not equal
+         *
+         * @param lhs left hand side of the expression
+         * @param rhs right hand side of the expression
+         * @return true if lhs != rhs
+         */
+        friend bool operator!=(const Discovery& lhs, const Discovery& rhs) {
+            return !(lhs == rhs);
+        }
+
+    private:
+        DiscoveredCharacteristic characteristic;
+        DiscoveryCallback_t onDiscovery;
+        TerminationCallback_t onTerminate;
+    };
+
+    // find a running discovery process
+    Discovery* findRunningDiscovery(const DiscoveredCharacteristic& characteristic);
+    Discovery* findRunningDiscovery(uint16_t handle);
+
+    // Called to terminate a discovery is over.
+    void terminate(Discovery* discovery, ble_error_t err);
+
+    // get one slot for a discovery process
+    Discovery* getAvailableDiscoverySlot();
+
+    // indicate if a connection is already running a discovery
+    bool isConnectionInUse(uint16_t connHandle);
+
+    // low level start of a discovery
+    static ble_error_t gattc_descriptors_discover(uint16_t connection_handle, uint16_t start_handle, uint16_t end_handle);
+
+    // count of concurrent connections which can run a descriptor discovery process
+    static const size_t MAXIMUM_CONCURRENT_CONNECTIONS_COUNT = 3;
+
+    // array of running discoveries
+    Discovery discoveryRunning[MAXIMUM_CONCURRENT_CONNECTIONS_COUNT];
+};
+
+#endif /*__NRF_CHARACTERISTIC_DESCRIPTOR_DISCOVERY_H__*/
\ No newline at end of file
--- a/source/nRF5xDiscoveredCharacteristic.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nRF5xDiscoveredCharacteristic.h	Wed Apr 06 22:39:17 2016 +0100
@@ -36,6 +36,10 @@
                ble_gatt_char_props_t    propsIn,
                GattAttribute::Handle_t  declHandleIn,
                GattAttribute::Handle_t  valueHandleIn);
+
+    void setLastHandle(GattAttribute::Handle_t last) {
+      lastHandle = last;
+    }
 };
 
 #endif /* __NRF_DISCOVERED_CHARACTERISTIC_H__ */
\ No newline at end of file
--- a/source/nRF5xGap.cpp	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nRF5xGap.cpp	Wed Apr 06 22:39:17 2016 +0100
@@ -14,20 +14,21 @@
  * limitations under the License.
  */
 
-#include "nRF5xGap.h"
-#include "mbed.h"
+#include "nRF5xn.h"
+#ifdef YOTTA_CFG_MBED_OS
+    #include "mbed-drivers/mbed.h"
+#else
+    #include "mbed.h"
+#endif
+#include "ble/BLE.h"
 
 #include "common/common.h"
 #include "ble_advdata.h"
 #include "ble_hci.h"
 
-nRF5xGap &nRF5xGap::getInstance() {
-    static nRF5xGap m_instance;
-    return m_instance;
-}
-
 void radioNotificationStaticCallback(bool param) {
-    nRF5xGap::getInstance().processRadioNotificationEvent(param);
+    nRF5xGap &gap = (nRF5xGap &) nRF5xn::Instance(BLE::DEFAULT_INSTANCE).getGap();
+    gap.processRadioNotificationEvent(param);
 }
 
 /**************************************************************************/
@@ -167,13 +168,31 @@
         return BLE_ERROR_PARAM_OUT_OF_RANGE;
     }
 
+    /* Allocate the stack's whitelist statically */
+    ble_gap_whitelist_t  whitelist;
+    ble_gap_addr_t      *whitelistAddressPtrs[YOTTA_CFG_WHITELIST_MAX_SIZE];
+    ble_gap_irk_t       *whitelistIrkPtrs[YOTTA_CFG_IRK_TABLE_MAX_SIZE];
+    /* Initialize the whitelist */
+    whitelist.pp_addrs   = whitelistAddressPtrs;
+    whitelist.pp_irks    = whitelistIrkPtrs;
+    whitelist.addr_count = 0;
+    whitelist.irk_count  = 0;
+
+    /* Add missing IRKs to whitelist from the bond table held by the SoftDevice */
+    if (advertisingPolicyMode != Gap::ADV_POLICY_IGNORE_WHITELIST) {
+        ble_error_t error = generateStackWhitelist(whitelist);
+        if (error != BLE_ERROR_NONE) {
+            return error;
+        }
+    }
+
     /* Start Advertising */
     ble_gap_adv_params_t adv_para = {0};
 
     adv_para.type        = params.getAdvertisingType();
     adv_para.p_peer_addr = NULL;                           // Undirected advertisement
-    adv_para.fp          = BLE_GAP_ADV_FP_ANY;
-    adv_para.p_whitelist = NULL;
+    adv_para.fp          = advertisingPolicyMode;
+    adv_para.p_whitelist = &whitelist;
     adv_para.interval    = params.getIntervalInADVUnits(); // advertising interval (in units of 0.625 ms)
     adv_para.timeout     = params.getTimeout();
 
@@ -184,6 +203,53 @@
     return BLE_ERROR_NONE;
 }
 
+/* Observer role is not supported by S110, return BLE_ERROR_NOT_IMPLEMENTED */
+#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
+ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams)
+{
+    /* Allocate the stack's whitelist statically */
+    ble_gap_whitelist_t  whitelist;
+    ble_gap_addr_t      *whitelistAddressPtrs[YOTTA_CFG_WHITELIST_MAX_SIZE];
+    ble_gap_irk_t       *whitelistIrkPtrs[YOTTA_CFG_IRK_TABLE_MAX_SIZE];
+    /* Initialize the whitelist */
+    whitelist.pp_addrs   = whitelistAddressPtrs;
+    whitelist.pp_irks    = whitelistIrkPtrs;
+    whitelist.addr_count = 0;
+    whitelist.irk_count  = 0;
+
+    /* Add missing IRKs to whitelist from the bond table held by the SoftDevice */
+    if (scanningPolicyMode != Gap::SCAN_POLICY_IGNORE_WHITELIST) {
+        ble_error_t error = generateStackWhitelist(whitelist);
+        if (error != BLE_ERROR_NONE) {
+            return error;
+        }
+    }
+
+    ble_gap_scan_params_t scanParams = {
+        .active      = scanningParams.getActiveScanning(), /**< If 1, perform active scanning (scan requests). */
+        .selective   = scanningPolicyMode,    /**< If 1, ignore unknown devices (non whitelisted). */
+        .p_whitelist = &whitelist, /**< Pointer to whitelist, NULL if none is given. */
+        .interval    = scanningParams.getInterval(),  /**< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
+        .window      = scanningParams.getWindow(),    /**< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
+        .timeout     = scanningParams.getTimeout(),   /**< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */
+    };
+
+    if (sd_ble_gap_scan_start(&scanParams) != NRF_SUCCESS) {
+        return BLE_ERROR_PARAM_OUT_OF_RANGE;
+    }
+
+    return BLE_ERROR_NONE;
+}
+
+ble_error_t nRF5xGap::stopScan(void) {
+    if (sd_ble_gap_scan_stop() == NRF_SUCCESS) {
+        return BLE_ERROR_NONE;
+    }
+
+    return BLE_STACK_BUSY;
+}
+#endif
+
 /**************************************************************************/
 /*!
     @brief  Stops the BLE HW and disconnects from any devices
@@ -210,10 +276,10 @@
     return BLE_ERROR_NONE;
 }
 
-ble_error_t nRF5xGap::connect(const Address_t           peerAddr,
-                              Gap::AddressType_t        peerAddrType,
-                              const ConnectionParams_t *connectionParams,
-                              const GapScanningParams  *scanParamsIn)
+ble_error_t nRF5xGap::connect(const Address_t             peerAddr,
+                              BLEProtocol::AddressType_t  peerAddrType,
+                              const ConnectionParams_t   *connectionParams,
+                              const GapScanningParams    *scanParamsIn)
 {
     ble_gap_addr_t addr;
     addr.addr_type = peerAddrType;
@@ -232,9 +298,27 @@
         connParams.conn_sup_timeout  = 600;
     }
 
+    /* Allocate the stack's whitelist statically */
+    ble_gap_whitelist_t  whitelist;
+    ble_gap_addr_t      *whitelistAddressPtrs[YOTTA_CFG_WHITELIST_MAX_SIZE];
+    ble_gap_irk_t       *whitelistIrkPtrs[YOTTA_CFG_IRK_TABLE_MAX_SIZE];
+    /* Initialize the whitelist */
+    whitelist.pp_addrs   = whitelistAddressPtrs;
+    whitelist.pp_irks    = whitelistIrkPtrs;
+    whitelist.addr_count = 0;
+    whitelist.irk_count  = 0;
+
+    /* Add missing IRKs to whitelist from the bond table held by the SoftDevice */
+    if (scanningPolicyMode != Gap::SCAN_POLICY_IGNORE_WHITELIST) {
+        ble_error_t error = generateStackWhitelist(whitelist);
+        if (error != BLE_ERROR_NONE) {
+            return error;
+        }
+    }
+
     ble_gap_scan_params_t scanParams;
-    scanParams.selective   = 0;    /**< If 1, ignore unknown devices (non whitelisted). */
-    scanParams.p_whitelist = NULL; /**< Pointer to whitelist, NULL if none is given. */
+    scanParams.selective   = scanningPolicyMode;    /**< If 1, ignore unknown devices (non whitelisted). */
+    scanParams.p_whitelist = &whitelist; /**< Pointer to whitelist, NULL if none is given. */
     if (scanParamsIn != NULL) {
         scanParams.active      = scanParamsIn->getActiveScanning();   /**< If 1, perform active scanning (scan requests). */
         scanParams.interval    = scanParamsIn->getInterval();         /**< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
@@ -338,6 +422,36 @@
 
 /**************************************************************************/
 /*!
+    @brief  Clear nRF5xGap's state.
+
+    @returns    ble_error_t
+
+    @retval     BLE_ERROR_NONE
+                Everything executed properly
+*/
+/**************************************************************************/
+ble_error_t nRF5xGap::reset(void)
+{
+    /* Clear all state that is from the parent, including private members */
+    if (Gap::reset() != BLE_ERROR_NONE) {
+        return BLE_ERROR_INVALID_STATE;
+    }
+
+    /* Clear derived class members */
+    m_connectionHandle = BLE_CONN_HANDLE_INVALID;
+
+    /* Set the whitelist policy filter modes to IGNORE_WHITELIST */
+    advertisingPolicyMode = Gap::ADV_POLICY_IGNORE_WHITELIST;
+    scanningPolicyMode    = Gap::SCAN_POLICY_IGNORE_WHITELIST;
+
+    /* Clear the internal whitelist */
+    whitelistAddressesSize = 0;
+
+    return BLE_ERROR_NONE;
+}
+
+/**************************************************************************/
+/*!
     @brief  Sets the 16-bit connection handle
 */
 /**************************************************************************/
@@ -367,22 +481,37 @@
     @code
 
     uint8_t device_address[6] = { 0xca, 0xfe, 0xf0, 0xf0, 0xf0, 0xf0 };
-    nrf.getGap().setAddress(Gap::ADDR_TYPE_RANDOM_STATIC, device_address);
+    nrf.getGap().setAddress(Gap::BLEProtocol::AddressType::RANDOM_STATIC, device_address);
 
     @endcode
 */
 /**************************************************************************/
 ble_error_t nRF5xGap::setAddress(AddressType_t type, const Address_t address)
 {
-    if (type > ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE) {
+    uint8_t cycle_mode;
+    ble_gap_addr_t dev_addr;
+
+    /* When using Public or Static addresses, the cycle mode must be None.
+       When using Random Private addresses, the cycle mode must be Auto.
+       In auto mode, the given address is ignored.
+    */
+    if ((type == BLEProtocol::AddressType::PUBLIC) || (type == BLEProtocol::AddressType::RANDOM_STATIC))
+    {
+        cycle_mode = BLE_GAP_ADDR_CYCLE_MODE_NONE;
+        memcpy(dev_addr.addr, address, ADDR_LEN);
+    }
+    else if ((type == BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE) || (type == BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE))
+    {
+        cycle_mode = BLE_GAP_ADDR_CYCLE_MODE_AUTO;
+        // address is ignored when in auto mode
+    }
+    else
+    {
         return BLE_ERROR_PARAM_OUT_OF_RANGE;
     }
 
-    ble_gap_addr_t dev_addr;
     dev_addr.addr_type = type;
-    memcpy(dev_addr.addr, address, ADDR_LEN);
-
-    ASSERT_INT(ERROR_NONE, sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &dev_addr), BLE_ERROR_PARAM_OUT_OF_RANGE);
+    ASSERT_INT(ERROR_NONE, sd_ble_gap_address_set(cycle_mode, &dev_addr), BLE_ERROR_PARAM_OUT_OF_RANGE);
 
     return BLE_ERROR_NONE;
 }
@@ -467,4 +596,343 @@
 
     *valueArrayPP = permittedTxValues;
     *countP = sizeof(permittedTxValues) / sizeof(int8_t);
+}
+
+/**************************************************************************/
+/*!
+    @brief  Get the capacity of the internal whitelist maintained by this
+            implementation.
+
+    @returns    The capacity of the internal whitelist.
+
+    @section EXAMPLE
+
+    @code
+
+    @endcode
+*/
+/**************************************************************************/
+uint8_t nRF5xGap::getMaxWhitelistSize(void) const
+{
+    return YOTTA_CFG_WHITELIST_MAX_SIZE;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Get a copy of the implementation's internal whitelist.
+
+    @param[out] whitelistOut
+                A \ref Gap::Whitelist_t structure containing a copy of the
+                addresses in the implemenetation's internal whitelist.
+
+    @returns    \ref ble_errror_t
+
+    @retval     BLE_ERROR_NONE
+                Everything executed properly.
+
+    @section EXAMPLE
+
+    @code
+
+    @endcode
+*/
+/**************************************************************************/
+ble_error_t nRF5xGap::getWhitelist(Gap::Whitelist_t &whitelistOut) const
+{
+    uint8_t i;
+    for (i = 0; i < whitelistAddressesSize && i < whitelistOut.capacity; ++i) {
+        memcpy(&whitelistOut.addresses[i], &whitelistAddresses[i], sizeof(BLEProtocol::Address_t));
+    }
+    whitelistOut.size = i;
+
+    return BLE_ERROR_NONE;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Set the whitelist that will be used in the next call to
+            startAdvertising().
+
+    @param[in]  whitelistIn
+                A reference to a \ref Gap::Whitelist_t structure
+                representing a whitelist containing all the white listed
+                BLE addresses.
+
+    @returns    \ref ble_errror_t
+
+    @retval     BLE_ERROR_NONE
+                Everything executed properly.
+
+                BLE_ERROR_INVALID_PARAM
+                The supplied whitelist contains a private non-resolvable
+                address
+
+                BLE_ERROR_PARAM_OUT_OF_RANGE
+                The size of the supplied whitelist exceeds the maximum
+                capacity of the implementation's internal whitelist.
+
+    @section EXAMPLE
+
+    @code
+
+    @endcode
+*/
+/**************************************************************************/
+ble_error_t nRF5xGap::setWhitelist(const Gap::Whitelist_t &whitelistIn)
+{
+    if (whitelistIn.size > getMaxWhitelistSize()) {
+        return BLE_ERROR_PARAM_OUT_OF_RANGE;
+    }
+
+    /* Test for invalid parameters before we change the internal state */
+    for (uint8_t i = 0; i < whitelistIn.size; ++i) {
+        if (whitelistIn.addresses[i].type == BLEProtocol::AddressType_t::RANDOM_PRIVATE_NON_RESOLVABLE) {
+            /* This is not allowed because it is completely meaningless */
+            return BLE_ERROR_INVALID_PARAM;
+        }
+    }
+
+    whitelistAddressesSize = 0;
+    for (uint8_t i = 0; i < whitelistIn.size; ++i) {
+        memcpy(&whitelistAddresses[whitelistAddressesSize], &whitelistIn.addresses[i], sizeof(BLEProtocol::Address_t));
+        whitelistAddressesSize++;
+    }
+
+    return BLE_ERROR_NONE;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Set the advertising policy filter mode that will be used in
+            the next call to startAdvertising().
+
+    @returns    \ref ble_errror_t
+
+    @retval     BLE_ERROR_NONE
+                Everything executed properly.
+
+                BLE_ERROR_NOT_IMPLEMENTED
+                This feature is currently note implemented.
+
+    @section EXAMPLE
+
+    @code
+
+    @endcode
+*/
+/**************************************************************************/
+ble_error_t nRF5xGap::setAdvertisingPolicyMode(Gap::AdvertisingPolicyMode_t mode)
+{
+    advertisingPolicyMode = mode;
+
+    return BLE_ERROR_NONE;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Set the scanning policy filter mode that will be used in
+            the next call to startAdvertising().
+
+    @returns    \ref ble_errror_t
+
+    @retval     BLE_ERROR_NONE
+                Everything executed properly.
+
+                BLE_ERROR_NOT_IMPLEMENTED
+                This feature is currently note implemented.
+
+    @section EXAMPLE
+
+    @code
+
+    @endcode
+*/
+/**************************************************************************/
+ble_error_t nRF5xGap::setScanningPolicyMode(Gap::ScanningPolicyMode_t mode)
+{
+    scanningPolicyMode = mode;
+
+    return BLE_ERROR_NONE;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Set the initiator policy filter mode that will be used in
+            the next call to startAdvertising()
+
+    @returns    \ref ble_errror_t
+
+    @retval     BLE_ERROR_NONE
+                Everything executed properly.
+
+                BLE_ERROR_NOT_IMPLEMENTED
+                This feature is currently note implemented.
+
+    @section EXAMPLE
+
+    @code
+
+    @endcode
+*/
+/**************************************************************************/
+ble_error_t nRF5xGap::setInitiatorPolicyMode(Gap::InitiatorPolicyMode_t mode)
+{
+    return BLE_ERROR_NOT_IMPLEMENTED;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Get the current advertising policy filter mode.
+
+    @returns    The advertising policy filter mode.
+
+    @section EXAMPLE
+
+    @code
+
+    @endcode
+*/
+/**************************************************************************/
+Gap::AdvertisingPolicyMode_t nRF5xGap::getAdvertisingPolicyMode(void) const
+{
+    return advertisingPolicyMode;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Get the current scanning policy filter mode.
+
+    @returns    The scanning policy filter mode.
+
+    @section EXAMPLE
+
+    @code
+
+    @endcode
+*/
+/**************************************************************************/
+Gap::ScanningPolicyMode_t nRF5xGap::getScanningPolicyMode(void) const
+{
+    return scanningPolicyMode;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Get the current initiator policy filter mode.
+
+    @returns    The initiator policy filter mode.
+
+    @note   Currently initiator filtering using the whitelist is not
+            implemented in this module.
+
+    @section EXAMPLE
+
+    @code
+
+    @endcode
+*/
+/**************************************************************************/
+Gap::InitiatorPolicyMode_t nRF5xGap::getInitiatorPolicyMode(void) const
+{
+    return Gap::INIT_POLICY_IGNORE_WHITELIST;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Helper function used to populate the ble_gap_whitelist_t that
+            will be used by the SoftDevice for filtering requests.
+
+    @returns    \ref ble_error_t
+
+    @retval     BLE_ERROR_NONE
+                Everything executed properly
+
+    @retval     BLE_ERROR_INVALID_STATE
+                The internal stack was not initialized correctly.
+
+    @note  Both the SecurityManager and Gap must initialize correctly for
+           this function to succeed.
+
+    @note  This function is needed because for the BLE API the whitelist
+           is just a collection of keys, but for the stack it also includes
+           the IRK table.
+
+    @section EXAMPLE
+
+    @code
+
+    @endcode
+*/
+/**************************************************************************/
+ble_error_t nRF5xGap::generateStackWhitelist(ble_gap_whitelist_t &whitelist)
+{
+    ble_gap_whitelist_t  whitelistFromBondTable;
+    ble_gap_addr_t      *addressPtr[1];
+    ble_gap_irk_t       *irkPtr[YOTTA_CFG_IRK_TABLE_MAX_SIZE];
+
+    nRF5xSecurityManager& securityManager = (nRF5xSecurityManager&) nRF5xn::Instance(0).getSecurityManager();
+
+    if (securityManager.hasInitialized()) {
+        /* We do not care about the addresses, set the count to 0 */
+        whitelistFromBondTable.addr_count = 0;
+        /* The Nordic SDK will return a failure if we set pp_addr to NULL */
+        whitelistFromBondTable.pp_addrs   = addressPtr;
+        /* We want all the IRKs we can get because we do not know which ones match the addresses */
+        whitelistFromBondTable.irk_count  = YOTTA_CFG_IRK_TABLE_MAX_SIZE;
+        whitelistFromBondTable.pp_irks    = irkPtr;
+
+        /* Use the security manager to get the IRKs from the bond table */
+        ble_error_t error = securityManager.createWhitelistFromBondTable(whitelistFromBondTable);
+        if (error != BLE_ERROR_NONE) {
+            return error;
+        }
+    } else  {
+        /**
+         * If there is no security manager then we cannot access the bond table,
+         * so disable IRK matching
+         */
+        whitelistFromBondTable.addr_count = 0;
+        whitelistFromBondTable.irk_count  = 0;
+    }
+
+    /**
+     * For every private resolvable address in the local whitelist check if
+     * there is an IRK for said address in the bond table and add it to the
+     * local IRK list.
+     */
+    whitelist.irk_count  = 0;
+    whitelist.addr_count = 0;
+    for (uint8_t i = 0; i < whitelistAddressesSize; ++i) {
+        if (whitelistAddresses[i].addr_type == BLEProtocol::AddressType_t::RANDOM_PRIVATE_RESOLVABLE) {
+            /* Test if there is a matching IRK for this private resolvable address */
+            for (uint8_t j = 0; j < whitelistFromBondTable.irk_count; ++j) {
+                if (securityManager.matchAddressAndIrk(&whitelistAddresses[i], whitelistFromBondTable.pp_irks[j])) {
+                    /* Found the corresponding IRK, add it to our local whitelist */
+                    whitelist.pp_irks[whitelist.irk_count] = whitelistFromBondTable.pp_irks[j];
+                    whitelist.irk_count++;
+                    /* Make sure we do not look at this IRK again */
+                    if (j != whitelistFromBondTable.irk_count - 1) {
+                        /**
+                         * This is not the last IRK, so replace the pointer
+                         * with the last pointer in the array
+                         */
+                        whitelistFromBondTable.pp_irks[j] =
+                            whitelistFromBondTable.pp_irks[whitelistFromBondTable.irk_count - 1];
+                    }
+                    /**
+                     * If the IRK is the last pointer in the array simply
+                     * decrement the total IRK count
+                     */
+                    whitelistFromBondTable.irk_count--;
+                    break;
+                }
+            }
+        } else {
+            /* Include the address into the whitelist */
+            whitelist.pp_addrs[whitelist.addr_count] = &whitelistAddresses[i];
+            whitelist.addr_count++;
+        }
+    }
+
+    return BLE_ERROR_NONE;
 }
\ No newline at end of file
--- a/source/nRF5xGap.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nRF5xGap.h	Wed Apr 06 22:39:17 2016 +0100
@@ -17,7 +17,23 @@
 #ifndef __NRF5x_GAP_H__
 #define __NRF5x_GAP_H__
 
-#include "mbed.h"
+#ifdef YOTTA_CFG_MBED_OS
+    #include "mbed-drivers/mbed.h"
+#else
+    #include "mbed.h"
+#endif
+#ifndef YOTTA_CFG_WHITELIST_MAX_SIZE
+    #define YOTTA_CFG_WHITELIST_MAX_SIZE BLE_GAP_WHITELIST_ADDR_MAX_COUNT
+#elif YOTTA_CFG_WHITELIST_MAX_SIZE > BLE_GAP_WHITELIST_ADDR_MAX_COUNT
+    #undef YOTTA_CFG_WHITELIST_MAX_SIZE
+    #define YOTTA_CFG_WHITELIST_MAX_SIZE BLE_GAP_WHITELIST_ADDR_MAX_COUNT
+#endif
+#ifndef YOTTA_CFG_IRK_TABLE_MAX_SIZE
+    #define YOTTA_CFG_IRK_TABLE_MAX_SIZE BLE_GAP_WHITELIST_IRK_MAX_COUNT
+#elif YOTTA_CFG_IRK_TABLE_MAX_SIZE > BLE_GAP_WHITELIST_IRK_MAX_COUNT
+    #undef YOTTA_CFG_IRK_TABLE_MAX_SIZE
+    #define YOTTA_CFG_IRK_TABLE_MAX_SIZE BLE_GAP_WHITELIST_IRK_MAX_COUNT
+#endif
 #include "ble/blecommon.h"
 #include "ble.h"
 #include "ble/GapAdvertisingParams.h"
@@ -26,7 +42,11 @@
 #include "ble/GapScanningParams.h"
 
 #include "nrf_soc.h"
+
+extern "C" {
 #include "ble_radio_notification.h"
+}
+
 #include "btle_security.h"
 
 void radioNotificationStaticCallback(bool param);
@@ -40,8 +60,6 @@
 class nRF5xGap : public Gap
 {
 public:
-    static nRF5xGap &getInstance();
-
     /* Functions that must be implemented from Gap */
     virtual ble_error_t setAddress(AddressType_t  type,  const Address_t address);
     virtual ble_error_t getAddress(AddressType_t *typeP, Address_t address);
@@ -53,7 +71,7 @@
 
     virtual ble_error_t startAdvertising(const GapAdvertisingParams &);
     virtual ble_error_t stopAdvertising(void);
-    virtual ble_error_t connect(const Address_t, Gap::AddressType_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams);
+    virtual ble_error_t connect(const Address_t, BLEProtocol::AddressType_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams);
     virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason);
     virtual ble_error_t disconnect(DisconnectionReason_t reason);
 
@@ -72,6 +90,23 @@
     virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params);
     virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params);
 
+    virtual ble_error_t reset(void);
+
+    /*
+     * The following functions are part of the whitelisting experimental API.
+     * Therefore, this functionality can change in the near future.
+     */
+    virtual uint8_t getMaxWhitelistSize(void) const;
+    virtual ble_error_t getWhitelist(Gap::Whitelist_t &whitelistOut) const;
+    virtual ble_error_t setWhitelist(const Gap::Whitelist_t &whitelistIn);
+
+    virtual ble_error_t setAdvertisingPolicyMode(AdvertisingPolicyMode_t mode);
+    virtual ble_error_t setScanningPolicyMode(ScanningPolicyMode_t mode);
+    virtual ble_error_t setInitiatorPolicyMode(InitiatorPolicyMode_t mode);
+    virtual Gap::AdvertisingPolicyMode_t getAdvertisingPolicyMode(void) const;
+    virtual Gap::ScanningPolicyMode_t getScanningPolicyMode(void) const;
+    virtual Gap::InitiatorPolicyMode_t getInitiatorPolicyMode(void) const;
+
     virtual ble_error_t initRadioNotification(void) {
         if (ble_radio_notification_init(NRF_APP_PRIORITY_HIGH, NRF_RADIO_NOTIFICATION_DISTANCE_800US, radioNotificationStaticCallback) == NRF_SUCCESS) {
             return BLE_ERROR_NONE;
@@ -82,45 +117,125 @@
 
 /* Observer role is not supported by S110, return BLE_ERROR_NOT_IMPLEMENTED */
 #if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
-    virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams) {
-        ble_gap_scan_params_t scanParams = {
-            .active      = scanningParams.getActiveScanning(), /**< If 1, perform active scanning (scan requests). */
-            .selective   = 0,    /**< If 1, ignore unknown devices (non whitelisted). */
-            .p_whitelist = NULL, /**< Pointer to whitelist, NULL if none is given. */
-            .interval    = scanningParams.getInterval(),  /**< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
-            .window      = scanningParams.getWindow(),    /**< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
-            .timeout     = scanningParams.getTimeout(),   /**< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */
-        };
-
-        if (sd_ble_gap_scan_start(&scanParams) != NRF_SUCCESS) {
-            return BLE_ERROR_PARAM_OUT_OF_RANGE;
-        }
-
-        return BLE_ERROR_NONE;
-    }
-
-    virtual ble_error_t stopScan(void) {
-        if (sd_ble_gap_scan_stop() == NRF_SUCCESS) {
-            return BLE_ERROR_NONE;
-        }
-
-        return BLE_STACK_BUSY;
-    }
+    virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams);
+    virtual ble_error_t stopScan(void);
 #endif
 
 private:
+    /*
+     * Whitelisting API related structures and helper functions.
+     */
+
+    /* Policy modes set by the user. By default these are set to ignore the whitelist */
+    Gap::AdvertisingPolicyMode_t advertisingPolicyMode;
+    Gap::ScanningPolicyMode_t    scanningPolicyMode;
+
+    /* Internal representation of a whitelist */
+    uint8_t         whitelistAddressesSize;
+    ble_gap_addr_t  whitelistAddresses[YOTTA_CFG_WHITELIST_MAX_SIZE];
+
+    /*
+     * An internal function used to populate the ble_gap_whitelist_t that will be used by
+     * the SoftDevice for filtering requests. This function is needed because for the BLE
+     * API the whitelist is just a collection of keys, but for the stack it also includes
+     * the IRK table.
+     */
+    ble_error_t generateStackWhitelist(ble_gap_whitelist_t &whitelist);
+
+private:
+    bool    radioNotificationCallbackParam; /* parameter to be passed into the Timeout-generated radio notification callback. */
+    Timeout radioNotificationTimeout;
+
+    /*
+     * A helper function to post radio notification callbacks with low interrupt priority.
+     */
+    void postRadioNotificationCallback(void) {
+#ifdef YOTTA_CFG_MBED_OS
+        /*
+         * In mbed OS, all user-facing BLE events (interrupts) are posted to the
+         * MINAR scheduler to be executed as callbacks in thread mode. MINAR guards
+         * its critical sections from interrupts by acquiring CriticalSectionLock,
+         * which results in a call to sd_nvic_critical_region_enter(). Thus, it is
+         * safe to invoke MINAR APIs from interrupt context as long as those
+         * interrupts are blocked by sd_nvic_critical_region_enter().
+         *
+         * Radio notifications are a special case for the above. The Radio
+         * Notification IRQ is handled at a very high priority--higher than the
+         * level blocked by sd_nvic_critical_region_enter(). Thus Radio Notification
+         * events can preempt MINAR's critical sections. Using MINAR APIs (such as
+         * posting an event) directly in processRadioNotification() may result in a
+         * race condition ending in a hard-fault.
+         *
+         * The solution is to *not* call MINAR APIs directly from the Radio
+         * Notification handling; i.e. to do the bulk of RadioNotification
+         * processing at a reduced priority which respects MINAR's critical
+         * sections. Unfortunately, on a cortex-M0, there is no clean way to demote
+         * priority for the currently executing interrupt--we wouldn't want to
+         * demote the radio notification handling anyway because it is sensitive to
+         * timing, and the system expects to finish this handling very quickly. The
+         * workaround is to employ a Timeout to trigger
+         * postRadioNotificationCallback() after a very short delay (~0 us) and post
+         * the MINAR callback that context.
+         *
+         * !!!WARNING!!! Radio notifications are very time critical events. The
+         * current solution is expected to work under the assumption that
+         * postRadioNotificationCalback() will be executed BEFORE the next radio
+         * notification event is generated.
+         */
+        minar::Scheduler::postCallback(
+            mbed::util::FunctionPointer1<void, bool>(&radioNotificationCallback, &FunctionPointerWithContext<bool>::call).bind(radioNotificationCallbackParam)
+        );
+#else
+        /*
+         * In mbed classic, all user-facing BLE events execute callbacks in interrupt
+         * mode. Radio Notifications are a special case because its IRQ is handled at
+         * a very high priority. Thus Radio Notification events can preempt other
+         * operations that require interaction with the SoftDevice such as advertising
+         * payload updates and changing the Gap state. Therefore, executing a Radio
+         * Notification callback directly from processRadioNotification() may result
+         * in a race condition ending in a hard-fault.
+         *
+         * The solution is to *not* execute the Radio Notification callback directly
+         * from the Radio Notification handling; i.e. to do the bulk of the
+         * Radio Notification processing at a reduced priority. Unfortunately, on a
+         * cortex-M0, there is no clean way to demote priority for the currently
+         * executing interrupt--we wouldn't want to demote the radio notification
+         * handling anyway because it is sensitive to timing, and the system expects
+         * to finish this handling very quickly. The workaround is to employ a Timeout
+         * to trigger postRadioNotificationCallback() after a very short delay (~0 us)
+         * and execute the callback in that context.
+         *
+         * !!!WARNING!!! Radio notifications are very time critical events. The
+         * current solution is expected to work under the assumption that
+         * postRadioNotificationCalback() will be executed BEFORE the next radio
+         * notification event is generated.
+         */
+        radioNotificationCallback.call(radioNotificationCallbackParam);
+#endif /* #ifdef YOTTA_CFG_MBED_OS */
+    }
+
     /**
      * A helper function to process radio-notification events; to be called internally.
      * @param param [description]
      */
     void processRadioNotificationEvent(bool param) {
-        radioNotificationCallback.call(param);
+        radioNotificationCallbackParam = param;
+        radioNotificationTimeout.attach_us(this, &nRF5xGap::postRadioNotificationCallback, 0);
     }
     friend void radioNotificationStaticCallback(bool param); /* allow invocations of processRadioNotificationEvent() */
 
 private:
     uint16_t m_connectionHandle;
-    nRF5xGap() {
+
+    /*
+     * Allow instantiation from nRF5xn when required.
+     */
+    friend class nRF5xn;
+
+    nRF5xGap() :
+        advertisingPolicyMode(Gap::ADV_POLICY_IGNORE_WHITELIST),
+        scanningPolicyMode(Gap::SCAN_POLICY_IGNORE_WHITELIST),
+        whitelistAddressesSize(0) {
         m_connectionHandle = BLE_CONN_HANDLE_INVALID;
     }
 
--- a/source/nRF5xGattClient.cpp	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nRF5xGattClient.cpp	Wed Apr 06 22:39:17 2016 +0100
@@ -16,15 +16,6 @@
 
 #include "nRF5xGattClient.h"
 
-nRF5xGattClient &
-nRF5xGattClient::getInstance(void) {
-    static nRF5xGattClient* nRFGattClientSingleton = NULL;
-    if (nRFGattClientSingleton == NULL) {
-        nRFGattClientSingleton = new nRF5xGattClient();
-    }
-    return *nRFGattClientSingleton;
-}
-
 #if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
 ble_error_t
 nRF5xGattClient::launchServiceDiscovery(Gap::Handle_t                               connectionHandle,
@@ -33,6 +24,27 @@
                                         const UUID                                 &matchingServiceUUIDIn,
                                         const UUID                                 &matchingCharacteristicUUIDIn)
 {
-    return discovery.launch(connectionHandle, sc, cc, matchingServiceUUIDIn, matchingCharacteristicUUIDIn);
+    return _discovery.launch(connectionHandle, sc, cc, matchingServiceUUIDIn, matchingCharacteristicUUIDIn);
 }
+
+ble_error_t nRF5xGattClient::discoverCharacteristicDescriptors(
+    const DiscoveredCharacteristic& characteristic,
+    const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
+    const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback)
+{
+    return _characteristicDescriptorDiscoverer.launch(
+        characteristic, 
+        discoveryCallback, 
+        terminationCallback
+    );
+}
+
+bool nRF5xGattClient::isCharacteristicDescriptorsDiscoveryActive(const DiscoveredCharacteristic& characteristic) const {
+    return _characteristicDescriptorDiscoverer.isActive(characteristic);   
+}
+
+void nRF5xGattClient::terminateCharacteristicDescriptorsDiscovery(const DiscoveredCharacteristic& characteristic) { 
+    return _characteristicDescriptorDiscoverer.requestTerminate(characteristic);
+}
+
 #endif
\ No newline at end of file
--- a/source/nRF5xGattClient.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nRF5xGattClient.h	Wed Apr 06 22:39:17 2016 +0100
@@ -19,12 +19,11 @@
 
 #include "ble/GattClient.h"
 #include "nRF5xServiceDiscovery.h"
+#include "nRF5xCharacteristicDescriptorDiscoverer.h"
 
 class nRF5xGattClient : public GattClient
 {
 public:
-    static nRF5xGattClient &getInstance();
-
     /**
      * When using S110, all Gatt client features will return
      * BLE_ERROR_NOT_IMPLEMENTED
@@ -87,14 +86,14 @@
                                                const UUID                                 &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN));
 
     virtual void onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback) {
-        discovery.onTermination(callback);
+        _discovery.onTermination(callback);
     }
 
     /**
      * Is service-discovery currently active?
      */
     virtual bool isServiceDiscoveryActive(void) const {
-        return discovery.isActive();
+        return _discovery.isActive();
     }
 
     /**
@@ -102,9 +101,31 @@
      * invocation of the TerminationCallback if service-discovery is active.
      */
     virtual void terminateServiceDiscovery(void) {
-        discovery.terminate();
+        _discovery.terminate();
     }
 
+    /**
+     * @brief Implementation of GattClient::discoverCharacteristicDescriptors
+     * @see GattClient::discoverCharacteristicDescriptors
+     */
+    virtual ble_error_t discoverCharacteristicDescriptors(
+        const DiscoveredCharacteristic& characteristic,
+        const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
+        const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback
+    );
+
+    /**
+     * @brief Implementation of GattClient::isCharacteristicDiscoveryActive
+     * @see GattClient::isCharacteristicDiscoveryActive
+     */
+    virtual bool isCharacteristicDescriptorsDiscoveryActive(const DiscoveredCharacteristic& characteristic) const;
+
+    /**
+     * @brief Implementation of GattClient::terminateCharacteristicDiscovery
+     * @see GattClient::terminateCharacteristicDiscovery
+     */
+    virtual void terminateCharacteristicDescriptorsDiscovery(const DiscoveredCharacteristic& characteristic);
+
     virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const {
         uint32_t rc = sd_ble_gattc_read(connHandle, attributeHandle, offset);
         if (rc == NRF_SUCCESS) {
@@ -147,19 +168,49 @@
         }
     }
 
+    /**
+     * @brief  Clear nRF5xGattClient's state.
+     *
+     * @return
+     *           BLE_ERROR_NONE if successful.
+     */
+    virtual ble_error_t reset(void) {
+        /* Clear all state that is from the parent, including private members */
+        if (GattClient::reset() != BLE_ERROR_NONE) {
+            return BLE_ERROR_INVALID_STATE;
+        }
+
+        /* Clear derived class members */
+        _discovery.reset();
+
+        return BLE_ERROR_NONE;
+    }
+
 public:
-    nRF5xGattClient() : discovery(this) {
+    /*
+     * Allow instantiation from nRF5xn when required.
+     */
+    friend class nRF5xn;
+
+    nRF5xGattClient() : _discovery(this) {
         /* empty */
     }
 
-    friend void bleGattcEventHandler(const ble_evt_t *p_ble_evt);
+    nRF5xServiceDiscovery& discovery() {
+        return _discovery;
+    }
+
+    nRF5xCharacteristicDescriptorDiscoverer& characteristicDescriptorDiscoverer() {
+        return _characteristicDescriptorDiscoverer;
+    }
 
 private:
     nRF5xGattClient(const nRF5xGattClient &);
     const nRF5xGattClient& operator=(const nRF5xGattClient &);
 
 private:
-    nRF5xServiceDiscovery discovery;
+    nRF5xServiceDiscovery _discovery;
+    nRF5xCharacteristicDescriptorDiscoverer _characteristicDescriptorDiscoverer;
 
 #endif // if !S110
 };
--- a/source/nRF5xGattServer.cpp	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nRF5xGattServer.cpp	Wed Apr 06 22:39:17 2016 +0100
@@ -15,17 +15,16 @@
  */
 
 #include "nRF5xGattServer.h"
-#include "mbed.h"
+#ifdef YOTTA_CFG_MBED_OS
+    #include "mbed-drivers/mbed.h"
+#else
+    #include "mbed.h"
+#endif
 
 #include "common/common.h"
 #include "btle/custom/custom_helper.h"
 
-#include "nRF5xGap.h"
-
-nRF5xGattServer &nRF5xGattServer::getInstance(void) {
-    static nRF5xGattServer m_instance;
-    return m_instance;
-}
+#include "nRF5xn.h"
 
 /**************************************************************************/
 /*!
@@ -69,7 +68,7 @@
 
         /* Skip any incompletely defined, read-only characteristics. */
         if ((p_char->getValueAttribute().getValuePtr() == NULL) &&
-            (p_char->getValueAttribute().getInitialLength() == 0) &&
+            (p_char->getValueAttribute().getLength() == 0) &&
             (p_char->getProperties() == GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ)) {
             continue;
         }
@@ -95,8 +94,9 @@
                                               p_char->getProperties(),
                                               p_char->getRequiredSecurity(),
                                               p_char->getValueAttribute().getValuePtr(),
-                                              p_char->getValueAttribute().getInitialLength(),
+                                              p_char->getValueAttribute().getLength(),
                                               p_char->getValueAttribute().getMaxLength(),
+                                              p_char->getValueAttribute().hasVariableLength(),
                                               userDescriptionDescriptorValuePtr,
                                               userDescriptionDescriptorValueLen,
                                               p_char->isReadAuthorizationEnabled(),
@@ -127,8 +127,9 @@
                    custom_add_in_descriptor(BLE_GATT_HANDLE_INVALID,
                                             &nordicUUID,
                                             p_desc->getValuePtr(),
-                                            p_desc->getInitialLength(),
+                                            p_desc->getLength(),
                                             p_desc->getMaxLength(),
+                                            p_desc->hasVariableLength(),
                                             &nrfDescriptorHandles[descriptorCount]),
                 BLE_ERROR_PARAM_OUT_OF_RANGE);
 
@@ -239,7 +240,8 @@
         hvx_params.p_len  = &len;
 
         if (connectionHandle == BLE_CONN_HANDLE_INVALID) { /* use the default connection handle if the caller hasn't specified a valid connectionHandle. */
-            connectionHandle = nRF5xGap::getInstance().getConnectionHandle();
+            nRF5xGap &gap = (nRF5xGap &) nRF5xn::Instance(BLE::DEFAULT_INSTANCE).getGap();
+            connectionHandle = gap.getConnectionHandle();
         }
         error_t error = (error_t) sd_ble_gatts_hvx(connectionHandle, &hvx_params);
         if (error != ERROR_NONE) {
@@ -275,10 +277,43 @@
     return returnValue;
 }
 
+/**
+ * Perform an explicit BLE notification of a given attribute.
+ *
+ * @param[in] attributeHandle
+ *              Handle for the value attribute of the Characteristic.
+ * @param[in] value
+ *              A pointer to a buffer holding the new value
+ * @param[in] size
+ *              Size of the new value (in bytes).
+ *
+ * @return BLE_ERROR_NONE if we have successfully set the value of the attribute.
+ */
+ble_error_t nRF5xGattServer::notify(GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len)
+{
+    uint16_t gapConnectionHandle = ((nRF5xGap &)nRF5xn::Instance(BLE::DEFAULT_INSTANCE).getGap()).getConnectionHandle();
+    ble_gatts_hvx_params_t hvx_params;
+
+    hvx_params.handle = attributeHandle;
+    hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
+    hvx_params.offset = 0;
+    hvx_params.p_data = const_cast<uint8_t *>(buffer);
+    hvx_params.p_len  = &len;
+
+    error_t error = (error_t) sd_ble_gatts_hvx(gapConnectionHandle, &hvx_params);
+
+    if (error == ERROR_NONE)  
+	    return BLE_ERROR_NONE;
+    else
+	    return BLE_STACK_BUSY;
+}
+
+
 ble_error_t nRF5xGattServer::areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP)
 {
     /* Forward the call with the default connection handle. */
-    return areUpdatesEnabled(nRF5xGap::getInstance().getConnectionHandle(), characteristic, enabledP);
+    nRF5xGap &gap = (nRF5xGap &) nRF5xn::Instance(BLE::DEFAULT_INSTANCE).getGap();
+    return areUpdatesEnabled(gap.getConnectionHandle(), characteristic, enabledP);
 }
 
 ble_error_t nRF5xGattServer::areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP)
@@ -310,6 +345,33 @@
 
 /**************************************************************************/
 /*!
+    @brief  Clear nRF5xGattServer's state.
+
+    @returns    ble_error_t
+
+    @retval     BLE_ERROR_NONE
+                Everything executed properly
+*/
+/**************************************************************************/
+ble_error_t nRF5xGattServer::reset(void)
+{
+    /* Clear all state that is from the parent, including private members */
+    if (GattServer::reset() != BLE_ERROR_NONE) {
+        return BLE_ERROR_INVALID_STATE;
+    }
+
+    /* Clear derived class members */
+    memset(p_characteristics,        0, sizeof(p_characteristics));
+    memset(p_descriptors,            0, sizeof(p_descriptors));
+    memset(nrfCharacteristicHandles, 0, sizeof(ble_gatts_char_handles_t));
+    memset(nrfDescriptorHandles,     0, sizeof(nrfDescriptorHandles));
+    descriptorCount = 0;
+
+    return BLE_ERROR_NONE;
+}
+
+/**************************************************************************/
+/*!
     @brief  Callback handler for events getting pushed up from the SD
 */
 /**************************************************************************/
@@ -359,9 +421,13 @@
             return;
         }
 
-        case BLE_GATTS_EVT_SYS_ATTR_MISSING:
-            sd_ble_gatts_sys_attr_set(gattsEventP->conn_handle, NULL, 0, 0);
+        case BLE_GATTS_EVT_SYS_ATTR_MISSING: 
+        case BLE_GAP_EVT_CONN_SEC_UPDATE:
+        {
+            GattSysAttrMissingCallbackParams cbParams = {gattsEventP->conn_handle};
+            handleSysAttrMissingEvent(&cbParams);
             return;
+        }
 
         case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
             switch (gattsEventP->params.authorize_request.type) {
--- a/source/nRF5xGattServer.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nRF5xGattServer.h	Wed Apr 06 22:39:17 2016 +0100
@@ -27,24 +27,25 @@
 class nRF5xGattServer : public GattServer
 {
 public:
-    static nRF5xGattServer &getInstance();
-
     /* Functions that must be implemented from GattServer */
     virtual ble_error_t addService(GattService &);
     virtual ble_error_t read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP);
     virtual ble_error_t read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP);
     virtual ble_error_t write(GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false);
     virtual ble_error_t write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false);
+    virtual ble_error_t notify(GattAttribute::Handle_t, const uint8_t[], uint16_t);
     virtual ble_error_t areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP);
     virtual ble_error_t areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP);
+    virtual ble_error_t reset(void);
 
     /* nRF51 Functions */
     void eventCallback(void);
     void hwCallback(ble_evt_t *p_ble_evt);
 
+
 private:
-    const static unsigned BLE_TOTAL_CHARACTERISTICS = 20;
-    const static unsigned BLE_TOTAL_DESCRIPTORS     = 8;
+    const static unsigned BLE_TOTAL_CHARACTERISTICS = 30;
+    const static unsigned BLE_TOTAL_DESCRIPTORS     = 20;
 
 private:
     /**
@@ -86,6 +87,11 @@
     uint8_t                   descriptorCount;
     uint16_t                  nrfDescriptorHandles[BLE_TOTAL_DESCRIPTORS];
 
+    /*
+     * Allow instantiation from nRF5xn when required.
+     */
+    friend class nRF5xn;
+
     nRF5xGattServer() : GattServer(), p_characteristics(), nrfCharacteristicHandles(), p_descriptors(), descriptorCount(0), nrfDescriptorHandles() {
         /* empty */
     }
--- a/source/nRF5xSecurityManager.cpp	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-/* 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 "nRF5xSecurityManager.h"
-
-nRF5xSecurityManager &nRF5xSecurityManager::getInstance(void) {
-    static nRF5xSecurityManager* m_instance = NULL;
-    if (m_instance == NULL) {
-        m_instance = new nRF5xSecurityManager();
-    }
-    return *m_instance;
-}
\ No newline at end of file
--- a/source/nRF5xSecurityManager.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nRF5xSecurityManager.h	Wed Apr 06 22:39:17 2016 +0100
@@ -19,14 +19,13 @@
 
 #include <stddef.h>
 
+#include "nRF5xGap.h"
 #include "ble/SecurityManager.h"
 #include "btle_security.h"
 
 class nRF5xSecurityManager : public SecurityManager
 {
 public:
-    static nRF5xSecurityManager &getInstance();
-
     /* Functions that must be implemented from SecurityManager */
     virtual ble_error_t init(bool                     enableBonding,
                              bool                     requireMITM,
@@ -39,11 +38,109 @@
         return btle_getLinkSecurity(connectionHandle, securityStatusP);
     }
 
+    virtual ble_error_t setLinkSecurity(Gap::Handle_t connectionHandle, SecurityMode_t securityMode) {
+        return btle_setLinkSecurity(connectionHandle, securityMode);
+    }
+
     virtual ble_error_t purgeAllBondingState(void) {
         return btle_purgeAllBondingState();
     }
 
+    /**
+     * @brief  Returns a list of addresses from peers in the stacks bond table.
+     *
+     * @param[in/out]   addresses
+     *                  (on input) @ref Gap::Whitelist_t structure where at
+     *                  most addresses.capacity addresses from bonded peers will
+     *                  be stored.
+     *                  (on output) A copy of the addresses from bonded peers.
+     *
+     * @return
+     *           BLE_ERROR_NONE if successful.
+     */
+    virtual ble_error_t getAddressesFromBondTable(Gap::Whitelist_t &addresses) const {
+        uint8_t i;
+
+        ble_gap_whitelist_t  whitelistFromBondTable;
+        ble_gap_addr_t      *addressPtr[YOTTA_CFG_WHITELIST_MAX_SIZE];
+        ble_gap_irk_t       *irkPtr[YOTTA_CFG_IRK_TABLE_MAX_SIZE];
+
+        /* Initialize the structure so that we get as many addreses as the whitelist can hold */
+        whitelistFromBondTable.addr_count = YOTTA_CFG_IRK_TABLE_MAX_SIZE;
+        whitelistFromBondTable.pp_addrs   = addressPtr;
+        whitelistFromBondTable.irk_count  = YOTTA_CFG_IRK_TABLE_MAX_SIZE;
+        whitelistFromBondTable.pp_irks    = irkPtr;
+
+        ble_error_t error = createWhitelistFromBondTable(whitelistFromBondTable);
+        if (error != BLE_ERROR_NONE) {
+            addresses.size = 0;
+            addresses.bonds = 0;
+            return error;
+        }
+
+        addresses.bonds = whitelistFromBondTable.irk_count;
+
+        /* Put all the addresses in the structure */
+        for (i = 0; i < whitelistFromBondTable.addr_count; ++i) {
+            if (i >= addresses.capacity) {
+                /* Ran out of space in the output Gap::Whitelist_t */
+                addresses.size = i;
+                return BLE_ERROR_NONE;
+            }
+            memcpy(&addresses.addresses[i], whitelistFromBondTable.pp_addrs[i], sizeof(BLEProtocol::Address_t));
+        }
+
+        /* Update the current address count */
+        addresses.size = i;
+
+        /* The assumption here is that the underlying implementation of
+         * createWhitelistFromBondTable()  will not return the private resolvable
+         * addresses (which is the case in the SoftDevice). Rather it returns the
+         * IRKs, so we need to generate the private resolvable address by ourselves.
+         */
+        for (i = 0; i < whitelistFromBondTable.irk_count; ++i) {
+            if (i + addresses.size >= addresses.capacity) {
+                /* Ran out of space in the output Gap::Whitelist_t */
+                addresses.size += i;
+                return BLE_ERROR_NONE;
+            }
+            btle_generateResolvableAddress(
+                *whitelistFromBondTable.pp_irks[i],
+                (ble_gap_addr_t &) addresses.addresses[i + addresses.size]
+            );
+        }
+
+        /* Update the current address count */
+        addresses.size += i;
+
+        return BLE_ERROR_NONE;
+    }
+
+    /**
+     * @brief  Clear nRF5xSecurityManager's state.
+     *
+     * @return
+     *           BLE_ERROR_NONE if successful.
+     */
+    virtual ble_error_t reset(void)
+    {
+        if (SecurityManager::reset() != BLE_ERROR_NONE) {
+            return BLE_ERROR_INVALID_STATE;
+        }
+
+        return BLE_ERROR_NONE;
+    }
+
+    bool hasInitialized(void) const {
+        return btle_hasInitializedSecurity();
+    }
+
 public:
+    /*
+     * Allow instantiation from nRF5xn when required.
+     */
+    friend class nRF5xn;
+
     nRF5xSecurityManager() {
         /* empty */
     }
@@ -51,6 +148,30 @@
 private:
     nRF5xSecurityManager(const nRF5xSecurityManager &);
     const nRF5xSecurityManager& operator=(const nRF5xSecurityManager &);
+
+    /*
+     * Expose an interface that allows us to query the SoftDevice bond table
+     * and extract a whitelist.
+     */
+    ble_error_t createWhitelistFromBondTable(ble_gap_whitelist_t &whitelistFromBondTable) const {
+        return btle_createWhitelistFromBondTable(&whitelistFromBondTable);
+    }
+
+    /*
+     * Given a BLE address and a IRK this function check whether the address
+     * can be generated from the IRK. To do so, this function uses the hash
+     * function and algorithm described in the Bluetooth low Energy
+     * Specification. Internally, Nordic SDK functions are used.
+     */
+    bool matchAddressAndIrk(ble_gap_addr_t *address, ble_gap_irk_t *irk) const {
+        return btle_matchAddressAndIrk(address, irk);
+    }
+
+    /*
+     * Give nRF5xGap access to createWhitelistFromBondTable() and
+     * matchAddressAndIrk()
+     */
+    friend class nRF5xGap;
 };
 
 #endif // ifndef __NRF51822_SECURITY_MANAGER_H__
\ No newline at end of file
--- a/source/nRF5xServiceDiscovery.cpp	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nRF5xServiceDiscovery.cpp	Wed Apr 06 22:39:17 2016 +0100
@@ -27,22 +27,32 @@
         .start_handle = startHandle,
         .end_handle   = endHandle
     };
-    uint32_t rc;
-    if ((rc = sd_ble_gattc_characteristics_discover(connectionHandle, &handleRange)) != NRF_SUCCESS) {
-        terminateCharacteristicDiscovery();
-        switch (rc) {
-            case BLE_ERROR_INVALID_CONN_HANDLE:
-            case NRF_ERROR_INVALID_ADDR:
-                return BLE_ERROR_INVALID_PARAM;
-            case NRF_ERROR_BUSY:
-                return BLE_STACK_BUSY;
-            default:
-            case NRF_ERROR_INVALID_STATE:
-                return BLE_ERROR_INVALID_STATE;
-        }
+    uint32_t rc = sd_ble_gattc_characteristics_discover(connectionHandle, &handleRange);
+    ble_error_t err = BLE_ERROR_NONE;
+
+    switch (rc) {
+        case NRF_SUCCESS:
+            err = BLE_ERROR_NONE;
+            break;
+        case BLE_ERROR_INVALID_CONN_HANDLE:
+        case NRF_ERROR_INVALID_ADDR:
+            err = BLE_ERROR_INVALID_PARAM;
+            break;
+        case NRF_ERROR_BUSY:
+            err = BLE_STACK_BUSY;
+            break;
+        case NRF_ERROR_INVALID_STATE:
+            err = BLE_ERROR_INVALID_STATE;
+            break;
+        default:
+            err = BLE_ERROR_UNSPECIFIED;
+            break;
     }
 
-    return BLE_ERROR_NONE;
+    if (err) {
+        terminateCharacteristicDiscovery(err);
+    }
+    return err;
 }
 
 void
@@ -78,7 +88,6 @@
 void
 nRF5xServiceDiscovery::setupDiscoveredCharacteristics(const ble_gattc_evt_char_disc_rsp_t *response)
 {
-    characteristicIndex = 0;
     numCharacteristics  = response->count;
 
     /* Account for the limitation on the number of discovered characteristics we can handle at a time. */
@@ -114,38 +123,62 @@
 void
 nRF5xServiceDiscovery::progressCharacteristicDiscovery(void)
 {
-    /* Iterate through the previously discovered characteristics cached in characteristics[]. */
-    while ((state == CHARACTERISTIC_DISCOVERY_ACTIVE) && (characteristicIndex < numCharacteristics)) {
+    if (state != CHARACTERISTIC_DISCOVERY_ACTIVE) {
+        return;
+    }
+
+    if ((discoveredCharacteristic != nRF5xDiscoveredCharacteristic()) && (numCharacteristics > 0)) {
+        discoveredCharacteristic.setLastHandle(characteristics[0].getDeclHandle() - 1);
+
         if ((matchingCharacteristicUUID == UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) ||
-            ((matchingCharacteristicUUID == characteristics[characteristicIndex].getUUID()) &&
+            ((matchingCharacteristicUUID == discoveredCharacteristic.getUUID()) &&
              (matchingServiceUUID != UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)))) {
             if (characteristicCallback) {
-                characteristicCallback(&characteristics[characteristicIndex]);
+                characteristicCallback(&discoveredCharacteristic);
             }
         }
-
-        characteristicIndex++;
     }
 
-    /* Relaunch discovery of new characteristics beyond the last entry cached in characteristics[]. */
-    if (state == CHARACTERISTIC_DISCOVERY_ACTIVE) {
-        /* Determine the ending handle of the last cached characteristic. */
-        Gap::Handle_t startHandle = characteristics[characteristicIndex - 1].getValueHandle() + 1;
-        Gap::Handle_t endHandle   = services[serviceIndex].getEndHandle();
-        resetDiscoveredCharacteristics(); /* Note: resetDiscoveredCharacteristics() must come after fetching start and end Handles. */
+    for (uint8_t i = 0; i < numCharacteristics; ++i) {
+        if (state != CHARACTERISTIC_DISCOVERY_ACTIVE) {
+            return;
+        }
+
+        if (i == (numCharacteristics - 1)) {
+            discoveredCharacteristic = characteristics[i];
+            break;
+        } else {
+            characteristics[i].setLastHandle(characteristics[i + 1].getDeclHandle() - 1);
+        }
 
-        if (startHandle < endHandle) {
-            ble_gattc_handle_range_t handleRange = {
-                .start_handle = startHandle,
-                .end_handle   = endHandle
-            };
-            if (sd_ble_gattc_characteristics_discover(connHandle, &handleRange) != NRF_SUCCESS) {
-                terminateCharacteristicDiscovery();
+        if ((matchingCharacteristicUUID == UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) ||
+            ((matchingCharacteristicUUID == characteristics[i].getUUID()) &&
+             (matchingServiceUUID != UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)))) {
+            if (characteristicCallback) {
+                characteristicCallback(&characteristics[i]);
             }
-        } else {
-            terminateCharacteristicDiscovery();
         }
     }
+
+    if (state != CHARACTERISTIC_DISCOVERY_ACTIVE) {
+        return;
+    }
+
+    Gap::Handle_t startHandle = (numCharacteristics > 0) ? characteristics[numCharacteristics - 1].getValueHandle() + 1 : SRV_DISC_END_HANDLE;
+    Gap::Handle_t endHandle   = services[serviceIndex].getEndHandle();
+    resetDiscoveredCharacteristics(); /* Note: resetDiscoveredCharacteristics() must come after fetching start and end Handles. */
+
+    if (startHandle < endHandle) {
+        ble_gattc_handle_range_t handleRange = {
+            .start_handle = startHandle,
+            .end_handle   = endHandle
+        };
+        if (sd_ble_gattc_characteristics_discover(connHandle, &handleRange) != NRF_SUCCESS) {
+            terminateCharacteristicDiscovery(BLE_ERROR_UNSPECIFIED);
+        }
+    } else {
+        terminateCharacteristicDiscovery(BLE_ERROR_NONE);
+    }
 }
 
 void
@@ -251,13 +284,10 @@
     if (state == DISCOVER_SERVICE_UUIDS) {
         if ((response->count == 1) && (response->value_len == UUID::LENGTH_OF_LONG_UUID)) {
             UUID::LongUUIDBytes_t uuid;
-            /* Switch longUUID bytes to MSB */
-            for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
-                uuid[i] = response->handle_value[0].p_value[UUID::LENGTH_OF_LONG_UUID - 1 - i];
-            }
+            memcpy(uuid, response->handle_value[0].p_value, UUID::LENGTH_OF_LONG_UUID);
 
             unsigned serviceIndex = serviceUUIDDiscoveryQueue.dequeue();
-            services[serviceIndex].setupLongUUID(uuid);
+            services[serviceIndex].setupLongUUID(uuid, UUID::LSB);
 
             serviceUUIDDiscoveryQueue.triggerFirst();
         } else {
@@ -266,13 +296,11 @@
     } else if (state == DISCOVER_CHARACTERISTIC_UUIDS) {
         if ((response->count == 1) && (response->value_len == UUID::LENGTH_OF_LONG_UUID + 1 /* props */ + 2 /* value handle */)) {
             UUID::LongUUIDBytes_t uuid;
-            /* Switch longUUID bytes to MSB */
-            for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
-                uuid[i] = response->handle_value[0].p_value[3 + UUID::LENGTH_OF_LONG_UUID - 1 - i];
-            }
+
+            memcpy(uuid, &(response->handle_value[0].p_value[3]), UUID::LENGTH_OF_LONG_UUID);
 
             unsigned charIndex = charUUIDDiscoveryQueue.dequeue();
-            characteristics[charIndex].setupLongUUID(uuid);
+            characteristics[charIndex].setupLongUUID(uuid, UUID::LSB);
 
             charUUIDDiscoveryQueue.triggerFirst();
         } else {
--- a/source/nRF5xServiceDiscovery.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nRF5xServiceDiscovery.h	Wed Apr 06 22:39:17 2016 +0100
@@ -41,7 +41,6 @@
         gattc(gattcIn),
         serviceIndex(0),
         numServices(0),
-        characteristicIndex(0),
         numCharacteristics(0),
         state(INACTIVE),
         services(),
@@ -95,10 +94,43 @@
         terminateServiceDiscovery();
     }
 
+    void terminate(Gap::Handle_t connectionHandle) {
+        if(connHandle == connectionHandle) {
+            terminate();
+        }
+    }
+
     virtual void onTermination(ServiceDiscovery::TerminationCallback_t callback) {
         onTerminationCallback = callback;
     }
 
+    /**
+     * @brief  Clear nRF5xServiceDiscovery's state.
+     *
+     * @return
+     *           BLE_ERROR_NONE if successful.
+     */
+    virtual ble_error_t reset(void) {
+        /* Clear all state that is from the parent, including private members */
+        if (ServiceDiscovery::reset() != BLE_ERROR_NONE) {
+            return BLE_ERROR_INVALID_STATE;
+        }
+
+        /* Clear derived class members */
+        serviceIndex = 0;
+        numServices = 0;
+        numCharacteristics = 0;
+
+        state = INACTIVE;
+
+        serviceUUIDDiscoveryQueue.reset();
+        charUUIDDiscoveryQueue.reset();
+
+        onTerminationCallback = NULL;
+
+        return BLE_ERROR_NONE;
+    }
+
 private:
     ble_error_t launchCharacteristicDiscovery(Gap::Handle_t connectionHandle, Gap::Handle_t startHandle, Gap::Handle_t endHandle);
 
@@ -111,6 +143,8 @@
     void removeFirstServiceNeedingUUIDDiscovery(void);
 
     void terminateServiceDiscovery(void) {
+        discoveredCharacteristic = nRF5xDiscoveredCharacteristic();
+
         bool wasActive = isActive();
         state = INACTIVE;
 
@@ -119,8 +153,24 @@
         }
     }
 
-    void terminateCharacteristicDiscovery(void) {
+    void terminateCharacteristicDiscovery(ble_error_t err) {
         if (state == CHARACTERISTIC_DISCOVERY_ACTIVE) {
+            if(discoveredCharacteristic != nRF5xDiscoveredCharacteristic()) {
+               if(err == BLE_ERROR_NONE) {
+                    // fullfill the last characteristic
+                    discoveredCharacteristic.setLastHandle(services[serviceIndex].getEndHandle());
+
+                    if ((matchingCharacteristicUUID == UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) ||
+                        ((matchingCharacteristicUUID == discoveredCharacteristic.getUUID()) &&
+                         (matchingServiceUUID != UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)))) {
+                        if (characteristicCallback) {
+                            characteristicCallback(&discoveredCharacteristic);
+                        }
+                    }
+               }
+               discoveredCharacteristic = nRF5xDiscoveredCharacteristic();
+            }
+
             state = SERVICE_DISCOVERY_ACTIVE;
         }
         serviceIndex++; /* Progress service index to keep discovery alive. */
@@ -134,7 +184,6 @@
 
     void resetDiscoveredCharacteristics(void) {
         numCharacteristics  = 0;
-        characteristicIndex = 0;
     }
 
 private:
@@ -281,7 +330,6 @@
 private:
     uint8_t  serviceIndex;        /**< Index of the current service being discovered. This is intended for internal use during service discovery.*/
     uint8_t  numServices;         /**< Number of services at the peers GATT database.*/
-    uint8_t  characteristicIndex; /**< Index of the current characteristic being discovered. This is intended for internal use during service discovery.*/
     uint8_t  numCharacteristics;  /**< Number of characteristics within the service.*/
 
     enum State_t {
@@ -300,6 +348,19 @@
     CharUUIDDiscoveryQueue      charUUIDDiscoveryQueue;
 
     TerminationCallback_t       onTerminationCallback;
+
+    /*
+     * The currently discovered characteristic. Discovery of a characteristic
+     * is a two phase process.
+     * First, declaration handle is fetched, it provide the UUID, the value handle and
+     * the properties of a characteristic.
+     * Second, the next declaration handle is fetched, with its declaration handle, it is
+     * possible to compute the last handle of the discovered characteristic and fill the
+     * missing part of the object.
+     * If there is no remaining characteristic to discover, the last handle of the
+     * discovered characteristic will be set to the last handle of its enclosing service.
+     */
+    nRF5xDiscoveredCharacteristic discoveredCharacteristic;
 };
 
 #endif /*__NRF_SERVICE_DISCOVERY_H__*/
\ No newline at end of file
--- a/source/nRF5xn.cpp	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nRF5xn.cpp	Wed Apr 06 22:39:17 2016 +0100
@@ -14,7 +14,11 @@
  * limitations under the License.
  */
 
-#include "mbed.h"
+#ifdef YOTTA_CFG_MBED_OS
+    #include "mbed-drivers/mbed.h"
+#else
+    #include "mbed.h"
+#endif
 #include "nRF5xn.h"
 #include "ble/blecommon.h"
 #include "nrf_soc.h"
@@ -22,12 +26,14 @@
 #include "btle/btle.h"
 #include "nrf_delay.h"
 
+extern "C" {
 #include "softdevice_handler.h"
+}
 
 /**
  * The singleton which represents the nRF51822 transport for the BLE.
  */
-static nRF5xn deviceInstance;
+static nRF5xn *deviceInstance = NULL;
 
 /**
  * BLE-API requires an implementation of the following function in order to
@@ -36,10 +42,24 @@
 BLEInstanceBase *
 createBLEInstance(void)
 {
-    return (&deviceInstance);
+    return &nRF5xn::Instance(BLE::DEFAULT_INSTANCE);
 }
 
-nRF5xn::nRF5xn(void) : initialized(false), instanceID(BLE::DEFAULT_INSTANCE)
+nRF5xn& nRF5xn::Instance(BLE::InstanceID_t instanceId)
+{
+    if (deviceInstance == NULL)
+        deviceInstance = new nRF5xn();
+
+    return *deviceInstance;
+}
+
+nRF5xn::nRF5xn(void) :
+    initialized(false),
+    instanceID(BLE::DEFAULT_INSTANCE),
+    gapInstance(),
+    gattServerInstance(NULL),
+    gattClientInstance(NULL),
+    securityManagerInstance(NULL)
 {
 }
 
@@ -77,6 +97,20 @@
     return versionString;
 }
 
+/**************************************************************************/
+/*!
+    @brief  Initialize the BLE stack.
+
+    @returns    ble_error_t
+
+    @retval     BLE_ERROR_NONE if everything executed properly and
+                BLE_ERROR_ALREADY_INITIALIZED if the stack has already
+                been initialized (possibly through a call to nRF5xn::init()).
+                BLE_ERROR_INTERNAL_STACK_FAILURE is returned if initialization
+                of the internal stack (SoftDevice) failed.
+
+*/
+/**************************************************************************/
 ble_error_t nRF5xn::init(BLE::InstanceID_t instanceID, FunctionPointerWithContext<BLE::InitializationCompleteCallbackContext *> callback)
 {
     if (initialized) {
@@ -91,7 +125,9 @@
     instanceID   = instanceID;
 
     /* ToDo: Clear memory contents, reset the SD, etc. */
-    btle_init();
+    if (btle_init() != ERROR_NONE) {
+        return BLE_ERROR_INTERNAL_STACK_FAILURE;
+    }
 
     initialized = true;
     BLE::InitializationCompleteCallbackContext context = {
@@ -102,16 +138,69 @@
     return BLE_ERROR_NONE;
 }
 
+/**************************************************************************/
+/*!
+    @brief  Purge the BLE stack of GATT and GAP state.
+
+    @returns    ble_error_t
+
+    @retval     BLE_ERROR_NONE
+                Everything executed properly
+
+    @note  When using S110, GattClient::shutdown() will not be called
+           since Gatt client features are not supported.
+*/
+/**************************************************************************/
 ble_error_t nRF5xn::shutdown(void)
 {
     if (!initialized) {
         return BLE_ERROR_INITIALIZATION_INCOMPLETE;
     }
 
-    if(softdevice_handler_sd_disable() != NRF_SUCCESS) {
+    /*
+     * Shutdown the SoftDevice first. This is because we need to disable all
+     * interrupts. Otherwise if we clear the BLE API and glue code first there
+     * will be many NULL references and no config information which could lead
+     * to errors if the shutdown process is interrupted.
+     */
+    if (softdevice_handler_sd_disable() != NRF_SUCCESS) {
         return BLE_STACK_BUSY;
     }
 
+
+    /* Shutdown the BLE API and nRF51 glue code */
+    ble_error_t error;
+
+    if (gattServerInstance != NULL) {
+        error = gattServerInstance->reset();
+        if (error != BLE_ERROR_NONE) {
+            return error;
+        }
+    }
+
+    if (securityManagerInstance != NULL) {
+        error = securityManagerInstance->reset();
+        if (error != BLE_ERROR_NONE) {
+            return error;
+        }
+    }
+
+    /* S110 does not support BLE client features, nothing to reset. */
+#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
+    if (gattClientInstance != NULL) {
+        error = gattClientInstance->reset();
+        if (error != BLE_ERROR_NONE) {
+            return error;
+        }
+    }
+#endif
+
+    /* Gap instance is always present */
+    error = gapInstance.reset();
+    if (error != BLE_ERROR_NONE) {
+        return error;
+    }
+
     initialized = false;
     return BLE_ERROR_NONE;
 }
--- a/source/nRF5xn.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nRF5xn.h	Wed Apr 06 22:39:17 2016 +0100
@@ -41,32 +41,142 @@
     virtual ble_error_t shutdown(void);
     virtual const char *getVersion(void);
 
+    /**
+     * Accessors to GAP. This function checks whether gapInstance points to an
+     * object. If if does not, then the gapInstance is updated to
+     * &_getInstance before returning.
+     *
+     * @return  A reference to GattServer.
+     *
+     * @note  Unlike the GattClient, GattServer and SecurityManager, Gap is
+     *        always needed in a BLE application. Therefore it is allocated
+     *        statically.
+     */
     virtual Gap &getGap() {
-        return nRF5xGap::getInstance();
+        return gapInstance;
     };
-    virtual const Gap &getGap() const  {
-        return nRF5xGap::getInstance();
-    };
+
+    /**
+     * Accessors to GATT Server. This function checks whether a GattServer
+     * object was previously instantiated. If such object does not exist, then
+     * it is created before returning.
+     *
+     * @return  A reference to GattServer.
+     */
     virtual GattServer &getGattServer() {
-        return nRF5xGattServer::getInstance();
+        if (gattServerInstance == NULL) {
+            gattServerInstance = new nRF5xGattServer();
+        }
+        return *gattServerInstance;
     };
-    virtual const GattServer &getGattServer() const {
-        return nRF5xGattServer::getInstance();
-    };
-    virtual GattClient &getGattClient() {
-        return nRF5xGattClient::getInstance();
+
+    /**
+     * Accessors to GATT Client. This function checks whether a GattClient
+     * object was previously instantiated. If such object does not exist, then
+     * it is created before returning.
+     *
+     * @return  A reference to GattClient.
+     */
+    virtual nRF5xGattClient &getGattClient() {
+        if (gattClientInstance == NULL) {
+            gattClientInstance = new nRF5xGattClient();
+        }
+        return *gattClientInstance;
+    }
+
+    /**
+     * Accessors to Security Manager. This function checks whether a SecurityManager
+     * object was previously instantiated. If such object does not exist, then
+     * it is created before returning.
+     *
+     * @return  A reference to GattServer.
+     */
+    virtual nRF5xSecurityManager &getSecurityManager() {
+        if (securityManagerInstance == NULL) {
+            securityManagerInstance = new nRF5xSecurityManager();
+        }
+        return *securityManagerInstance;
     }
-    virtual const SecurityManager &getSecurityManager() const {
-        return nRF5xSecurityManager::getInstance();
+
+    /**
+     * Accessors to GAP. This function checks whether gapInstance points to an
+     * object. If if does not, then the gapInstance is updated to
+     * &_getInstance before returning.
+     *
+     * @return  A const reference to GattServer.
+     *
+     * @note  Unlike the GattClient, GattServer and SecurityManager, Gap is
+     *        always needed in a BLE application. Therefore it is allocated
+     *        statically.
+     *
+     * @note  The accessor is able to modify the object's state because the
+     *        internal pointer has been declared mutable.
+     */
+    virtual const nRF5xGap &getGap() const  {
+        return gapInstance;
+    };
+
+    /**
+     * Accessors to GATT Server. This function checks whether a GattServer
+     * object was previously instantiated. If such object does not exist, then
+     * it is created before returning.
+     *
+     * @return  A const reference to GattServer.
+     *
+     * @note  The accessor is able to modify the object's state because the
+     *        internal pointer has been declared mutable.
+     */
+    virtual const nRF5xGattServer &getGattServer() const {
+        if (gattServerInstance == NULL) {
+            gattServerInstance = new nRF5xGattServer();
+        }
+        return *gattServerInstance;
+    };
+
+    /**
+     * Accessors to Security Manager. This function checks whether a SecurityManager
+     * object was previously instantiated. If such object does not exist, then
+     * it is created before returning.
+     *
+     * @return  A const reference to GattServer.
+     *
+     * @note  The accessor is able to modify the object's state because the
+     *        internal pointer has been declared mutable.
+     */
+    virtual const nRF5xSecurityManager &getSecurityManager() const {
+        if (securityManagerInstance == NULL) {
+            securityManagerInstance = new nRF5xSecurityManager();
+        }
+        return *securityManagerInstance;
     }
-    virtual SecurityManager &getSecurityManager() {
-        return nRF5xSecurityManager::getInstance();
-    }
+
     virtual void waitForEvent(void);
 
+public:
+    static nRF5xn& Instance(BLE::InstanceID_t instanceId);
+
 private:
     bool              initialized;
     BLE::InstanceID_t instanceID;
+
+private:
+    mutable nRF5xGap gapInstance; /**< Gap instance whose reference is returned from a call to
+                                   * getGap(). Unlike the GattClient, GattServer and
+                                   * SecurityManager, Gap is always needed in a BLE application. */
+
+private:
+    mutable nRF5xGattServer      *gattServerInstance;      /**< Pointer to the GattServer object instance.
+                                                            *   If NULL, then GattServer has not been initialized.
+                                                            *   The pointer has been declared as 'mutable' so that
+                                                            *   it can be assigned inside a 'const' function. */
+    mutable nRF5xGattClient      *gattClientInstance;      /**< Pointer to the GattClient object instance.
+                                                            *   If NULL, then GattClient has not been initialized.
+                                                            *   The pointer has been declared as 'mutable' so that
+                                                            *   it can be assigned inside a 'const' function. */
+    mutable nRF5xSecurityManager *securityManagerInstance; /**< Pointer to the SecurityManager object instance.
+                                                            *   If NULL, then SecurityManager has not been initialized.
+                                                            *   The pointer has been declared as 'mutable' so that
+                                                            *   it can be assigned inside a 'const' function. */
 };
 
 #endif
\ No newline at end of file
--- a/source/nordic-sdk/components/ble/ble_radio_notification/ble_radio_notification.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "ble_radio_notification.h"
-#include <stdlib.h>
-
-
-static bool                                 m_radio_active = false;  /**< Current radio state. */
-static ble_radio_notification_evt_handler_t m_evt_handler  = NULL;   /**< Application event handler for handling Radio Notification events. */
-
-
-void SWI1_IRQHandler(void)
-{
-    m_radio_active = !m_radio_active;
-    if (m_evt_handler != NULL)
-    {
-        m_evt_handler(m_radio_active);
-    }
-}
-
-
-uint32_t ble_radio_notification_init(nrf_app_irq_priority_t               irq_priority,
-                                     nrf_radio_notification_distance_t    distance,
-                                     ble_radio_notification_evt_handler_t evt_handler)
-{
-    uint32_t err_code;
-
-    m_evt_handler = evt_handler;
-
-    // Initialize Radio Notification software interrupt
-    err_code = sd_nvic_ClearPendingIRQ(SWI1_IRQn);
-    if (err_code != NRF_SUCCESS)
-    {
-        return err_code;
-    }
-
-    err_code = sd_nvic_SetPriority(SWI1_IRQn, irq_priority);
-    if (err_code != NRF_SUCCESS)
-    {
-        return err_code;
-    }
-
-    err_code = sd_nvic_EnableIRQ(SWI1_IRQn);
-    if (err_code != NRF_SUCCESS)
-    {
-        return err_code;
-    }
-
-    // Configure the event
-    return sd_radio_notification_cfg_set(NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH, distance);
-}
\ No newline at end of file
--- a/source/nordic-sdk/components/ble/ble_radio_notification/ble_radio_notification.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/** @file
- *
- * @defgroup ble_radio_notification Radio Notification Event Handler
- * @{
- * @ingroup ble_sdk_lib
- * @brief Module for propagating Radio Notification events to the application.
- */
-
-#ifndef BLE_RADIO_NOTIFICATION_H__
-#define BLE_RADIO_NOTIFICATION_H__
-
-#include <stdint.h>
-#include <stdbool.h>
-#include "nrf_soc.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**@brief Application radio notification event handler type. */
-typedef void (*ble_radio_notification_evt_handler_t) (bool radio_active);
-
-/**@brief Function for initializing the Radio Notification module.
- *
- * @param[in]  irq_priority   Interrupt priority for the Radio Notification interrupt handler.
- * @param[in]  distance       The time from an Active event until the radio is activated.
- * @param[in]  evt_handler    Handler to be executed when a radio notification event has been
- *                            received.
- *
- * @return     NRF_SUCCESS on successful initialization, otherwise an error code.
- */
-uint32_t ble_radio_notification_init(nrf_app_irq_priority_t               irq_priority,
-                                     nrf_radio_notification_distance_t    distance,
-                                     ble_radio_notification_evt_handler_t evt_handler);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // BLE_RADIO_NOTIFICATION_H__
-
-/** @} */
\ No newline at end of file
--- a/source/nordic-sdk/components/ble/ble_services/ble_dfu/ble_dfu.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,686 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "ble_dfu.h"
-#include "nrf_error.h"
-#include "ble_types.h"
-#include "ble_gatts.h"
-#include "app_util.h"
-#include "ble_srv_common.h"
-#include "nordic_common.h"
-#include <stdint.h>
-#include <string.h>
-#include <stddef.h>
-
-#define MAX_DFU_PKT_LEN         20                                              /**< Maximum length (in bytes) of the DFU Packet characteristic. */
-#define PKT_START_DFU_PARAM_LEN 2                                               /**< Length (in bytes) of the parameters for Packet Start DFU Request. */
-#define PKT_INIT_DFU_PARAM_LEN  2                                               /**< Length (in bytes) of the parameters for Packet Init DFU Request. */
-#define PKT_RCPT_NOTIF_REQ_LEN  3                                               /**< Length (in bytes) of the Packet Receipt Notification Request. */
-#define MAX_PKTS_RCPT_NOTIF_LEN 6                                               /**< Maximum length (in bytes) of the Packets Receipt Notification. */
-#define MAX_RESPONSE_LEN        7                                               /**< Maximum length (in bytes) of the response to a Control Point command. */
-#define MAX_NOTIF_BUFFER_LEN    MAX(MAX_PKTS_RCPT_NOTIF_LEN, MAX_RESPONSE_LEN)  /**< Maximum length (in bytes) of the buffer needed by DFU Service while sending notifications to peer. */
-
-enum
-{
-    OP_CODE_START_DFU          = 1,                                             /**< Value of the Op code field for 'Start DFU' command.*/
-    OP_CODE_RECEIVE_INIT       = 2,                                             /**< Value of the Op code field for 'Initialize DFU parameters' command.*/
-    OP_CODE_RECEIVE_FW         = 3,                                             /**< Value of the Op code field for 'Receive firmware image' command.*/
-    OP_CODE_VALIDATE           = 4,                                             /**< Value of the Op code field for 'Validate firmware' command.*/
-    OP_CODE_ACTIVATE_N_RESET   = 5,                                             /**< Value of the Op code field for 'Activate & Reset' command.*/
-    OP_CODE_SYS_RESET          = 6,                                             /**< Value of the Op code field for 'Reset System' command.*/
-    OP_CODE_IMAGE_SIZE_REQ     = 7,                                             /**< Value of the Op code field for 'Report received image size' command.*/
-    OP_CODE_PKT_RCPT_NOTIF_REQ = 8,                                             /**< Value of the Op code field for 'Request packet receipt notification.*/
-    OP_CODE_RESPONSE           = 16,                                            /**< Value of the Op code field for 'Response.*/
-    OP_CODE_PKT_RCPT_NOTIF     = 17                                             /**< Value of the Op code field for 'Packets Receipt Notification'.*/
-};
-
-static bool     m_is_dfu_service_initialized = false;                           /**< Variable to check if the DFU service was initialized by the application.*/
-static uint8_t  m_notif_buffer[MAX_NOTIF_BUFFER_LEN];                           /**< Buffer used for sending notifications to peer. */
-
-/**@brief       Function for adding DFU Packet characteristic to the BLE Stack.
- *
- * @param[in]   p_dfu DFU Service structure.
- *
- * @return      NRF_SUCCESS on success. Otherwise an error code.
- */
-static uint32_t dfu_pkt_char_add(ble_dfu_t * const p_dfu)
-{
-    ble_gatts_char_md_t char_md;
-    ble_gatts_attr_t    attr_char_value;
-    ble_uuid_t          char_uuid;
-    ble_gatts_attr_md_t attr_md;
-
-    memset(&char_md, 0, sizeof(char_md));
-
-    char_md.char_props.write_wo_resp = 1;
-    char_md.p_char_user_desc         = NULL;
-    char_md.p_char_pf                = NULL;
-    char_md.p_user_desc_md           = NULL;
-    char_md.p_cccd_md                = NULL;
-    char_md.p_sccd_md                = NULL;
-
-    char_uuid.type = p_dfu->uuid_type;
-    char_uuid.uuid = BLE_DFU_PKT_CHAR_UUID;
-
-    memset(&attr_md, 0, sizeof(attr_md));
-
-    BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.read_perm);
-    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
-
-    attr_md.vloc    = BLE_GATTS_VLOC_STACK;
-    attr_md.rd_auth = 0;
-    attr_md.wr_auth = 0;
-    attr_md.vlen    = 1;
-
-    memset(&attr_char_value, 0, sizeof(attr_char_value));
-
-    attr_char_value.p_uuid    = &char_uuid;
-    attr_char_value.p_attr_md = &attr_md;
-    attr_char_value.init_len  = 0;
-    attr_char_value.init_offs = 0;
-    attr_char_value.max_len   = MAX_DFU_PKT_LEN;
-    attr_char_value.p_value   = NULL;
-
-    return sd_ble_gatts_characteristic_add(p_dfu->service_handle,
-                                           &char_md,
-                                           &attr_char_value,
-                                           &p_dfu->dfu_pkt_handles);
-}
-
-
-/**@brief       Function for adding DFU Revision characteristic to the BLE Stack.
- *
- * @param[in]   p_dfu DFU Service structure.
- *
- * @return      NRF_SUCCESS on success. Otherwise an error code.
- */
-static uint32_t dfu_rev_char_add(ble_dfu_t * const p_dfu, ble_dfu_init_t const * const p_dfu_init)
-{
-    ble_gatts_char_md_t char_md;
-    ble_gatts_attr_t    attr_char_value;
-    ble_uuid_t          char_uuid;
-    ble_gatts_attr_md_t attr_md;
-
-    memset(&char_md, 0, sizeof(char_md));
-
-    char_md.char_props.read          = 1;
-    char_md.p_char_user_desc         = NULL;
-    char_md.p_char_pf                = NULL;
-    char_md.p_user_desc_md           = NULL;
-    char_md.p_cccd_md                = NULL;
-    char_md.p_sccd_md                = NULL;
-
-    char_uuid.type = p_dfu->uuid_type;
-    char_uuid.uuid = BLE_DFU_REV_CHAR_UUID;
-
-    memset(&attr_md, 0, sizeof(attr_md));
-
-    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
-    BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.write_perm);
-
-    attr_md.vloc    = BLE_GATTS_VLOC_STACK;
-    attr_md.rd_auth = 0;
-    attr_md.wr_auth = 0;
-    attr_md.vlen    = 1;
-
-    memset(&attr_char_value, 0, sizeof(attr_char_value));
-
-    attr_char_value.p_uuid    = &char_uuid;
-    attr_char_value.p_attr_md = &attr_md;
-    attr_char_value.init_len  = sizeof(uint16_t);
-    attr_char_value.init_offs = 0;
-    attr_char_value.max_len   = sizeof(uint16_t);
-    attr_char_value.p_value   = (uint8_t *)&p_dfu_init->revision;
-
-    return sd_ble_gatts_characteristic_add(p_dfu->service_handle,
-                                           &char_md,
-                                           &attr_char_value,
-                                           &p_dfu->dfu_rev_handles);
-}
-
-
-/**@brief       Function for adding DFU Control Point characteristic to the BLE Stack.
- *
- * @param[in]   p_dfu DFU Service structure.
- *
- * @return      NRF_SUCCESS on success. Otherwise an error code.
- */
-static uint32_t dfu_ctrl_pt_add(ble_dfu_t * const p_dfu)
-{
-    ble_gatts_char_md_t char_md;
-    ble_gatts_attr_t    attr_char_value;
-    ble_uuid_t          char_uuid;
-    ble_gatts_attr_md_t attr_md;
-
-    memset(&char_md, 0, sizeof(char_md));
-
-    char_md.char_props.write  = 1;
-    char_md.char_props.notify = 1;
-    char_md.p_char_user_desc  = NULL;
-    char_md.p_char_pf         = NULL;
-    char_md.p_user_desc_md    = NULL;
-    char_md.p_cccd_md         = NULL;
-    char_md.p_sccd_md         = NULL;
-
-    char_uuid.type = p_dfu->uuid_type;
-    char_uuid.uuid = BLE_DFU_CTRL_PT_UUID;
-
-    memset(&attr_md, 0, sizeof(attr_md));
-
-    BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.read_perm);
-    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
-
-    attr_md.vloc    = BLE_GATTS_VLOC_STACK;
-    attr_md.rd_auth = 0;
-    attr_md.wr_auth = 1;
-    attr_md.vlen    = 1;
-
-    memset(&attr_char_value, 0, sizeof(attr_char_value));
-
-    attr_char_value.p_uuid    = &char_uuid;
-    attr_char_value.p_attr_md = &attr_md;
-    attr_char_value.init_len  = 0;
-    attr_char_value.init_offs = 0;
-    attr_char_value.max_len   = BLE_L2CAP_MTU_DEF;
-    attr_char_value.p_value   = NULL;
-
-    return sd_ble_gatts_characteristic_add(p_dfu->service_handle,
-                                           &char_md,
-                                           &attr_char_value,
-                                           &p_dfu->dfu_ctrl_pt_handles);
-}
-
-
-/**@brief     Function for handling the @ref BLE_GAP_EVT_CONNECTED event from the S110 SoftDevice.
- *
- * @param[in] p_dfu     DFU Service Structure.
- * @param[in] p_ble_evt Pointer to the event received from BLE stack.
- */
-static void on_connect(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt)
-{
-    p_dfu->conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
-}
-
-
-/**@brief     Function for checking if the CCCD of DFU Control point is configured for Notification.
- *
- * @details   This function checks if the CCCD of DFU Control Point characteristic is configured
- *            for Notification by the DFU Controller.
- *
- * @param[in] p_dfu DFU Service structure.
- *
- * @return    True if the CCCD of DFU Control Point characteristic is configured for Notification.
- *            False otherwise.
- */
-static bool is_cccd_configured(ble_dfu_t * p_dfu)
-{
-    // Check if the CCCDs are configured.
-    uint8_t  cccd_val_buf[BLE_CCCD_VALUE_LEN];
-    ble_gatts_value_t gatts_value;
-
-    // Initialize value struct.
-    memset(&gatts_value, 0, sizeof(gatts_value));
-
-    gatts_value.len     = BLE_CCCD_VALUE_LEN;
-    gatts_value.offset  = 0;
-    gatts_value.p_value = cccd_val_buf;
-
-    // Check the CCCD Value of DFU Control Point.
-    uint32_t err_code = sd_ble_gatts_value_get(p_dfu->conn_handle,
-                                               p_dfu->dfu_ctrl_pt_handles.cccd_handle,
-                                               &gatts_value);
-    if (err_code != NRF_SUCCESS)
-    {
-        if (p_dfu->error_handler != NULL)
-        {
-            p_dfu->error_handler(err_code);
-        }
-        return false;
-    }
-
-    return ble_srv_is_notification_enabled(cccd_val_buf);
-}
-
-
-/**@brief     Function for handling a Write event on the Control Point characteristic.
- *
- * @param[in] p_dfu             DFU Service Structure.
- * @param[in] p_ble_write_evt   Pointer to the write event received from BLE stack.
- *
- * @return    NRF_SUCCESS on successful processing of control point write. Otherwise an error code.
- */
-static uint32_t on_ctrl_pt_write(ble_dfu_t * p_dfu, ble_gatts_evt_write_t * p_ble_write_evt)
-{
-    ble_gatts_rw_authorize_reply_params_t write_authorize_reply;
-
-    write_authorize_reply.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE;
-
-    if (!is_cccd_configured(p_dfu))
-    {
-        // Send an error response to the peer indicating that the CCCD is improperly configured.
-        write_authorize_reply.params.write.gatt_status =
-            BLE_GATT_STATUS_ATTERR_CPS_CCCD_CONFIG_ERROR;
-
-        return (sd_ble_gatts_rw_authorize_reply(p_dfu->conn_handle, &write_authorize_reply));
-
-    }
-    else
-    {
-        uint32_t err_code;
-
-        write_authorize_reply.params.write.gatt_status = BLE_GATT_STATUS_SUCCESS;
-
-        err_code = (sd_ble_gatts_rw_authorize_reply(p_dfu->conn_handle, &write_authorize_reply));
-
-        if (err_code != NRF_SUCCESS)
-        {
-            return err_code;
-        }
-    }
-
-    ble_dfu_evt_t ble_dfu_evt;
-
-    switch (p_ble_write_evt->data[0])
-    {
-        case OP_CODE_START_DFU:
-            ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_START;
-
-            if (p_ble_write_evt->len < PKT_START_DFU_PARAM_LEN)
-            {
-                return ble_dfu_response_send(p_dfu,
-                                             (ble_dfu_procedure_t) p_ble_write_evt->data[0],
-                                             BLE_DFU_RESP_VAL_OPER_FAILED);
-            }
-
-            ble_dfu_evt.evt.ble_dfu_pkt_write.len    = 1;
-            ble_dfu_evt.evt.ble_dfu_pkt_write.p_data = &(p_ble_write_evt->data[1]);
-
-            p_dfu->evt_handler(p_dfu, &ble_dfu_evt);
-            break;
-
-        case OP_CODE_RECEIVE_INIT:
-            ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_RECEIVE_INIT_DATA;
-
-            if (p_ble_write_evt->len < PKT_INIT_DFU_PARAM_LEN)
-            {
-                return ble_dfu_response_send(p_dfu,
-                                             (ble_dfu_procedure_t) p_ble_write_evt->data[0],
-                                             BLE_DFU_RESP_VAL_OPER_FAILED);
-            }
-            
-            ble_dfu_evt.evt.ble_dfu_pkt_write.len    = 1;
-            ble_dfu_evt.evt.ble_dfu_pkt_write.p_data = &(p_ble_write_evt->data[1]);
-
-            p_dfu->evt_handler(p_dfu, &ble_dfu_evt);
-            break;
-
-        case OP_CODE_RECEIVE_FW:
-            ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_RECEIVE_APP_DATA;
-
-            p_dfu->evt_handler(p_dfu, &ble_dfu_evt);
-            break;
-
-        case OP_CODE_VALIDATE:
-            ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_VALIDATE;
-
-            p_dfu->evt_handler(p_dfu, &ble_dfu_evt);
-            break;
-
-        case OP_CODE_ACTIVATE_N_RESET:
-            ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_ACTIVATE_N_RESET;
-
-            p_dfu->evt_handler(p_dfu, &ble_dfu_evt);
-            break;
-
-        case OP_CODE_SYS_RESET:
-            ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_SYS_RESET;
-
-            p_dfu->evt_handler(p_dfu, &ble_dfu_evt);
-            break;
-
-        case OP_CODE_PKT_RCPT_NOTIF_REQ:
-            if (p_ble_write_evt->len < PKT_RCPT_NOTIF_REQ_LEN)
-            {
-                return (ble_dfu_response_send(p_dfu,
-                                              BLE_DFU_PKT_RCPT_REQ_PROCEDURE,
-                                              BLE_DFU_RESP_VAL_NOT_SUPPORTED));
-            }
-
-            ble_dfu_evt.evt.pkt_rcpt_notif_req.num_of_pkts =
-                uint16_decode(&(p_ble_write_evt->data[1]));
-
-            if (ble_dfu_evt.evt.pkt_rcpt_notif_req.num_of_pkts == 0)
-            {
-                ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_PKT_RCPT_NOTIF_DISABLED;
-            }
-            else
-            {
-                ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_PKT_RCPT_NOTIF_ENABLED;
-            }
-
-            p_dfu->evt_handler(p_dfu, &ble_dfu_evt);
-
-            break;
-
-        case OP_CODE_IMAGE_SIZE_REQ:
-            ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_BYTES_RECEIVED_SEND;
-
-            p_dfu->evt_handler(p_dfu, &ble_dfu_evt);
-            break;
-
-        default:
-            // Unsupported op code.
-            return ble_dfu_response_send(p_dfu,
-                                         (ble_dfu_procedure_t) p_ble_write_evt->data[0],
-                                         BLE_DFU_RESP_VAL_NOT_SUPPORTED);
-    }
-    return NRF_SUCCESS;
-}
-
-
-/**@brief     Function for handling the @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event from the S110
- *            Stack.
- *
- * @param[in] p_dfu     DFU Service Structure.
- * @param[in] p_ble_evt Pointer to the event received from BLE stack.
- */
-static void on_rw_authorize_req(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt)
-{
-    ble_gatts_evt_rw_authorize_request_t * p_authorize_request;
-
-    p_authorize_request = &(p_ble_evt->evt.gatts_evt.params.authorize_request);
-
-    if (
-        (p_authorize_request->type == BLE_GATTS_AUTHORIZE_TYPE_WRITE)
-        &&
-        (p_authorize_request->request.write.handle == p_dfu->dfu_ctrl_pt_handles.value_handle)
-        && 
-        (p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.op != BLE_GATTS_OP_PREP_WRITE_REQ)
-        &&
-        (p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.op != BLE_GATTS_OP_EXEC_WRITE_REQ_NOW)
-        &&
-        (p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.op != BLE_GATTS_OP_EXEC_WRITE_REQ_CANCEL)
-       )
-    {
-        uint32_t err_code;
-
-        err_code = on_ctrl_pt_write(p_dfu, &(p_authorize_request->request.write));
-
-        if (err_code != NRF_SUCCESS && p_dfu->error_handler != NULL)
-        {
-            p_dfu->error_handler(err_code);
-        }
-    }
-}
-
-
-/**@brief     Function for handling the @ref BLE_GATTS_EVT_WRITE event from the S110 SoftDevice.
- *
- * @param[in] p_dfu     DFU Service Structure.
- * @param[in] p_ble_evt Pointer to the event received from BLE stack.
- */
-static void on_write(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt)
-{
-    if (p_ble_evt->evt.gatts_evt.params.write.handle == p_dfu->dfu_pkt_handles.value_handle)
-    {
-        // DFU Packet written
-
-        ble_dfu_evt_t ble_dfu_evt;
-
-        ble_dfu_evt.ble_dfu_evt_type             = BLE_DFU_PACKET_WRITE;
-        ble_dfu_evt.evt.ble_dfu_pkt_write.len    = p_ble_evt->evt.gatts_evt.params.write.len;
-        ble_dfu_evt.evt.ble_dfu_pkt_write.p_data = p_ble_evt->evt.gatts_evt.params.write.data;
-
-        p_dfu->evt_handler(p_dfu, &ble_dfu_evt);
-    }
-}
-
-
-/**@brief     Function for handling the BLE_GAP_EVT_DISCONNECTED event from the S110 SoftDevice.
- *
- * @param[in] p_dfu     DFU Service Structure.
- * @param[in] p_ble_evt Pointer to the event received from BLE stack.
- */
-static void on_disconnect(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt)
-{
-    p_dfu->conn_handle = BLE_CONN_HANDLE_INVALID;
-}
-
-
-uint32_t ble_dfu_init(ble_dfu_t * p_dfu, ble_dfu_init_t * p_dfu_init)
-{
-    if ((p_dfu == NULL) || (p_dfu_init == NULL) || (p_dfu_init->evt_handler == NULL))
-    {
-        return NRF_ERROR_NULL;
-    }
-
-    p_dfu->conn_handle = BLE_CONN_HANDLE_INVALID;
-
-    ble_uuid_t service_uuid;
-    uint32_t   err_code;
-
-    const ble_uuid128_t base_uuid128 =
-    {
-        {
-            0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15,
-            0xDE, 0xEF, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00
-        }
-    };
-
-    service_uuid.uuid = BLE_DFU_SERVICE_UUID;
-
-    err_code = sd_ble_uuid_vs_add(&base_uuid128, &(service_uuid.type));
-    if (err_code != NRF_SUCCESS)
-    {
-        return err_code;
-    }
-
-    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
-                                        &service_uuid,
-                                        &(p_dfu->service_handle));
-    if (err_code != NRF_SUCCESS)
-    {
-        return err_code;
-    }
-
-    p_dfu->uuid_type = service_uuid.type;
-
-    err_code = dfu_pkt_char_add(p_dfu);
-    if (err_code != NRF_SUCCESS)
-    {
-        return err_code;
-    }
-
-    err_code = dfu_ctrl_pt_add(p_dfu);
-    if (err_code != NRF_SUCCESS)
-    {
-        return err_code;
-    }
-
-    err_code = dfu_rev_char_add(p_dfu, p_dfu_init);
-    if (err_code != NRF_SUCCESS)
-    {
-        return err_code;
-    }
-
-    p_dfu->evt_handler = p_dfu_init->evt_handler;
-
-    if (p_dfu_init->error_handler != NULL)
-    {
-        p_dfu->error_handler = p_dfu_init->error_handler;
-    }
-
-    m_is_dfu_service_initialized = true;
-
-    return NRF_SUCCESS;
-}
-
-
-void ble_dfu_on_ble_evt(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt)
-{
-    if ((p_dfu == NULL) || (p_ble_evt == NULL))
-    {
-        return;
-    }
-
-    if (p_dfu->evt_handler != NULL)
-    {
-        switch (p_ble_evt->header.evt_id)
-        {
-            case BLE_GAP_EVT_CONNECTED:
-                on_connect(p_dfu, p_ble_evt);
-                break;
-
-            case BLE_GATTS_EVT_WRITE:
-                on_write(p_dfu, p_ble_evt);
-                break;
-
-            case BLE_GAP_EVT_DISCONNECTED:
-                on_disconnect(p_dfu, p_ble_evt);
-                break;
-
-            case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
-                on_rw_authorize_req(p_dfu, p_ble_evt);
-                break;
-
-            default:
-                // No implementation needed.
-                break;
-        }
-    }
-}
-
-
-uint32_t ble_dfu_bytes_rcvd_report(ble_dfu_t * p_dfu, uint32_t num_of_firmware_bytes_rcvd)
-{
-    if (p_dfu == NULL)
-    {
-        return NRF_ERROR_NULL;
-    }
-
-    if ((p_dfu->conn_handle == BLE_CONN_HANDLE_INVALID) || !m_is_dfu_service_initialized)
-    {
-        return NRF_ERROR_INVALID_STATE;
-    }
-
-    ble_gatts_hvx_params_t hvx_params;
-    uint16_t               index = 0;
-
-    // Encode the Op Code.
-    m_notif_buffer[index++] = OP_CODE_RESPONSE;
-
-    // Encode the Reqest Op Code.
-    m_notif_buffer[index++] = OP_CODE_IMAGE_SIZE_REQ;
-
-    // Encode the Response Value.
-    m_notif_buffer[index++] = (uint8_t)BLE_DFU_RESP_VAL_SUCCESS;
-
-    index += uint32_encode(num_of_firmware_bytes_rcvd, &m_notif_buffer[index]);
-
-    memset(&hvx_params, 0, sizeof(hvx_params));
-
-    hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle;
-    hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
-    hvx_params.offset = 0;
-    hvx_params.p_len  = &index;
-    hvx_params.p_data = m_notif_buffer;
-
-    return sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params);
-}
-
-
-uint32_t ble_dfu_pkts_rcpt_notify(ble_dfu_t * p_dfu, uint32_t num_of_firmware_bytes_rcvd)
-{
-    if (p_dfu == NULL)
-    {
-        return NRF_ERROR_NULL;
-    }
-
-    if ((p_dfu->conn_handle == BLE_CONN_HANDLE_INVALID) || !m_is_dfu_service_initialized)
-    {
-        return NRF_ERROR_INVALID_STATE;
-    }
-
-    ble_gatts_hvx_params_t hvx_params;
-    uint16_t               index = 0;
-
-    m_notif_buffer[index++] = OP_CODE_PKT_RCPT_NOTIF;
-
-    index += uint32_encode(num_of_firmware_bytes_rcvd, &m_notif_buffer[index]);
-
-    memset(&hvx_params, 0, sizeof(hvx_params));
-
-    hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle;
-    hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
-    hvx_params.offset = 0;
-    hvx_params.p_len  = &index;
-    hvx_params.p_data = m_notif_buffer;
-
-    return sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params);
-}
-
-
-uint32_t ble_dfu_response_send(ble_dfu_t         * p_dfu,
-                               ble_dfu_procedure_t dfu_proc,
-                               ble_dfu_resp_val_t  resp_val)
-{
-    if (p_dfu == NULL)
-    {
-        return NRF_ERROR_NULL;
-    }
-
-    if ((p_dfu->conn_handle == BLE_CONN_HANDLE_INVALID) || !m_is_dfu_service_initialized)
-    {
-        return NRF_ERROR_INVALID_STATE;
-    }
-
-    ble_gatts_hvx_params_t hvx_params;
-    uint16_t               index = 0;
-
-    m_notif_buffer[index++] = OP_CODE_RESPONSE;
-
-    // Encode the Request Op code
-    m_notif_buffer[index++] = (uint8_t)dfu_proc;
-
-    // Encode the Response Value.
-    m_notif_buffer[index++] = (uint8_t)resp_val;
-
-    memset(&hvx_params, 0, sizeof(hvx_params));
-
-    hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle;
-    hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
-    hvx_params.offset = 0;
-    hvx_params.p_len  = &index;
-    hvx_params.p_data = m_notif_buffer;
-
-    return sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params);
-}
\ No newline at end of file
--- a/source/nordic-sdk/components/ble/ble_services/ble_dfu/ble_dfu.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,259 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/**@file
- *
- * @defgroup ble_sdk_srv_dfu Device Firmware Update Service
- * @{
- * @ingroup  ble_sdk_srv
- * @brief    Device Firmware Update Service
- *
- * @details  The Device Firmware Update (DFU) service is a GATT based service that can be used for
- *           performing firmware updates over BLE. Note that this implementation uses vendor
- *           specific UUIDs for service and characteristics and is intended to demonstrate the
- *           firmware updates over BLE. Refer @ref ota_spec_sec and @ref
- *            ota_profile_section for more information on the service and profile respectively.
- */
-
-#ifndef BLE_DFU_H__
-#define BLE_DFU_H__
-
-#include <stdint.h>
-#include "ble_gatts.h"
-#include "ble_gap.h"
-#include "ble.h"
-#include "ble_srv_common.h"
-
-#define BLE_DFU_SERVICE_UUID                 0x1530                       /**< The UUID of the DFU Service. */
-#define BLE_DFU_PKT_CHAR_UUID                0x1532                       /**< The UUID of the DFU Packet Characteristic. */
-#define BLE_DFU_CTRL_PT_UUID                 0x1531                       /**< The UUID of the DFU Control Point. */
-#define BLE_DFU_STATUS_REP_UUID              0x1533                       /**< The UUID of the DFU Status Report Characteristic. */
-#define BLE_DFU_REV_CHAR_UUID                0x1534                       /**< The UUID of the DFU Revision Characteristic. */
-
-/**@brief   DFU Event type.
- *
- * @details This enumeration contains the types of events that will be received from the DFU Service.
- */
-typedef enum
-{
-    BLE_DFU_START,                                                      /**< The event indicating that the peer wants the application to prepare for a new firmware update. */
-    BLE_DFU_RECEIVE_INIT_DATA,                                          /**< The event indicating that the peer wants the application to prepare to receive init parameters. */
-    BLE_DFU_RECEIVE_APP_DATA,                                           /**< The event indicating that the peer wants the application to prepare to receive the new firmware image. */
-    BLE_DFU_VALIDATE,                                                   /**< The event indicating that the peer wants the application to validate the newly received firmware image. */
-    BLE_DFU_ACTIVATE_N_RESET,                                           /**< The event indicating that the peer wants the application to undergo activate new firmware and restart with new valid application */
-    BLE_DFU_SYS_RESET,                                                  /**< The event indicating that the peer wants the application to undergo a reset and start the currently valid application image.*/
-    BLE_DFU_PKT_RCPT_NOTIF_ENABLED,                                     /**< The event indicating that the peer has enabled packet receipt notifications. It is the responsibility of the application to call @ref ble_dfu_pkts_rcpt_notify each time the number of packets indicated by num_of_pkts field in @ref ble_dfu_evt_t is received.*/
-    BLE_DFU_PKT_RCPT_NOTIF_DISABLED,                                    /**< The event indicating that the peer has disabled the packet receipt notifications.*/
-    BLE_DFU_PACKET_WRITE,                                               /**< The event indicating that the peer has written a value to the 'DFU Packet' characteristic. The data received from the peer will be present in the @ref BLE_DFU_PACKET_WRITE element contained within @ref ble_dfu_evt_t.*/
-    BLE_DFU_BYTES_RECEIVED_SEND                                         /**< The event indicating that the peer is requesting for the number of bytes of firmware data last received by the application. It is the responsibility of the application to call @ref ble_dfu_pkts_rcpt_notify in response to this event. */
-} ble_dfu_evt_type_t;
-
-/**@brief   DFU Procedure type.
- *
- * @details This enumeration contains the types of DFU procedures.
- */
-typedef enum
-{
-    BLE_DFU_START_PROCEDURE        = 1,                                 /**< DFU Start procedure.*/
-    BLE_DFU_INIT_PROCEDURE         = 2,                                 /**< DFU Initialization procedure.*/
-    BLE_DFU_RECEIVE_APP_PROCEDURE  = 3,                                 /**< Firmware receiving procedure.*/
-    BLE_DFU_VALIDATE_PROCEDURE     = 4,                                 /**< Firmware image validation procedure .*/
-    BLE_DFU_PKT_RCPT_REQ_PROCEDURE = 8                                  /**< Packet receipt notification request procedure. */
-} ble_dfu_procedure_t;
-
-/**@brief   DFU Response value type.
- */
-typedef enum
-{
-    BLE_DFU_RESP_VAL_SUCCESS = 1,                                       /**< Success.*/
-    BLE_DFU_RESP_VAL_INVALID_STATE,                                     /**< Invalid state.*/
-    BLE_DFU_RESP_VAL_NOT_SUPPORTED,                                     /**< Operation not supported.*/
-    BLE_DFU_RESP_VAL_DATA_SIZE,                                         /**< Data size exceeds limit.*/
-    BLE_DFU_RESP_VAL_CRC_ERROR,                                         /**< CRC Error.*/
-    BLE_DFU_RESP_VAL_OPER_FAILED                                        /**< Operation failed.*/
-} ble_dfu_resp_val_t;
-
-
-/**@brief   DFU Packet structure.
- *
- * @details This structure contains the value of the DFU Packet characteristic as written by the
- *          peer and the length of the value written. It will be filled by the DFU Service when the
- *          peer writes to the DFU Packet characteristic.
- */
-typedef struct
-{
-    uint8_t                      len;                                   /**< Length of the packet received. */
-    uint8_t *                    p_data;                                /**< Pointer to the received packet. This will point to a word aligned memory location.*/
-} ble_dfu_pkt_write_t;
-
-/**@brief   Packet receipt notification request structure.
- *
- * @details This structure contains the contents of the packet receipt notification request
- *          sent by the DFU Controller.
- */
-typedef struct
-{
-    uint16_t                     num_of_pkts;                           /**< The number of packets of firmware data to be received by application before sending the next Packet Receipt Notification to the peer. */
-} ble_pkt_rcpt_notif_req_t;
-
-/**@brief   DFU Event structure.
- *
- * @details This structure contains the event generated by the DFU Service based on the data
- *          received from the peer.
- */
-typedef struct
-{
-    ble_dfu_evt_type_t           ble_dfu_evt_type;                      /**< Type of the event.*/
-    union
-    {
-        ble_dfu_pkt_write_t      ble_dfu_pkt_write;                     /**< The DFU packet received. This field is when the @ref ble_dfu_evt_type field is set to @ref BLE_DFU_PACKET_WRITE.*/
-        ble_pkt_rcpt_notif_req_t pkt_rcpt_notif_req;                    /**< Packet receipt notification request. This field is when the @ref ble_dfu_evt_type field is set to @ref BLE_DFU_PKT_RCPT_NOTIF_ENABLED.*/
-    } evt;
-} ble_dfu_evt_t;
-
-// Forward declaration of the ble_dfu_t type.
-typedef struct ble_dfu_s ble_dfu_t;
-
-/**@brief DFU Service event handler type. */
-typedef void (*ble_dfu_evt_handler_t) (ble_dfu_t * p_dfu, ble_dfu_evt_t * p_evt);
-
-/**@brief   DFU service structure.
- *
- * @details This structure contains status information related to the service.
- */
-struct ble_dfu_s
-{
-    uint16_t                     conn_handle;                           /**< Handle of the current connection (as provided by the S110 SoftDevice). This will be BLE_CONN_HANDLE_INVALID when not in a connection. */
-    uint16_t                     revision;                              /**< Handle of DFU Service (as provided by the S110 SoftDevice). */
-    uint16_t                     service_handle;                        /**< Handle of DFU Service (as provided by the S110 SoftDevice). */
-    uint8_t                      uuid_type;                             /**< UUID type assigned for DFU Service by the S110 SoftDevice. */
-    ble_gatts_char_handles_t     dfu_pkt_handles;                       /**< Handles related to the DFU Packet characteristic. */
-    ble_gatts_char_handles_t     dfu_ctrl_pt_handles;                   /**< Handles related to the DFU Control Point characteristic. */
-    ble_gatts_char_handles_t     dfu_status_rep_handles;                /**< Handles related to the DFU Status Report characteristic. */
-    ble_gatts_char_handles_t     dfu_rev_handles;                       /**< Handles related to the DFU Revision characteristic. */
-    ble_dfu_evt_handler_t        evt_handler;                           /**< The event handler to be called when an event is to be sent to the application.*/
-    ble_srv_error_handler_t      error_handler;                         /**< Function to be called in case of an error. */
-};
-
-/**@brief      DFU service initialization structure.
- *
- * @details    This structure contains the initialization information for the DFU Service. The
- *             application needs to fill this structure and pass it to the DFU Service using the
- *             @ref ble_dfu_init function.
- */
-typedef struct
-{
-    uint16_t                     revision;                              /**< Revision number to be exposed by the DFU service. */
-    ble_dfu_evt_handler_t        evt_handler;                           /**< Event handler to be called for handling events in the Device Firmware Update Service. */
-    ble_srv_error_handler_t      error_handler;                         /**< Function to be called in case of an error. */
-} ble_dfu_init_t;
-
-/**@brief      Function for handling a BLE event.
- *
- * @details    The DFU service expects the application to call this function each time an event
- *             is received from the S110 SoftDevice. This function processes the event, if it is
- *             relevant for the DFU service and calls the DFU event handler of the application if
- *             necessary.
- *
- * @param[in]  p_dfu        Pointer to the DFU service structure.
- * @param[in]  p_ble_evt    Pointer to the event received from S110 SoftDevice.
- */
-void ble_dfu_on_ble_evt(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt);
-
-/**@brief      Function for initializing the DFU service.
- *
- * @param[out] p_dfu        Device Firmware Update service structure. This structure will have to be
- *                          supplied by the application. It will be initialized by this function,
- *                          and will later be used to identify the service instance.
- * @param[in]  p_dfu_init   Information needed to initialize the service.
- *
- * @return     NRF_SUCCESS if the DFU service and its characteristics were successfully added to the
- *             S110 SoftDevice. Otherwise an error code.
- *             This function returns NRF_ERROR_NULL if the value of evt_handler in p_dfu_init
- *             structure provided is NULL or if the pointers supplied as input are NULL.
- */
-uint32_t ble_dfu_init(ble_dfu_t * p_dfu, ble_dfu_init_t * p_dfu_init);
-
-/**@brief       Function for sending response to a control point command.
- *
- * @details     This function will encode a DFU Control Point response using the given input
- *              parameters and will send a notification of the same to the peer.
- *
- * @param[in]   p_dfu       Pointer to the DFU service structure.
- * @param[in]   dfu_proc    Procedure for which this response is to be sent.
- * @param[in]   resp_val    Response value.
- *
- * @return      NRF_SUCCESS if the DFU Service has successfully requested the S110 SoftDevice to
- *              send the notification. Otherwise an error code.
- *              This function returns NRF_ERROR_INVALID_STATE if the device is not connected to a
- *              peer or if the DFU service is not initialized or if the notification of the DFU
- *              Status Report characteristic was not enabled by the peer. It returns NRF_ERROR_NULL
- *              if the pointer p_dfu is NULL.
- */
-uint32_t ble_dfu_response_send(ble_dfu_t *          p_dfu,
-                               ble_dfu_procedure_t  dfu_proc,
-                               ble_dfu_resp_val_t   resp_val);
-
-/**@brief      Function for notifying the peer about the number of bytes of firmware data received.
- *
- * @param[in]  p_dfu                      Pointer to the DFU service structure.
- * @param[in]  num_of_firmware_bytes_rcvd Number of bytes.
- *
- * @return     NRF_SUCCESS if the DFU Service has successfully requested the S110 SoftDevice to send
- *             the notification. Otherwise an error code.
- *             This function returns NRF_ERROR_INVALID_STATE if the device is not connected to a
- *             peer or if the DFU service is not initialized or if the notification of the DFU
- *             Status Report characteristic was not enabled by the peer. It returns NRF_ERROR_NULL
- *             if the pointer p_dfu is NULL.
- */
-uint32_t ble_dfu_bytes_rcvd_report(ble_dfu_t * p_dfu, uint32_t num_of_firmware_bytes_rcvd);
-
-/**@brief      Function for sending Packet Receipt Notification to the peer.
- *
- *             This function will encode the number of bytes received as input parameter into a
- *             notification of the control point characteristic and send it to the peer.
- *
- * @param[in]  p_dfu                      Pointer to the DFU service structure.
- * @param[in]  num_of_firmware_bytes_rcvd Number of bytes of firmware image received.
- *
- * @return     NRF_SUCCESS if the DFU Service has successfully requested the S110 SoftDevice to send
- *             the notification. Otherwise an error code.
- *             This function returns NRF_ERROR_INVALID_STATE if the device is not connected to a
- *             peer or if the DFU service is not initialized or if the notification of the DFU
- *             Status Report characteristic was not enabled by the peer. It returns NRF_ERROR_NULL
- *             if the pointer p_dfu is NULL.
- */
-uint32_t ble_dfu_pkts_rcpt_notify(ble_dfu_t * p_dfu, uint32_t num_of_firmware_bytes_rcvd);
-
-#endif // BLE_DFU_H__
-
-/** @} */
\ No newline at end of file
--- a/source/nordic-sdk/components/ble/common/ble_advdata.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,609 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "ble_advdata.h"
-#include "nordic_common.h"
-#include "nrf_error.h"
-#include "ble_gap.h"
-#include "ble_srv_common.h"
-#include "app_util.h"
-
-
-// Offset from where advertisement data other than flags information can start.
-#define ADV_FLAG_OFFSET 2
-
-// Offset for Advertising Data.
-// Offset is 2 as each Advertising Data contain 1 octet of Adveritising Data Type and
-// one octet Advertising Data Length.
-#define ADV_DATA_OFFSET 2
-
-// NOTE: For now, Security Manager TK Value and Security Manager Out of Band Flags (OOB) are omitted
-//       from the advertising data.
-
-
-static uint32_t name_encode(const ble_advdata_t * p_advdata,
-                            uint8_t             * p_encoded_data,
-                            uint8_t             * p_len)
-{
-    uint32_t err_code;
-    uint16_t rem_adv_data_len;
-    uint16_t actual_length;
-    uint8_t  adv_data_format;
-    uint8_t  adv_offset;
-
-    adv_offset = *p_len;
-
-
-    // Check for buffer overflow.
-    if ((adv_offset + ADV_DATA_OFFSET > BLE_GAP_ADV_MAX_SIZE) ||
-        ((p_advdata->short_name_len + ADV_DATA_OFFSET) > BLE_GAP_ADV_MAX_SIZE))
-    {
-        return NRF_ERROR_DATA_SIZE;
-    }
-    actual_length = rem_adv_data_len = (BLE_GAP_ADV_MAX_SIZE - adv_offset - ADV_FLAG_OFFSET);
-
-    // Get GAP device name and length
-    err_code = sd_ble_gap_device_name_get(&p_encoded_data[adv_offset + ADV_DATA_OFFSET],
-                                          &actual_length);
-    if (err_code != NRF_SUCCESS)
-    {
-        return err_code;
-    }
-    
-    // Check if device internd to use short name and it can fit available data size.
-    if ((p_advdata->name_type == BLE_ADVDATA_FULL_NAME) && (actual_length <= rem_adv_data_len))
-    {
-        // Complete device name can fit, setting Complete Name in Adv Data.
-        adv_data_format  = BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME;
-        rem_adv_data_len = actual_length;
-    }
-    else
-    {
-        // Else short name needs to be used. Or application has requested use of short name.
-        adv_data_format = BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME;
-
-        // If application has set a preference on the short name size, it needs to be considered,
-        // else fit what can be fit.
-        if ((p_advdata->short_name_len != 0) && (p_advdata->short_name_len <= rem_adv_data_len))
-        {
-            // Short name fits available size.
-            rem_adv_data_len = p_advdata->short_name_len;
-        }
-        // Else whatever can fit the data buffer will be packed.
-        else
-        {
-            rem_adv_data_len = actual_length;
-        }
-    }
-
-    // Complete name field in encoded data.
-    p_encoded_data[adv_offset++] = rem_adv_data_len + 1;
-    p_encoded_data[adv_offset++] = adv_data_format;
-    (*p_len)                    += (rem_adv_data_len + ADV_DATA_OFFSET);
-
-    return NRF_SUCCESS;
-}
-
-
-static uint32_t appearance_encode(uint8_t * p_encoded_data, uint8_t * p_len)
-{
-    uint32_t err_code;
-    uint16_t appearance;
-
-    // Check for buffer overflow.
-    if ((*p_len) + 4 > BLE_GAP_ADV_MAX_SIZE)
-    {
-        return NRF_ERROR_DATA_SIZE;
-    }
-
-    // Get GAP appearance field.
-    err_code = sd_ble_gap_appearance_get(&appearance);
-    if (err_code != NRF_SUCCESS)
-    {
-        return err_code;
-    }
-
-    // Encode Length, AD Type and Appearance.
-    p_encoded_data[(*p_len)++] = 3;
-    p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_APPEARANCE;
-
-    (*p_len) += uint16_encode(appearance, &p_encoded_data[*p_len]);
-
-    return NRF_SUCCESS;
-}
-
-
-static uint32_t tx_power_level_encode(int8_t    tx_power_level,
-                                      uint8_t * p_encoded_data,
-                                      uint8_t * p_len)
-{
-    // Check for buffer overflow.
-    if ((*p_len) + 3 > BLE_GAP_ADV_MAX_SIZE)
-    {
-        return NRF_ERROR_DATA_SIZE;
-    }
-
-    // Encode TX Power Level.
-    p_encoded_data[(*p_len)++] = 2;
-    p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_TX_POWER_LEVEL;
-    p_encoded_data[(*p_len)++] = (uint8_t)tx_power_level;
-
-    return NRF_SUCCESS;
-}
-
-
-static uint32_t uuid_list_sized_encode(const ble_advdata_uuid_list_t * p_uuid_list,
-                                       uint8_t                         adv_type,
-                                       uint8_t                         uuid_size,
-                                       uint8_t                       * p_encoded_data,
-                                       uint8_t                       * p_len)
-{
-    int     i;
-    bool    is_heading_written = false;
-    uint8_t start_pos          = *p_len;
-
-    for (i = 0; i < p_uuid_list->uuid_cnt; i++)
-    {
-        uint32_t   err_code;
-        uint8_t    encoded_size;
-        ble_uuid_t uuid = p_uuid_list->p_uuids[i];
-        
-        // Find encoded uuid size.
-        err_code = sd_ble_uuid_encode(&uuid, &encoded_size, NULL);
-        if (err_code != NRF_SUCCESS)
-        {
-            return err_code;
-        }
-
-        // Check size.
-        if (encoded_size == uuid_size)
-        {
-            uint8_t heading_bytes = (is_heading_written) ? 0 : 2;
-            
-            // Check for buffer overflow
-            if (*p_len + encoded_size + heading_bytes > BLE_GAP_ADV_MAX_SIZE)
-            {
-                return NRF_ERROR_DATA_SIZE;
-            }
-
-            if (!is_heading_written)
-            {
-                // Write AD structure heading.
-                (*p_len)++;
-                p_encoded_data[(*p_len)++] = adv_type;
-                is_heading_written         = true;
-            }
-
-            // Write UUID.
-            err_code = sd_ble_uuid_encode(&uuid, &encoded_size, &p_encoded_data[*p_len]);
-            if (err_code != NRF_SUCCESS)
-            {
-                return err_code;
-            }
-            (*p_len) += encoded_size;
-        }
-    }
-
-    if (is_heading_written)
-    {
-        // Write length.
-        p_encoded_data[start_pos] = (*p_len) - (start_pos + 1);
-    }
-
-    return NRF_SUCCESS;
-}
-
-
-static uint32_t uuid_list_encode(const ble_advdata_uuid_list_t * p_uuid_list,
-                                 uint8_t                         adv_type_16,
-                                 uint8_t                         adv_type_128,
-                                 uint8_t                       * p_encoded_data,
-                                 uint8_t                       * p_len)
-{
-    uint32_t err_code;
-
-    // Encode 16 bit UUIDs.
-    err_code = uuid_list_sized_encode(p_uuid_list,
-                                      adv_type_16,
-                                      sizeof(uint16_le_t),
-                                      p_encoded_data,
-                                      p_len);
-    if (err_code != NRF_SUCCESS)
-    {
-        return err_code;
-    }
-
-    // Encode 128 bit UUIDs.
-    err_code = uuid_list_sized_encode(p_uuid_list,
-                                      adv_type_128,
-                                      sizeof(ble_uuid128_t),
-                                      p_encoded_data,
-                                      p_len);
-    if (err_code != NRF_SUCCESS)
-    {
-        return err_code;
-    }
-
-    return NRF_SUCCESS;
-}
-
-
-static uint32_t conn_int_check(const ble_advdata_conn_int_t *p_conn_int)
-{
-    // Check Minimum Connection Interval.
-    if ((p_conn_int->min_conn_interval < 0x0006) ||
-        (
-            (p_conn_int->min_conn_interval > 0x0c80) &&
-            (p_conn_int->min_conn_interval != 0xffff)
-        )
-       )
-    {
-        return NRF_ERROR_INVALID_PARAM;
-    }
-
-    // Check Maximum Connection Interval.
-    if ((p_conn_int->max_conn_interval < 0x0006) || 
-        (
-            (p_conn_int->max_conn_interval > 0x0c80) && 
-            (p_conn_int->max_conn_interval != 0xffff)
-        )
-       )
-    {
-        return NRF_ERROR_INVALID_PARAM;
-    }
-
-    // Make sure Minimum Connection Interval is not bigger than Maximum Connection Interval.
-    if ((p_conn_int->min_conn_interval != 0xffff) &&
-        (p_conn_int->max_conn_interval != 0xffff) &&
-        (p_conn_int->min_conn_interval > p_conn_int->max_conn_interval)
-        )
-    {
-        return NRF_ERROR_INVALID_PARAM;
-    }
-
-    return NRF_SUCCESS;
-}
-
-
-static uint32_t conn_int_encode(const ble_advdata_conn_int_t * p_conn_int,
-                                uint8_t                      * p_encoded_data,
-                                uint8_t                      * p_len)
-{
-    uint32_t err_code;
-
-    // Check for buffer overflow.
-    if ((*p_len) + ADV_DATA_OFFSET + 2 * sizeof(uint16_le_t) > BLE_GAP_ADV_MAX_SIZE)
-    {
-        return NRF_ERROR_DATA_SIZE;
-    }
-
-    // Check parameters.
-    err_code = conn_int_check(p_conn_int);
-    if (err_code != NRF_SUCCESS)
-    {
-        return err_code;
-    }
-
-    // Encode Length and AD Type.
-    p_encoded_data[(*p_len)++] = 1 + 2 * sizeof(uint16_le_t);
-    p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_SLAVE_CONNECTION_INTERVAL_RANGE;
-
-    // Encode Minimum and Maximum Connection Intervals.
-    (*p_len) += uint16_encode(p_conn_int->min_conn_interval, &p_encoded_data[*p_len]);
-    (*p_len) += uint16_encode(p_conn_int->max_conn_interval, &p_encoded_data[*p_len]);
-
-    return NRF_SUCCESS;
-}
-
-
-static uint32_t manuf_specific_data_encode(const ble_advdata_manuf_data_t * p_manuf_sp_data,
-                                           uint8_t                        * p_encoded_data,
-                                           uint8_t                        * p_len)
-{
-    uint8_t data_size = sizeof(uint16_le_t) + p_manuf_sp_data->data.size;
-
-    // Check for buffer overflow.
-    if ((*p_len) + ADV_DATA_OFFSET + data_size > BLE_GAP_ADV_MAX_SIZE)
-    {
-        return NRF_ERROR_DATA_SIZE;
-    }
-
-    // Encode Length and AD Type.
-    p_encoded_data[(*p_len)++] = 1 + data_size;
-    p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA;
-    
-    // Encode Company Identifier.
-    (*p_len) += uint16_encode(p_manuf_sp_data->company_identifier, &p_encoded_data[*p_len]);
-    
-    // Encode additional manufacturer specific data.
-    if (p_manuf_sp_data->data.size > 0)
-    {
-        if (p_manuf_sp_data->data.p_data == NULL)
-        {
-            return NRF_ERROR_INVALID_PARAM;
-        }
-        memcpy(&p_encoded_data[*p_len], p_manuf_sp_data->data.p_data, p_manuf_sp_data->data.size);
-        (*p_len) += p_manuf_sp_data->data.size;
-    }
-
-    return NRF_SUCCESS;
-}
-
-
-static uint32_t service_data_encode(const ble_advdata_t * p_advdata,
-                                    uint8_t             * p_encoded_data,
-                                    uint8_t             * p_len)
-{
-    uint8_t i;
-
-    // Check parameter consistency.
-    if (p_advdata->p_service_data_array == NULL)
-    {
-        return NRF_ERROR_INVALID_PARAM;
-    }
-
-    for (i = 0; i < p_advdata->service_data_count; i++)
-    {
-        ble_advdata_service_data_t * p_service_data;
-        uint8_t                      data_size;
-
-        p_service_data = &p_advdata->p_service_data_array[i];
-        data_size      = sizeof(uint16_le_t) + p_service_data->data.size;
-
-        // Encode Length and AD Type.
-        p_encoded_data[(*p_len)++] = 1 + data_size;
-        p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_SERVICE_DATA;
-
-        // Encode service UUID.
-        (*p_len) += uint16_encode(p_service_data->service_uuid, &p_encoded_data[*p_len]);
-
-        // Encode additional service data.
-        if (p_service_data->data.size > 0)
-        {
-            if (p_service_data->data.p_data == NULL)
-            {
-                return NRF_ERROR_INVALID_PARAM;
-            }
-            memcpy(&p_encoded_data[*p_len], p_service_data->data.p_data, p_service_data->data.size);
-            (*p_len) += p_service_data->data.size;
-        }
-    }
-
-    return NRF_SUCCESS;
-}
-
-
-static uint32_t adv_data_encode(const ble_advdata_t * p_advdata,
-                                uint8_t             * p_encoded_data,
-                                uint8_t             * p_len)
-{
-    uint32_t err_code = NRF_SUCCESS;
-
-    *p_len = 0;
-
-    // Encode name.
-    if (p_advdata->name_type != BLE_ADVDATA_NO_NAME)
-    {
-        err_code = name_encode(p_advdata, p_encoded_data, p_len);
-        if (err_code != NRF_SUCCESS)
-        {
-            return err_code;
-        }
-    }
-
-    // Encode appearance.
-    if (p_advdata->include_appearance)
-    {
-        err_code = appearance_encode(p_encoded_data, p_len);
-        if (err_code != NRF_SUCCESS)
-        {
-            return err_code;
-        }
-    }
-
-    if(p_advdata->flags != 0 )
-    {
-        // Encode flags.
-        p_encoded_data[(*p_len)++] = 1 + sizeof(uint8_t);
-        p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_FLAGS;
-        p_encoded_data[(*p_len)++] = p_advdata->flags;
-    } 
-
-    // Encode TX power level.
-    if (p_advdata->p_tx_power_level != NULL)
-    {
-        err_code = tx_power_level_encode(*p_advdata->p_tx_power_level, p_encoded_data, p_len);
-        if (err_code != NRF_SUCCESS)
-        {
-            return err_code;
-        }
-    }
-    
-    // Encode 'more available' uuid list.
-    if (p_advdata->uuids_more_available.uuid_cnt > 0)
-    {
-        err_code = uuid_list_encode(&p_advdata->uuids_more_available,
-                                    BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE,
-                                    BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_MORE_AVAILABLE,
-                                    p_encoded_data,
-                                    p_len);
-        if (err_code != NRF_SUCCESS)
-        {
-            return err_code;
-        }
-    }
-
-    // Encode 'complete' uuid list.
-    if (p_advdata->uuids_complete.uuid_cnt > 0)
-    {
-        err_code = uuid_list_encode(&p_advdata->uuids_complete,
-                                    BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE,
-                                    BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE,
-                                    p_encoded_data,
-                                    p_len);
-        if (err_code != NRF_SUCCESS)
-        {
-            return err_code;
-        }
-    }
-
-    // Encode 'solicited service' uuid list.
-    if (p_advdata->uuids_solicited.uuid_cnt > 0)
-    {
-        err_code = uuid_list_encode(&p_advdata->uuids_solicited,
-                                    BLE_GAP_AD_TYPE_SOLICITED_SERVICE_UUIDS_16BIT,
-                                    BLE_GAP_AD_TYPE_SOLICITED_SERVICE_UUIDS_128BIT,
-                                    p_encoded_data,
-                                    p_len);
-        if (err_code != NRF_SUCCESS)
-        {
-            return err_code;
-        }
-    }
-
-    // Encode Slave Connection Interval Range.
-    if (p_advdata->p_slave_conn_int != NULL)
-    {
-        err_code = conn_int_encode(p_advdata->p_slave_conn_int, p_encoded_data, p_len);
-        if (err_code != NRF_SUCCESS)
-        {
-            return err_code;
-        }
-    }
-
-    // Encode Manufacturer Specific Data.
-    if (p_advdata->p_manuf_specific_data != NULL)
-    {
-        err_code = manuf_specific_data_encode(p_advdata->p_manuf_specific_data,
-                                              p_encoded_data,
-                                              p_len);
-        if (err_code != NRF_SUCCESS)
-        {
-            return err_code;
-        }
-    }
-
-    // Encode Service Data.
-    if (p_advdata->service_data_count > 0)
-    {
-        err_code = service_data_encode(p_advdata, p_encoded_data, p_len);
-        if (err_code != NRF_SUCCESS)
-        {
-            return err_code;
-        }
-    }
-
-    return err_code;
-}
-
-
-static uint32_t advdata_check(const ble_advdata_t * p_advdata)
-{
-    // Flags must be included in advertising data, and the BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED flag must be set.
-    if (
-        ((p_advdata->flags & BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED) == 0)
-       )
-    {
-        return NRF_ERROR_INVALID_PARAM;
-    }
-
-    return NRF_SUCCESS;
-}
-
-
-static uint32_t srdata_check(const ble_advdata_t * p_srdata)
-{
-    // Flags shall not be included in the scan response data.
-    if (p_srdata->flags)
-    {
-        return NRF_ERROR_INVALID_PARAM;
-    }
-
-    return NRF_SUCCESS;
-}
-
-
-uint32_t ble_advdata_set(const ble_advdata_t * p_advdata, const ble_advdata_t * p_srdata)
-{
-    uint32_t  err_code;
-    uint8_t   len_advdata = 0;
-    uint8_t   len_srdata  = 0;
-    uint8_t   encoded_advdata[BLE_GAP_ADV_MAX_SIZE];
-    uint8_t   encoded_srdata[BLE_GAP_ADV_MAX_SIZE];
-    uint8_t * p_encoded_advdata;
-    uint8_t * p_encoded_srdata;
-
-    // Encode advertising data (if supplied).
-    if (p_advdata != NULL)
-    {
-        err_code = advdata_check(p_advdata);
-        if (err_code != NRF_SUCCESS)
-        {
-            return err_code;
-        }
-
-        err_code = adv_data_encode(p_advdata, encoded_advdata, &len_advdata);
-        if (err_code != NRF_SUCCESS)
-        {
-            return err_code;
-        }
-        p_encoded_advdata = encoded_advdata;
-    }
-    else
-    {
-        p_encoded_advdata = NULL;
-    }
-
-    // Encode scan response data (if supplied).
-    if (p_srdata != NULL)
-    {
-        err_code = srdata_check(p_srdata);
-        if (err_code != NRF_SUCCESS)
-        {
-            return err_code;
-        }
-
-        err_code = adv_data_encode(p_srdata, encoded_srdata, &len_srdata);
-        if (err_code != NRF_SUCCESS)
-        {
-            return err_code;
-        }
-        p_encoded_srdata = encoded_srdata;
-    }
-    else
-    {
-        p_encoded_srdata = NULL;
-    }
-
-    // Pass encoded advertising data and/or scan response data to the stack.
-    return sd_ble_gap_adv_data_set(p_encoded_advdata, len_advdata, p_encoded_srdata, len_srdata);
-}
\ No newline at end of file
--- a/source/nordic-sdk/components/ble/common/ble_advdata.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,133 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/** @file
- *
- * @defgroup ble_sdk_lib_advdata Advertising Data Encoder
- * @{
- * @ingroup ble_sdk_lib
- * @brief Function for encoding the advertising data and/or scan response data, and passing them to
- *        the stack.
- */
-
-#ifndef BLE_ADVDATA_H__
-#define BLE_ADVDATA_H__
-
-#include <stdint.h>
-#include <stdbool.h>
-#include <string.h>
-#include "ble.h"
-#include "app_util.h"
-
-/**@brief Advertising data name type. This contains the options available for the device name inside
- *        the advertising data. */
-typedef enum
-{
-    BLE_ADVDATA_NO_NAME,                                              /**< Include no device name in advertising data. */
-    BLE_ADVDATA_SHORT_NAME,                                           /**< Include short device name in advertising data. */
-    BLE_ADVDATA_FULL_NAME                                             /**< Include full device name in advertising data. */
-} ble_advdata_name_type_t;
-
-/**@brief UUID list type. */
-typedef struct
-{
-    uint16_t                     uuid_cnt;                            /**< Number of UUID entries. */
-    ble_uuid_t *                 p_uuids;                             /**< Pointer to UUID array entries. */
-} ble_advdata_uuid_list_t;
-
-/**@brief Connection interval range structure. */
-typedef struct
-{
-    uint16_t                     min_conn_interval;                   /**< Minimum Connection Interval, in units of 1.25ms, range 6 to 3200 (i.e. 7.5ms to 4s). */
-    uint16_t                     max_conn_interval;                   /**< Maximum Connection Interval, in units of 1.25ms, range 6 to 3200 (i.e. 7.5ms to 4s). Value of 0xFFFF indicates no specific maximum. */
-} ble_advdata_conn_int_t;
-
-/**@brief Manufacturer specific data structure. */
-typedef struct
-{
-    uint16_t                     company_identifier;                  /**< Company Identifier Code. */
-    uint8_array_t                data;                                /**< Additional manufacturer specific data. */
-} ble_advdata_manuf_data_t;
-
-/**@brief Service data structure. */
-typedef struct
-{
-    uint16_t                     service_uuid;                        /**< Service UUID. */
-    uint8_array_t                data;                                /**< Additional service data. */
-} ble_advdata_service_data_t;
-
-/**@brief Advertising data structure. This contains all options and data needed for encoding and
- *        setting the advertising data. */
-typedef struct
-{
-    ble_advdata_name_type_t      name_type;                           /**< Type of device name. */
-    uint8_t                      short_name_len;                      /**< Length of short device name (if short type is specified). */
-    bool                         include_appearance;                  /**< Determines if Appearance shall be included. */
-    uint8_t                      flags;                               /**< Advertising data Flags field. */
-    int8_t *                     p_tx_power_level;                    /**< TX Power Level field. */
-    ble_advdata_uuid_list_t      uuids_more_available;                /**< List of UUIDs in the 'More Available' list. */
-    ble_advdata_uuid_list_t      uuids_complete;                      /**< List of UUIDs in the 'Complete' list. */
-    ble_advdata_uuid_list_t      uuids_solicited;                     /**< List of solcited UUIDs. */
-    ble_advdata_conn_int_t *     p_slave_conn_int;                    /**< Slave Connection Interval Range. */
-    ble_advdata_manuf_data_t *   p_manuf_specific_data;               /**< Manufacturer specific data. */
-    ble_advdata_service_data_t * p_service_data_array;                /**< Array of Service data structures. */
-    uint8_t                      service_data_count;                  /**< Number of Service data structures. */
-} ble_advdata_t;
-
-/**@brief Function for encoding and setting the advertising data and/or scan response data.
- *
- * @details This function encodes advertising data and/or scan response data based on the selections
- *          in the supplied structures, and passes the encoded data to the stack.
- *
- * @param[in]   p_advdata   Structure for specifying the content of the advertising data.
- *                          Set to NULL if advertising data is not to be set.
- * @param[in]   p_srdata    Structure for specifying the content of the scan response data.
- *                          Set to NULL if scan response data is not to be set.
- *
- * @return      NRF_SUCCESS on success, NRF_ERROR_DATA_SIZE if not all the requested data could fit
- *              into the advertising packet. The maximum size of the advertisement packet is @ref
- *              BLE_GAP_ADV_MAX_SIZE.
- *
- * @warning This API may override application's request to use the long name and use a short name
- * instead. This truncation will occur in case the long name does not fit advertisement data size.
- * Application is permitted to specify a preferred short name length in case truncation is required.
- * For example, if the complete device name is ABCD_HRMonitor, application can specify short name 
- * length to 8 such that short device name appears as ABCD_HRM instead of ABCD_HRMo or ABCD_HRMoni
- * etc if available size for short name is 9 or 12 respectively to have more apporpriate short name.
- * However, it should be noted that this is just a preference that application can specify and
- * if the preference too large to fit in Advertisement Data, this can be further truncated. 
- */
-uint32_t ble_advdata_set(const ble_advdata_t * p_advdata, const ble_advdata_t * p_srdata);
-
-#endif // BLE_ADVDATA_H__
-
-/** @} */
\ No newline at end of file
--- a/source/nordic-sdk/components/ble/common/ble_advdata_parser.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "ble_advdata_parser.h"
-
-uint32_t ble_advdata_parser_field_find(uint8_t    type,
-                                       uint8_t  * p_advdata,
-                                       uint8_t  * len,
-                                       uint8_t ** pp_field_data)
-{
-    uint32_t index = 0;
-
-    while (index < *len)
-    {
-        uint8_t field_length = p_advdata[index];
-        uint8_t field_type   = p_advdata[index + 1];
-
-        if (field_type == type)
-        {
-            *pp_field_data = &p_advdata[index + 2];
-            *len           = field_length - 1;
-            return NRF_SUCCESS;
-        }
-        index += field_length + 1;
-    }
-    return NRF_ERROR_NOT_FOUND;
-}
\ No newline at end of file
--- a/source/nordic-sdk/components/ble/common/ble_advdata_parser.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#ifndef BLE_ADVDATA_PARSER_H_
-#define BLE_ADVDATA_PARSER_H_
-
-#include "ble_advdata.h"
-
-uint32_t ble_advdata_parse(uint8_t * p_data, uint8_t len, ble_advdata_t * advdata);
-uint32_t ble_advdata_parser_field_find(uint8_t type, uint8_t * p_advdata, uint8_t * len, uint8_t ** pp_field_data);
-
-#endif
\ No newline at end of file
--- a/source/nordic-sdk/components/ble/common/ble_conn_params.cpp	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,381 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "ble_conn_params.h"
-#include <stdlib.h>
-#include "nordic_common.h"
-#include "ble_hci.h"
-#include "ble_srv_common.h"
-#include "app_util.h"
-
-#ifdef USE_APP_TIMER
-#include "app_timer.h"
-#else
-#include "mbed.h"
-#endif
-
-static ble_conn_params_init_t m_conn_params_config;     /**< Configuration as specified by the application. */
-static ble_gap_conn_params_t  m_preferred_conn_params;  /**< Connection parameters preferred by the application. */
-static uint8_t                m_update_count;           /**< Number of Connection Parameter Update messages that has currently been sent. */
-static uint16_t               m_conn_handle;            /**< Current connection handle. */
-static ble_gap_conn_params_t  m_current_conn_params;    /**< Connection parameters received in the most recent Connect event. */
-#ifdef USE_APP_TIMER
-static app_timer_id_t         m_conn_params_timer_id;   /**< Connection parameters timer. */
-#else
-static Ticker                 m_conn_params_timer;
-#endif
-
-static bool m_change_param = false;
-
-static bool is_conn_params_ok(ble_gap_conn_params_t * p_conn_params)
-{
-    // Check if interval is within the acceptable range.
-    // NOTE: Using max_conn_interval in the received event data because this contains
-    //       the client's connection interval.
-    if (
-        (p_conn_params->max_conn_interval >= m_preferred_conn_params.min_conn_interval)
-        && 
-        (p_conn_params->max_conn_interval <= m_preferred_conn_params.max_conn_interval)
-       )
-    {
-        return true;
-    }
-    else
-    {
-        return false;
-    }
-}
-
-
-#ifdef USE_APP_TIMER
-static void update_timeout_handler(void * p_context)
-{
-    UNUSED_PARAMETER(p_context);
-
-#else /* #if !USE_APP_TIMER */
-static void update_timeout_handler(void)
-{
-    m_conn_params_timer.detach(); /* this is supposed to be a single-shot timer callback */
-#endif /* #if !USE_APP_TIMER */
-    if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
-    {
-        // Check if we have reached the maximum number of attempts
-        m_update_count++;
-        if (m_update_count <= m_conn_params_config.max_conn_params_update_count)
-        {
-            uint32_t err_code;
-
-            // Parameters are not ok, send connection parameters update request.
-            err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_preferred_conn_params);
-            if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
-            {
-                m_conn_params_config.error_handler(err_code);
-            }
-        }
-        else
-        {
-            m_update_count = 0;
-
-            // Negotiation failed, disconnect automatically if this has been configured
-            if (m_conn_params_config.disconnect_on_fail)
-            {
-                uint32_t err_code;
-
-                err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE);
-                if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
-                {
-                    m_conn_params_config.error_handler(err_code);
-                }
-            }
-
-            // Notify the application that the procedure has failed
-            if (m_conn_params_config.evt_handler != NULL)
-            {
-                ble_conn_params_evt_t evt;
-
-                evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED;
-                m_conn_params_config.evt_handler(&evt);
-            }
-        }
-    }
-}
-
-
-uint32_t ble_conn_params_init(const ble_conn_params_init_t * p_init)
-{
-    uint32_t err_code;
-
-    m_conn_params_config = *p_init;
-    m_change_param = false;
-    if (p_init->p_conn_params != NULL)
-    {
-        m_preferred_conn_params = *p_init->p_conn_params;
-
-        // Set the connection params in stack
-        err_code = sd_ble_gap_ppcp_set(&m_preferred_conn_params);
-        if (err_code != NRF_SUCCESS)
-        {
-            return err_code;
-        }
-    }
-    else
-    {
-        // Fetch the connection params from stack
-        err_code = sd_ble_gap_ppcp_get(&m_preferred_conn_params);
-        if (err_code != NRF_SUCCESS)
-        {
-            return err_code;
-        }
-    }
-
-    m_conn_handle  = BLE_CONN_HANDLE_INVALID;
-    m_update_count = 0;
-
-#ifdef USE_APP_TIMER
-    return app_timer_create(&m_conn_params_timer_id,
-                            APP_TIMER_MODE_SINGLE_SHOT,
-                            update_timeout_handler);
-#else
-    return NRF_SUCCESS;
-#endif
-}
-
-
-uint32_t ble_conn_params_stop(void)
-{
-#ifdef USE_APP_TIMER
-    return app_timer_stop(m_conn_params_timer_id);
-#else /* #if !USE_APP_TIMER */
-    m_conn_params_timer.detach();
-    return NRF_SUCCESS;
-#endif /* #if !USE_APP_TIMER */
-}
-
-
-static void conn_params_negotiation(void)
-{
-    // Start negotiation if the received connection parameters are not acceptable
-    if (!is_conn_params_ok(&m_current_conn_params))
-    {
-#ifdef USE_APP_TIMER
-        uint32_t err_code;
-#endif
-        uint32_t timeout_ticks;
-
-        if (m_change_param)
-        {
-            // Notify the application that the procedure has failed
-            if (m_conn_params_config.evt_handler != NULL)
-            {
-                ble_conn_params_evt_t evt;
-
-                evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED;
-                m_conn_params_config.evt_handler(&evt);
-            }
-        }
-        else
-        {
-            if (m_update_count == 0)
-            {
-                // First connection parameter update
-                timeout_ticks = m_conn_params_config.first_conn_params_update_delay;
-            }
-            else
-            {
-                timeout_ticks = m_conn_params_config.next_conn_params_update_delay;
-            }
-
-#ifdef USE_APP_TIMER
-            err_code = app_timer_start(m_conn_params_timer_id, timeout_ticks, NULL);
-            if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
-            {
-                m_conn_params_config.error_handler(err_code);
-            }
-#else
-            m_conn_params_timer.attach(update_timeout_handler, timeout_ticks / 32768);
-#endif
-        }
-    }
-    else
-    {
-        // Notify the application that the procedure has succeded
-        if (m_conn_params_config.evt_handler != NULL)
-        {
-            ble_conn_params_evt_t evt;
-
-            evt.evt_type = BLE_CONN_PARAMS_EVT_SUCCEEDED;
-            m_conn_params_config.evt_handler(&evt);
-        }
-    }
-    m_change_param = false;
-}
-
-
-static void on_connect(ble_evt_t * p_ble_evt)
-{
-    // Save connection parameters
-    m_conn_handle         = p_ble_evt->evt.gap_evt.conn_handle;
-    m_current_conn_params = p_ble_evt->evt.gap_evt.params.connected.conn_params;
-    m_update_count        = 0;  // Connection parameter negotiation should re-start every connection
-
-    // Check if we shall handle negotiation on connect
-    if (m_conn_params_config.start_on_notify_cccd_handle == BLE_GATT_HANDLE_INVALID)
-    {
-        conn_params_negotiation();
-    }
-}
-
-
-static void on_disconnect(ble_evt_t * p_ble_evt)
-{
-#ifdef USE_APP_TIMER
-    uint32_t err_code;
-#endif
-
-    m_conn_handle = BLE_CONN_HANDLE_INVALID;
-
-    // Stop timer if running
-    m_update_count = 0; // Connection parameters updates should happen during every connection
-
-#ifdef USE_APP_TIMER
-    err_code = app_timer_stop(m_conn_params_timer_id);
-    if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
-    {
-        m_conn_params_config.error_handler(err_code);
-    }
-#else
-    m_conn_params_timer.detach();
-#endif
-}
-
-
-static void on_write(ble_evt_t * p_ble_evt)
-{
-    ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
-
-    // Check if this the correct CCCD
-    if (
-        (p_evt_write->handle == m_conn_params_config.start_on_notify_cccd_handle)
-        &&
-        (p_evt_write->len == 2)
-       )
-    {
-        // Check if this is a 'start notification'
-        if (ble_srv_is_notification_enabled(p_evt_write->data))
-        {
-            // Do connection parameter negotiation if necessary
-            conn_params_negotiation();
-        }
-        else
-        {
-#ifdef USE_APP_TIMER
-            uint32_t err_code;
-
-            // Stop timer if running
-            err_code = app_timer_stop(m_conn_params_timer_id);
-            if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
-            {
-                m_conn_params_config.error_handler(err_code);
-            }
-#else /* #if !USE_APP_TIMER */
-            m_conn_params_timer.detach();
-#endif /* #if !USE_APP_TIMER */
-        }
-    }
-}
-
-
-static void on_conn_params_update(ble_evt_t * p_ble_evt)
-{
-    // Copy the parameters
-    m_current_conn_params = p_ble_evt->evt.gap_evt.params.conn_param_update.conn_params;
-
-    conn_params_negotiation();
-}
-
-
-void ble_conn_params_on_ble_evt(ble_evt_t * p_ble_evt)
-{
-    switch (p_ble_evt->header.evt_id)
-    {
-        case BLE_GAP_EVT_CONNECTED:
-            on_connect(p_ble_evt);
-            break;
-
-        case BLE_GAP_EVT_DISCONNECTED:
-            on_disconnect(p_ble_evt);
-            break;
-
-        case BLE_GATTS_EVT_WRITE:
-            on_write(p_ble_evt);
-            break;
-
-        case BLE_GAP_EVT_CONN_PARAM_UPDATE:
-            on_conn_params_update(p_ble_evt);
-            break;
-
-        default:
-            // No implementation needed.
-            break;
-    }
-}
-
-uint32_t ble_conn_params_change_conn_params(ble_gap_conn_params_t *new_params)
-{
-    uint32_t err_code;
-
-    m_preferred_conn_params = *new_params;
-    // Set the connection params in stack
-    err_code = sd_ble_gap_ppcp_set(&m_preferred_conn_params);
-    if (err_code == NRF_SUCCESS)
-    {
-        if (!is_conn_params_ok(&m_current_conn_params))
-        {
-            m_change_param = true;
-            err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_preferred_conn_params);
-            m_update_count = 1;
-        }
-        else
-        {
-            // Notify the application that the procedure has succeded
-            if (m_conn_params_config.evt_handler != NULL)
-            {
-                ble_conn_params_evt_t evt;
-
-                evt.evt_type = BLE_CONN_PARAMS_EVT_SUCCEEDED;
-                m_conn_params_config.evt_handler(&evt);
-            }
-            err_code = NRF_SUCCESS;
-        }
-    }
-    return err_code;
-}
\ No newline at end of file
--- a/source/nordic-sdk/components/ble/common/ble_conn_params.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,139 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/** @file
- *
- * @defgroup ble_sdk_lib_conn_params Connection Parameters Negotiation
- * @{
- * @ingroup ble_sdk_lib
- * @brief Module for initiating and executing a connection parameters negotiation procedure.
- */
-
-#ifndef BLE_CONN_PARAMS_H__
-#define BLE_CONN_PARAMS_H__
-
-#include <stdint.h>
-#include "ble.h"
-#include "ble_srv_common.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**@brief Connection Parameters Module event type. */
-typedef enum
-{
-    BLE_CONN_PARAMS_EVT_FAILED   ,                                  /**< Negotiation procedure failed. */
-    BLE_CONN_PARAMS_EVT_SUCCEEDED                                   /**< Negotiation procedure succeeded. */
-} ble_conn_params_evt_type_t;
-
-/**@brief Connection Parameters Module event. */
-typedef struct
-{
-    ble_conn_params_evt_type_t evt_type;                            /**< Type of event. */
-} ble_conn_params_evt_t;
-
-/**@brief Connection Parameters Module event handler type. */
-typedef void (*ble_conn_params_evt_handler_t) (ble_conn_params_evt_t * p_evt);
-
-/**@brief Connection Parameters Module init structure. This contains all options and data needed for
- *        initialization of the connection parameters negotiation module. */
-typedef struct
-{
-    ble_gap_conn_params_t *       p_conn_params;                    /**< Pointer to the connection parameters desired by the application. When calling ble_conn_params_init, if this parameter is set to NULL, the connection parameters will be fetched from host. */
-    uint32_t                      first_conn_params_update_delay;   /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (in number of timer ticks). */
-    uint32_t                      next_conn_params_update_delay;    /**< Time between each call to sd_ble_gap_conn_param_update after the first (in number of timer ticks). Recommended value 30 seconds as per BLUETOOTH SPECIFICATION Version 4.0. */
-    uint8_t                       max_conn_params_update_count;     /**< Number of attempts before giving up the negotiation. */
-    uint16_t                      start_on_notify_cccd_handle;      /**< If procedure is to be started when notification is started, set this to the handle of the corresponding CCCD. Set to BLE_GATT_HANDLE_INVALID if procedure is to be started on connect event. */
-    bool                          disconnect_on_fail;               /**< Set to TRUE if a failed connection parameters update shall cause an automatic disconnection, set to FALSE otherwise. */
-    ble_conn_params_evt_handler_t evt_handler;                      /**< Event handler to be called for handling events in the Connection Parameters. */
-    ble_srv_error_handler_t       error_handler;                    /**< Function to be called in case of an error. */
-} ble_conn_params_init_t;
-
-
-/**@brief Function for initializing the Connection Parameters module.
- *
- * @note If the negotiation procedure should be triggered when notification/indication of
- *       any characteristic is enabled by the peer, then this function must be called after
- *       having initialized the services.
- *
- * @param[in]   p_init  This contains information needed to initialize this module.
- *
- * @return      NRF_SUCCESS on successful initialization, otherwise an error code.
- */
-uint32_t ble_conn_params_init(const ble_conn_params_init_t * p_init);
-
-/**@brief Function for stopping the Connection Parameters module.
- *
- * @details This function is intended to be used by the application to clean up the connection
- *          parameters update module. This will stop the connection parameters update timer if
- *          running, thereby preventing any impending connection parameters update procedure. This
- *          function must be called by the application when it needs to clean itself up (for
- *          example, before disabling the bluetooth SoftDevice) so that an unwanted timer expiry
- *          event can be avoided.
- *
- * @return      NRF_SUCCESS on successful initialization, otherwise an error code.
- */
-uint32_t ble_conn_params_stop(void);
-
-/**@brief Function for changing the current connection parameters to a new set.
- *
- *  @details Use this function to change the connection parameters to a new set of parameter
- *       (ie different from the ones given at init of the module).
- *       This function is usefull for scenario where most of the time the application
- *       needs a relatively big connection interval, and just sometimes, for a temporary
- *       period requires shorter connection interval, for example to transfer a higher
- *       amount of data.
- *       If the given parameters does not match the current connection's parameters
- *       this function initiates a new negotiation.
- *
- * @param[in]   new_params  This contains the new connections parameters to setup.
- *
- * @return      NRF_SUCCESS on successful initialization, otherwise an error code.
- */
-uint32_t ble_conn_params_change_conn_params(ble_gap_conn_params_t *new_params);
-
-/**@brief Function for handling the Application's BLE Stack events.
- *
- * @details Handles all events from the BLE stack that are of interest to this module.
- *
- * @param[in]   p_ble_evt  The event received from the BLE stack.
- */
-void ble_conn_params_on_ble_evt(ble_evt_t * p_ble_evt);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // BLE_CONN_PARAMS_H__
-
-/** @} */
\ No newline at end of file
--- a/source/nordic-sdk/components/ble/common/ble_date_time.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,97 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/* Attention!
-*  To maintain compliance with Nordic Semiconductor ASA’s Bluetooth profile
-*  qualification listings, this section of source code must not be modified.
-*/
-
-/** @file
- * @brief Contains definition of ble_date_time structure.
- */
-
-/** @file
- *
- * @defgroup ble_sdk_srv_date_time BLE Date Time characteristic type
- * @{
- * @ingroup ble_sdk_lib
- * @brief Definition of ble_date_time_t type.
- */
-
-#ifndef BLE_DATE_TIME_H__
-#define BLE_DATE_TIME_H__
-
-#include <stdint.h>
-
-/**@brief Date and Time structure. */
-typedef struct
-{
-    uint16_t year;
-    uint8_t  month;
-    uint8_t  day;
-    uint8_t  hours;
-    uint8_t  minutes;
-    uint8_t  seconds;
-} ble_date_time_t;
-
-static __INLINE uint8_t ble_date_time_encode(const ble_date_time_t * p_date_time,
-                                             uint8_t *               p_encoded_data)
-{
-    uint8_t len = uint16_encode(p_date_time->year, p_encoded_data);
-
-    p_encoded_data[len++] = p_date_time->month;
-    p_encoded_data[len++] = p_date_time->day;
-    p_encoded_data[len++] = p_date_time->hours;
-    p_encoded_data[len++] = p_date_time->minutes;
-    p_encoded_data[len++] = p_date_time->seconds;
-
-    return len;
-}
-
-static __INLINE uint8_t ble_date_time_decode(ble_date_time_t * p_date_time,
-                                             const uint8_t *   p_encoded_data)
-{
-    uint8_t len = sizeof(uint16_t);
-
-    p_date_time->year    = uint16_decode(p_encoded_data);
-    p_date_time->month   = p_encoded_data[len++];
-    p_date_time->day     = p_encoded_data[len++];
-    p_date_time->hours   = p_encoded_data[len++];
-    p_date_time->minutes = p_encoded_data[len++];
-    p_date_time->seconds = p_encoded_data[len++];
-
-    return len;
-}
-
-#endif // BLE_DATE_TIME_H__
-
-/** @} */
\ No newline at end of file
--- a/source/nordic-sdk/components/ble/common/ble_sensor_location.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-
- /* Attention!
-*  To maintain compliance with Nordic Semiconductor ASA’s Bluetooth profile
-*  qualification listings, this section of source code must not be modified.
-*/
-
-#ifndef BLE_SENSOR_LOCATION_H__
-#define BLE_SENSOR_LOCATION_H__
-
-typedef enum {
-    BLE_SENSOR_LOCATION_OTHER        = 0 ,  /**<-- Other        */
-    BLE_SENSOR_LOCATION_TOP_OF_SHOE  = 1 ,  /**<-- Top of shoe  */
-    BLE_SENSOR_LOCATION_IN_SHOE      = 2 ,  /**<-- In shoe      */
-    BLE_SENSOR_LOCATION_HIP          = 3 ,  /**<-- Hip          */
-    BLE_SENSOR_LOCATION_FRONT_WHEEL  = 4 ,  /**<-- Front Wheel  */
-    BLE_SENSOR_LOCATION_LEFT_CRANK   = 5 ,  /**<-- Left Crank   */
-    BLE_SENSOR_LOCATION_RIGHT_CRANK  = 6 ,  /**<-- Right Crank  */
-    BLE_SENSOR_LOCATION_LEFT_PEDAL   = 7 ,  /**<-- Left Pedal   */
-    BLE_SENSOR_LOCATION_RIGHT_PEDAL  = 8 ,  /**<-- Right Pedal  */
-    BLE_SENSOR_LOCATION_FRONT_HUB    = 9 ,  /**<-- Front Hub    */
-    BLE_SENSOR_LOCATION_REAR_DROPOUT = 10,  /**<-- Rear Dropout */
-    BLE_SENSOR_LOCATION_CHAINSTAY    = 11,  /**<-- Chainstay    */
-    BLE_SENSOR_LOCATION_REAR_WHEEL   = 12,  /**<-- Rear Wheel   */
-    BLE_SENSOR_LOCATION_REAR_HUB     = 13,  /**<-- Rear Hub     */
-}ble_sensor_location_t;
-
-#define BLE_NB_MAX_SENSOR_LOCATIONS 14
-
-#endif // BLE_SENSOR_LOCATION_H__
\ No newline at end of file
--- a/source/nordic-sdk/components/ble/common/ble_srv_common.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/* Attention!
-*  To maintain compliance with Nordic Semiconductor ASA’s Bluetooth profile
-*  qualification listings, this section of source code must not be modified.
-*/
-
-#include "ble_srv_common.h"
-#include <string.h>
-#include "nordic_common.h"
-#include "app_error.h"
-
-
-uint8_t ble_srv_report_ref_encode(uint8_t                    * p_encoded_buffer,
-                                  const ble_srv_report_ref_t * p_report_ref)
-{
-    uint8_t len = 0;
-
-    p_encoded_buffer[len++] = p_report_ref->report_id;
-    p_encoded_buffer[len++] = p_report_ref->report_type;
-
-    APP_ERROR_CHECK_BOOL(len == BLE_SRV_ENCODED_REPORT_REF_LEN);
-    return len;
-}
-
-
-void ble_srv_ascii_to_utf8(ble_srv_utf8_str_t * p_utf8, char * p_ascii)
-{
-    p_utf8->length = (uint16_t)strlen(p_ascii);
-    p_utf8->p_str  = (uint8_t *)p_ascii;
-}
\ No newline at end of file
--- a/source/nordic-sdk/components/ble/common/ble_srv_common.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,250 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/** @file
- *
- * @defgroup ble_sdk_srv_common Common service definitions
- * @{
- * @ingroup ble_sdk_srv
- * @brief Constants, type definitions and functions that are common to all services.
- */
-
-#ifndef BLE_SRV_COMMON_H__
-#define BLE_SRV_COMMON_H__
-
-#include <stdint.h>
-#include <stdbool.h>
-#include "ble_types.h"
-#include "app_util.h"
-#include "ble_gap.h"
-#include "ble_gatt.h"
-
-/** @defgroup UUID_SERVICES Service UUID definitions
- * @{ */
-#define BLE_UUID_ALERT_NOTIFICATION_SERVICE                      0x1811     /**< Alert Notification service UUID. */
-#define BLE_UUID_BATTERY_SERVICE                                 0x180F     /**< Battery service UUID. */
-#define BLE_UUID_BLOOD_PRESSURE_SERVICE                          0x1810     /**< Blood Pressure service UUID. */
-#define BLE_UUID_CURRENT_TIME_SERVICE                            0x1805     /**< Current Time service UUID. */
-#define BLE_UUID_CYCLING_SPEED_AND_CADENCE                       0x1816     /**< Cycling Speed and Cadence service UUID. */
-#define BLE_UUID_DEVICE_INFORMATION_SERVICE                      0x180A     /**< Device Information service UUID. */
-#define BLE_UUID_GLUCOSE_SERVICE                                 0x1808     /**< Glucose service UUID. */
-#define BLE_UUID_HEALTH_THERMOMETER_SERVICE                      0x1809     /**< Health Thermometer service UUID. */
-#define BLE_UUID_HEART_RATE_SERVICE                              0x180D     /**< Heart Rate service UUID. */
-#define BLE_UUID_HUMAN_INTERFACE_DEVICE_SERVICE                  0x1812     /**< Human Interface Device service UUID. */
-#define BLE_UUID_IMMEDIATE_ALERT_SERVICE                         0x1802     /**< Immediate Alert service UUID. */
-#define BLE_UUID_LINK_LOSS_SERVICE                               0x1803     /**< Link Loss service UUID. */
-#define BLE_UUID_NEXT_DST_CHANGE_SERVICE                         0x1807     /**< Next Dst Change service UUID. */
-#define BLE_UUID_PHONE_ALERT_STATUS_SERVICE                      0x180E     /**< Phone Alert Status service UUID. */
-#define BLE_UUID_REFERENCE_TIME_UPDATE_SERVICE                   0x1806     /**< Reference Time Update service UUID. */
-#define BLE_UUID_RUNNING_SPEED_AND_CADENCE                       0x1814     /**< Running Speed and Cadence service UUID. */
-#define BLE_UUID_SCAN_PARAMETERS_SERVICE                         0x1813     /**< Scan Parameters service UUID. */
-#define BLE_UUID_TX_POWER_SERVICE                                0x1804     /**< TX Power service UUID. */
-/** @} */
-
-/** @defgroup UUID_CHARACTERISTICS Characteristic UUID definitions
- * @{ */
-#define BLE_UUID_BATTERY_LEVEL_STATE_CHAR                        0x2A1B     /**< Battery Level State characteristic UUID. */
-#define BLE_UUID_BATTERY_POWER_STATE_CHAR                        0x2A1A     /**< Battery Power State characteristic UUID. */
-#define BLE_UUID_REMOVABLE_CHAR                                  0x2A3A     /**< Removable characteristic UUID. */
-#define BLE_UUID_SERVICE_REQUIRED_CHAR                           0x2A3B     /**< Service Required characteristic UUID. */
-#define BLE_UUID_ALERT_CATEGORY_ID_CHAR                          0x2A43     /**< Alert Category Id characteristic UUID. */
-#define BLE_UUID_ALERT_CATEGORY_ID_BIT_MASK_CHAR                 0x2A42     /**< Alert Category Id Bit Mask characteristic UUID. */
-#define BLE_UUID_ALERT_LEVEL_CHAR                                0x2A06     /**< Alert Level characteristic UUID. */
-#define BLE_UUID_ALERT_NOTIFICATION_CONTROL_POINT_CHAR           0x2A44     /**< Alert Notification Control Point characteristic UUID. */
-#define BLE_UUID_ALERT_STATUS_CHAR                               0x2A3F     /**< Alert Status characteristic UUID. */
-#define BLE_UUID_BATTERY_LEVEL_CHAR                              0x2A19     /**< Battery Level characteristic UUID. */
-#define BLE_UUID_BLOOD_PRESSURE_FEATURE_CHAR                     0x2A49     /**< Blood Pressure Feature characteristic UUID. */
-#define BLE_UUID_BLOOD_PRESSURE_MEASUREMENT_CHAR                 0x2A35     /**< Blood Pressure Measurement characteristic UUID. */
-#define BLE_UUID_BODY_SENSOR_LOCATION_CHAR                       0x2A38     /**< Body Sensor Location characteristic UUID. */
-#define BLE_UUID_BOOT_KEYBOARD_INPUT_REPORT_CHAR                 0x2A22     /**< Boot Keyboard Input Report characteristic UUID. */
-#define BLE_UUID_BOOT_KEYBOARD_OUTPUT_REPORT_CHAR                0x2A32     /**< Boot Keyboard Output Report characteristic UUID. */
-#define BLE_UUID_BOOT_MOUSE_INPUT_REPORT_CHAR                    0x2A33     /**< Boot Mouse Input Report characteristic UUID. */
-#define BLE_UUID_CURRENT_TIME_CHAR                               0x2A2B     /**< Current Time characteristic UUID. */
-#define BLE_UUID_DATE_TIME_CHAR                                  0x2A08     /**< Date Time characteristic UUID. */
-#define BLE_UUID_DAY_DATE_TIME_CHAR                              0x2A0A     /**< Day Date Time characteristic UUID. */
-#define BLE_UUID_DAY_OF_WEEK_CHAR                                0x2A09     /**< Day Of Week characteristic UUID. */
-#define BLE_UUID_DST_OFFSET_CHAR                                 0x2A0D     /**< Dst Offset characteristic UUID. */
-#define BLE_UUID_EXACT_TIME_256_CHAR                             0x2A0C     /**< Exact Time 256 characteristic UUID. */
-#define BLE_UUID_FIRMWARE_REVISION_STRING_CHAR                   0x2A26     /**< Firmware Revision String characteristic UUID. */
-#define BLE_UUID_GLUCOSE_FEATURE_CHAR                            0x2A51     /**< Glucose Feature characteristic UUID. */
-#define BLE_UUID_GLUCOSE_MEASUREMENT_CHAR                        0x2A18     /**< Glucose Measurement characteristic UUID. */
-#define BLE_UUID_GLUCOSE_MEASUREMENT_CONTEXT_CHAR                0x2A34     /**< Glucose Measurement Context characteristic UUID. */
-#define BLE_UUID_HARDWARE_REVISION_STRING_CHAR                   0x2A27     /**< Hardware Revision String characteristic UUID. */
-#define BLE_UUID_HEART_RATE_CONTROL_POINT_CHAR                   0x2A39     /**< Heart Rate Control Point characteristic UUID. */
-#define BLE_UUID_HEART_RATE_MEASUREMENT_CHAR                     0x2A37     /**< Heart Rate Measurement characteristic UUID. */
-#define BLE_UUID_HID_CONTROL_POINT_CHAR                          0x2A4C     /**< Hid Control Point characteristic UUID. */
-#define BLE_UUID_HID_INFORMATION_CHAR                            0x2A4A     /**< Hid Information characteristic UUID. */
-#define BLE_UUID_IEEE_REGULATORY_CERTIFICATION_DATA_LIST_CHAR    0x2A2A     /**< IEEE Regulatory Certification Data List characteristic UUID. */
-#define BLE_UUID_INTERMEDIATE_CUFF_PRESSURE_CHAR                 0x2A36     /**< Intermediate Cuff Pressure characteristic UUID. */
-#define BLE_UUID_INTERMEDIATE_TEMPERATURE_CHAR                   0x2A1E     /**< Intermediate Temperature characteristic UUID. */
-#define BLE_UUID_LOCAL_TIME_INFORMATION_CHAR                     0x2A0F     /**< Local Time Information characteristic UUID. */
-#define BLE_UUID_MANUFACTURER_NAME_STRING_CHAR                   0x2A29     /**< Manufacturer Name String characteristic UUID. */
-#define BLE_UUID_MEASUREMENT_INTERVAL_CHAR                       0x2A21     /**< Measurement Interval characteristic UUID. */
-#define BLE_UUID_MODEL_NUMBER_STRING_CHAR                        0x2A24     /**< Model Number String characteristic UUID. */
-#define BLE_UUID_UNREAD_ALERT_CHAR                               0x2A45     /**< Unread Alert characteristic UUID. */
-#define BLE_UUID_NEW_ALERT_CHAR                                  0x2A46     /**< New Alert characteristic UUID. */
-#define BLE_UUID_PNP_ID_CHAR                                     0x2A50     /**< PNP Id characteristic UUID. */
-#define BLE_UUID_PROTOCOL_MODE_CHAR                              0x2A4E     /**< Protocol Mode characteristic UUID. */
-#define BLE_UUID_RECORD_ACCESS_CONTROL_POINT_CHAR                0x2A52     /**< Record Access Control Point characteristic UUID. */
-#define BLE_UUID_REFERENCE_TIME_INFORMATION_CHAR                 0x2A14     /**< Reference Time Information characteristic UUID. */
-#define BLE_UUID_REPORT_CHAR                                     0x2A4D     /**< Report characteristic UUID. */
-#define BLE_UUID_REPORT_MAP_CHAR                                 0x2A4B     /**< Report Map characteristic UUID. */
-#define BLE_UUID_RINGER_CONTROL_POINT_CHAR                       0x2A40     /**< Ringer Control Point characteristic UUID. */
-#define BLE_UUID_RINGER_SETTING_CHAR                             0x2A41     /**< Ringer Setting characteristic UUID. */
-#define BLE_UUID_SCAN_INTERVAL_WINDOW_CHAR                       0x2A4F     /**< Scan Interval Window characteristic UUID. */
-#define BLE_UUID_SCAN_REFRESH_CHAR                               0x2A31     /**< Scan Refresh characteristic UUID. */
-#define BLE_UUID_SERIAL_NUMBER_STRING_CHAR                       0x2A25     /**< Serial Number String characteristic UUID. */
-#define BLE_UUID_SOFTWARE_REVISION_STRING_CHAR                   0x2A28     /**< Software Revision String characteristic UUID. */
-#define BLE_UUID_SUPPORTED_NEW_ALERT_CATEGORY_CHAR               0x2A47     /**< Supported New Alert Category characteristic UUID. */
-#define BLE_UUID_SUPPORTED_UNREAD_ALERT_CATEGORY_CHAR            0x2A48     /**< Supported Unread Alert Category characteristic UUID. */
-#define BLE_UUID_SYSTEM_ID_CHAR                                  0x2A23     /**< System Id characteristic UUID. */
-#define BLE_UUID_TEMPERATURE_MEASUREMENT_CHAR                    0x2A1C     /**< Temperature Measurement characteristic UUID. */
-#define BLE_UUID_TEMPERATURE_TYPE_CHAR                           0x2A1D     /**< Temperature Type characteristic UUID. */
-#define BLE_UUID_TIME_ACCURACY_CHAR                              0x2A12     /**< Time Accuracy characteristic UUID. */
-#define BLE_UUID_TIME_SOURCE_CHAR                                0x2A13     /**< Time Source characteristic UUID. */
-#define BLE_UUID_TIME_UPDATE_CONTROL_POINT_CHAR                  0x2A16     /**< Time Update Control Point characteristic UUID. */
-#define BLE_UUID_TIME_UPDATE_STATE_CHAR                          0x2A17     /**< Time Update State characteristic UUID. */
-#define BLE_UUID_TIME_WITH_DST_CHAR                              0x2A11     /**< Time With Dst characteristic UUID. */
-#define BLE_UUID_TIME_ZONE_CHAR                                  0x2A0E     /**< Time Zone characteristic UUID. */
-#define BLE_UUID_TX_POWER_LEVEL_CHAR                             0x2A07     /**< TX Power Level characteristic UUID. */
-#define BLE_UUID_CSC_FEATURE_CHAR                                0x2A5C     /**< Cycling Speed and Cadence Feature characteristic UUID. */
-#define BLE_UUID_CSC_MEASUREMENT_CHAR                            0x2A5B     /**< Cycling Speed and Cadence Measurement characteristic UUID. */
-#define BLE_UUID_RSC_FEATURE_CHAR                                0x2A54     /**< Running Speed and Cadence Feature characteristic UUID. */
-#define BLE_UUID_SC_CTRLPT_CHAR                                  0x2A55     /**< Speed and Cadence Control Point UUID. */
-#define BLE_UUID_RSC_MEASUREMENT_CHAR                            0x2A53     /**< Running Speed and Cadence Measurement characteristic UUID. */
-#define BLE_UUID_SENSOR_LOCATION_CHAR                            0x2A5D     /**< Sensor Location characteristic UUID. */
-#define BLE_UUID_EXTERNAL_REPORT_REF_DESCR                       0x2907     /**< External Report Reference descriptor UUID. */
-#define BLE_UUID_REPORT_REF_DESCR                                0x2908     /**< Report Reference descriptor UUID. */
-/** @} */
-
-/** @defgroup ALERT_LEVEL_VALUES Definitions for the Alert Level characteristic values
- * @{ */
-#define BLE_CHAR_ALERT_LEVEL_NO_ALERT                            0x00       /**< No Alert. */
-#define BLE_CHAR_ALERT_LEVEL_MILD_ALERT                          0x01       /**< Mild Alert. */
-#define BLE_CHAR_ALERT_LEVEL_HIGH_ALERT                          0x02       /**< High Alert. */
-/** @} */
-
-#define BLE_SRV_ENCODED_REPORT_REF_LEN                           2          /**< The length of an encoded Report Reference Descriptor. */
-#define BLE_CCCD_VALUE_LEN                                       2          /**< The length of a CCCD value. */
-
-/**@brief Type definition for error handler function which will be called in case of an error in
- *        a service or a service library module. */
-typedef void (*ble_srv_error_handler_t) (uint32_t nrf_error);
-
-/**@brief Value of a Report Reference descriptor. 
- *
- * @details This is mapping information which maps the parent characteristic to the Report ID(s) and
- *          Report Type(s) defined within a Report Map characteristic.
- */
-typedef struct
-{
-    uint8_t report_id;                                  /**< Non-zero value if these is more than one instance of the same Report Type */
-    uint8_t report_type;                                /**< Type of Report characteristic @if (SD_S110) (see @ref BLE_HIDS_REPORT_TYPE) @endif */
-} ble_srv_report_ref_t;
-
-/**@brief UTF-8 string data type.
- *
- * @note The type can only hold a pointer to the string data (i.e. not the actual data).
- */
-typedef struct
-{
-    uint16_t  length;                                   /**< String length. */
-    uint8_t * p_str;                                    /**< String data. */
-} ble_srv_utf8_str_t;
-
-/**@brief Security settings structure.
- * @details This structure contains the security options needed during initialization of the
- *          service.
- */
-typedef struct
-{
-    ble_gap_conn_sec_mode_t read_perm;                  /**< Read permissions. */
-    ble_gap_conn_sec_mode_t write_perm;                 /**< Write permissions. */
-} ble_srv_security_mode_t;
-
-/**@brief Security settings structure.
- * @details This structure contains the security options needed during initialization of the
- *          service. It can be used when the charecteristics contains cccd.
- */
-typedef struct
-{
-    ble_gap_conn_sec_mode_t cccd_write_perm;
-    ble_gap_conn_sec_mode_t read_perm;                  /**< Read permissions. */
-    ble_gap_conn_sec_mode_t write_perm;                 /**< Write permissions. */
-} ble_srv_cccd_security_mode_t;
-
-/**@brief Function for decoding a CCCD value, and then testing if notification is
- *        enabled.
- *
- * @param[in]   p_encoded_data   Buffer where the encoded CCCD is stored.
- *
- * @return      TRUE if notification is enabled, FALSE otherwise.
- */
-static __INLINE bool ble_srv_is_notification_enabled(uint8_t * p_encoded_data)
-{
-    uint16_t cccd_value = uint16_decode(p_encoded_data);
-    return ((cccd_value & BLE_GATT_HVX_NOTIFICATION) != 0);
-}
-    
-/**@brief Function for decoding a CCCD value, and then testing if indication is
- *        enabled.
- *
- * @param[in]   p_encoded_data   Buffer where the encoded CCCD is stored.
- *
- * @return      TRUE if indication is enabled, FALSE otherwise.
- */
-static __INLINE bool ble_srv_is_indication_enabled(uint8_t * p_encoded_data)
-{
-    uint16_t cccd_value = uint16_decode(p_encoded_data);
-    return ((cccd_value & BLE_GATT_HVX_INDICATION) != 0);
-}
-
-/**@brief Function for encoding a Report Reference Descriptor.
- *
- * @param[in]   p_encoded_buffer  The buffer of the encoded data.
- * @param[in]   p_report_ref      Report Reference value to be encoded.
- *
- * @return      Length of the encoded data.
- */
-uint8_t ble_srv_report_ref_encode(uint8_t *                    p_encoded_buffer,
-                                  const ble_srv_report_ref_t * p_report_ref);
-
-/**@brief Function for making UTF-8 structure refer to an ASCII string.
- *
- * @param[out]  p_utf8   UTF-8 structure to be set.
- * @param[in]   p_ascii  ASCII string to be referred to.
- */
-void ble_srv_ascii_to_utf8(ble_srv_utf8_str_t * p_utf8, char * p_ascii);
-
-#endif // BLE_SRV_COMMON_H__
-
-/** @} */
\ No newline at end of file
--- a/source/nordic-sdk/components/ble/device_manager/config/device_manager_cnfg.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,118 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
- /**
- * @file device_manager_cnfg.h
- *
- * @cond
- * @defgroup device_manager_cnfg Device Manager Configuration 
- * @ingroup device_manager
- * @{
- *
- * @brief Defines application specific configuration for Device Manager.
- *
- * @details All configurations that are specific to application have been defined
- *          here. Application should configuration that best suits its requirements.
- */
- 
-#ifndef DEVICE_MANAGER_CNFG_H__
-#define DEVICE_MANAGER_CNFG_H__
-
-/**
- * @defgroup device_manager_inst Device Manager Instances
- * @{
- */
-/**
- * @brief Maximum applications that Device Manager can support.
- *
- * @details Maximum application that the Device Manager can support.
- *          Currently only one application can be supported.
- *          Minimum value : 1
- *          Maximum value : 1
- *          Dependencies  : None.
- */
-#define DEVICE_MANAGER_MAX_APPLICATIONS  1
-
-/**
- * @brief Maximum connections that Device Manager should simultaneously manage.
- *
- * @details Maximum connections that Device Manager should simultaneously manage.
- *          Minimum value : 1
- *          Maximum value : Maximum links supported by SoftDevice.
- *          Dependencies  : None.
- */
-#define DEVICE_MANAGER_MAX_CONNECTIONS   1
-
-
-/**
- * @brief Maximum bonds that Device Manager should manage.
- *
- * @details Maximum bonds that Device Manager should manage.
- *          Minimum value : 1
- *          Maximum value : 254.
- *          Dependencies  : None.
- * @note In case of GAP Peripheral role, the Device Manager will accept bonding procedure 
- *       requests from peers even if this limit is reached, but bonding information will not 
- *       be stored. In such cases, application will be notified with DM_DEVICE_CONTEXT_FULL 
- *       as event result at the completion of the security procedure.
- */
-#define DEVICE_MANAGER_MAX_BONDS         2
-
-
-/**
- * @brief Maximum Characteristic Client Descriptors used for GATT Server.
- *
- * @details Maximum Characteristic Client Descriptors used for GATT Server.
- *          Minimum value : 1
- *          Maximum value : 254.
- *          Dependencies  : None.
- */
-#define DM_GATT_CCCD_COUNT               2
-
-
-/**
- * @brief Size of application context.
- *
- * @details Size of application context that Device Manager should manage for each bonded device.
- *          Size had to be a multiple of word size.
- *          Minimum value : 4.
- *          Maximum value : 256. 
- *          Dependencies  : Needed only if Application Context saving is used by the application.
- * @note If set to zero, its an indication that application context is not required to be managed
- *       by the module.
- */
-#define DEVICE_MANAGER_APP_CONTEXT_SIZE    0
-
-/* @} */
-/* @} */
-/** @endcond */
-#endif // DEVICE_MANAGER_CNFG_H__
--- a/source/nordic-sdk/components/ble/device_manager/device_manager.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,916 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/**
- * @file device_manager.h
- *
- * @defgroup device_manager Device Manager
- * @ingroup ble_sdk_lib
- * @{
- * @brief Device Manager Application Interface Abstraction.
- *
- * @details The Device Manager module manages Active and Bonded Peers. Management of peer includes
- *          book keeping of contextual information like the Security Keys, GATT
- *          configuration and any application specific information.
- *
- *          Active Peers are devices which are connected, and may or may not be bonded.
- *          Bonded Peers are devices which are bonded, and may or may not be Active (Connected).
- *          Active Bonded Peer refers to a device which is connected and bonded.
- *
- *          Paired Devices refers to peer devices that are connected and have necessary context
- *          establishment/exchange for the current connection session. On disconnect,
- *          all contextual information is flushed. For example, SMP Information Exchanged during
- *          pairing and GATT Configuration is not retained on disconnection.
- *
- *          Note that this module allows management of contextual information but 
- *          does not provide an interface for connection management. Therefore, entering connectible
- *          mode, connection establishment, or disconnection of a link with peer is not in scope
- *          of this module.
- *
- *          For bonded peers, the contextual information is required to be retained on disconnection
- *          and power cycling. Persistent storage of contextual information is handled by the
- *          module. This module categorizes the contextual information into 3 categories:
- *             - <b>Bonding Information</b>
- *               Bond information is the information exchanged between local and peer device to
- *               establish a bond. It also includes peer identification information,
- *               like the peer address or the IRK or both. From here on this category of information
- *               is referred to as Device Context.
- *             - <b>Service/Protocol Information</b>
- *               Service/Protocol information is the information retained for the peer to save on one-time
- *               procedures like the GATT Service Discovery procedures and Service Configurations.
- *               It allows devices to resume data exchange on subsequent reconnection without having
- *               to perform initial set-up procedures each time. From here on this category is
- *               referred to as Service Context.
- *             - <b>Application Information</b>
- *               Application information is the context that the application would like to associate with
- *               each of the bonded device. For example, if the application chooses to rank its peers
- *               in order to manage them better, the rank information could be treated as
- *               Application Information. This storage space is provided to save the application from
- *               maintaining a mapping table with each Device Instance and Application Information.
- *               However, if the application have no use for this, it is possible to not
- *               use or employ this at compile time. From here on this category of information is
- *               referred to as Application Context.
- */
-
-
-#ifndef DEVICE_MANAGER_H__
-#define DEVICE_MANAGER_H__
-
-#include <stdint.h>
-#include <stdbool.h>
-#include "sdk_common.h"
-#include "ble.h"
-#include "ble_gap.h"
-#include "device_manager_cnfg.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @defgroup dm_service_cntext_types Service/Protocol Types
- *
- * @brief Describes the possible types of Service/Protocol Contexts for a bonded/peer device.
- *
- * @details Possible Service/Protocol context per peer device. The Device Manager provides the
- *          functionality of persistently storing the Service/Protocol context and can automatically
- *          load them when needed.
- *          For example system attributes for a GATT Server. Based on the nature of the application, 
- *          not all service types may be needed. The application can specify
- *          only the service/protocol context it wants to use at the time of registration.
- * @{
- */
-#define DM_PROTOCOL_CNTXT_NONE         0x00  /**< No Service Context, this implies the application does not want to associate any service/protocol context with the peer device */
-#define DM_PROTOCOL_CNTXT_GATT_SRVR_ID 0x01  /**< GATT Server Service Context, this implies the application does associate GATT Server with the peer device and this information will be loaded when needed for a bonded device */
-#define DM_PROTOCOL_CNTXT_GATT_CLI_ID  0x02  /**< GATT Client Service Context, this implies the application does associate GATT Client with the peer device and this information will be loaded when needed for a bonded device */
-#define DM_PROTOCOL_CNTXT_ALL                                                                     \
-        (DM_PROTOCOL_CNTXT_GATT_SRVR_ID | DM_PROTOCOL_CNTXT_GATT_CLI_ID) /**< All Service/Protocol Context, this implies that the application wants to associate all Service/Protocol Information with the bonded device. This is configurable based on system requirements. If the application has only one type of service, this define could be altered to reflect the same.  */
-/** @} */
-
-
-/**
- * @defgroup dm_events Device Manager Events
- *
- * @brief This section describes the device manager events that are notified to the application.
- *
- * @details The Device Manager notifies the application of various asynchronous events using the
- *          asynchronous event notification callback. All events has been categorized into:
- *          a. General.
- *          b. Link Status.
- *          c. Context Management.
- *
- *          In the callback, these events are notified along with handle that uniquely identifies:
- *          application instance, active instance (if applicable), device instance
- *          bonding instance, (if applicable) and service instance.
- *          Not all events are pertaining to an active connection, for example a context deletion event could occur even if the peer
- *          is not connected. Also, general category of events may not be pertaining to any specific peer.
- *          See also \ref dm_event_cb_t and \ref dm_register.
- * @{
- */
-/**
- * @defgroup general_events General Events
- *
- * @brief General or miscellaneous events.
- *
- * @details This category of events are general events not pertaining to a peer or context.
- *
- * @{
- */
-#define DM_EVT_RFU   0x00 /**< Reserved for future use, is never notified. */
-#define DM_EVT_ERROR 0x01 /**< Device Manager Event Error. */
-/** @} */
-
-/**
- * @defgroup link_status_events Link Status Events
- *
- * @brief Link Status Events.
- *
- * @details This category of events notify the application of the link status. Event result associated
- *          with the event is provided along with the event in the callback to provide more details of
- *          whether a procedure succeeded or failed and assist the application in decision making of
- *          how to proceed. For example if a DM_DEVICE_CONNECT_IND is indicated with NRF_SUCCESS
- *          result, the application may want to proceed with discovering and association with
- *          service of the peer. However, if indicated with a failure result, the application may
- *          want to take an alternate action such as reattempting to connect or go into a
- *          sleep mode.
- *
- * @{
- */
-#define DM_EVT_CONNECTION              0x11 /**< Indicates that link with the peer is established. */
-#define DM_EVT_DISCONNECTION           0x12 /**< Indicates that link with peer is torn down. */
-#define DM_EVT_SECURITY_SETUP          0x13 /**< Security procedure for link started indication */
-#define DM_EVT_SECURITY_SETUP_COMPLETE 0x14 /**< Security procedure for link completion indication. */
-#define DM_EVT_LINK_SECURED            0x15 /**< Indicates that link with the peer is secured. For bonded devices, subsequent reconnections with bonded peer will result only in this event when the link is secured and setup procedures will not occur unless the bonding information is either lost or deleted on either or both sides.  */
-#define DM_EVT_SECURITY_SETUP_REFRESH  0x16 /**< Indicates that the security on the link was re-established. */
-/** @} */
-
-/**
- * @defgroup context_mgmt_events Context Management Events
- *
- * @brief Context Management Events.
- *
- * @details These events notify the application of the status of context loading and storing.
- *
- * @{
- */
-#define DM_EVT_DEVICE_CONTEXT_LOADED   0x21 /**< Indicates that device context for a peer is loaded. */
-#define DM_EVT_DEVICE_CONTEXT_STORED   0x22 /**< Indicates that device context is stored persistently. */
-#define DM_EVT_DEVICE_CONTEXT_DELETED  0x23 /**< Indicates that device context is deleted. */
-#define DM_EVT_SERVICE_CONTEXT_LOADED  0x31 /**< Indicates that service context for a peer is loaded. */
-#define DM_EVT_SERVICE_CONTEXT_STORED  0x32 /**< Indicates that service context is stored persistently. */
-#define DM_EVT_SERVICE_CONTEXT_DELETED 0x33 /**< Indicates that service context is deleted. */
-#define DM_EVT_APPL_CONTEXT_LOADED     0x41 /**< Indicates that application context for a peer is loaded. */
-#define DM_EVT_APPL_CONTEXT_STORED     0x42 /**< Indicates that application context is stored persistently. */
-#define DM_EVT_APPL_CONTEXT_DELETED    0x43 /**< Indicates that application context is deleted. */
-/** @} */
-/** @} */
-
-#define DM_INVALID_ID 0xFF /**< Invalid instance idenitifer. */
-
-/**
- * @defgroup dm_data_structure Device Manager Data Types
- *
- * @brief This section describes all the data types exposed by the module to the application.
- * @{
- */
-
-/**
- * @brief Application Instance.
- *
- * @details Application instance uniquely identifies an application. The identifier is allocated by
- *          the device manager when application registers with the module. The application is
- *          expected to identify itself with this instance identifier when initiating subsequent
- *          requests. Application should use the utility API \ref dm_application_instance_set in
- *          order to set its application instance in dm_handle_t needed for all subsequent APIs.
- *          See also \ref dm_register.
- */
-typedef uint8_t dm_application_instance_t;
-
-/**
- * @brief Connection Instance.
- *
- * @details Identifies connection instance for an active device. This instance is allocated by the 
- *          device manager when a connection is established and is notified with DM_EVT_CONNECTION
- *          with the event result NRF_SUCCESS.
- */
-typedef uint8_t dm_connection_instance_t;
-
-/**
- * @brief Device Instance.
- *
- * @details Uniquely identifies a bonded peer device. The peer device may or may not be connected.
- *          In case of the central: The bonded device instance to identify the peer is allocated when bonding procedure is initiated by the central using dm_security_setup_req.
- *          In case of the peripheral: When the bonding procedure is successful, the DM_EVT_SECURITY_SETUP_COMPLETE event with success event result, is received.
- *          In case the module cannot add more bonded devices, no instance is allocated, this is indicated by an appropriate error code for the API/event as the case may be. Application can choose to disconnect the link.
- */
-typedef uint8_t dm_device_instance_t;
-
-/**
- * @brief Service Instance.
- *
- * @details Uniquely identifies a peer device. The peer device may or may not be connected. This
- *          instance is allocated by the device manager when a device is bonded and is notified
- *          when security procedures have been initiated.
- *          Security Procedures initiation is notified with DM_SECURITY_SETUP_IND with
- *          success event result. In case the event result indicates that the module cannot add more
- *          bonded devices, no instance is allocated. Application can chose to disconnect the link.
- */
-typedef uint8_t dm_service_instance_t;
-
-/**
- * @brief Service/Protocol Type Identifier.
- *
- * @details Uniquely identifies a service or a protocol type. Service/Protocol Type identification
- *          is needed as each service/protocol can have its own contextual data.
- *          This allows the peer to access more than one service at a time. \ref dm_service_cntext_types describes the
- *          list of services/protocols supported.
- */
-typedef uint8_t service_type_t;
-
-/**@brief Device Manager Master identification and encryption information. */
-typedef struct dm_enc_key
-{
-    ble_gap_enc_info_t  enc_info;  /**< GAP encryption information. */
-    ble_gap_master_id_t master_id; /**< Master identification. */
-} dm_enc_key_t;
-
-/** @brief Device Manager identity and address information. */
-typedef struct dm_id_key
-{
-  ble_gap_irk_t  id_info;      /**< Identity information. */
-  ble_gap_addr_t id_addr_info; /**< Identity address information. */
-} dm_id_key_t;
-
-/** @brief Device Manager signing information. */
-typedef struct dm_sign_key
-{
-    ble_gap_sign_info_t sign_key; /**< GAP signing information. */
-} dm_sign_key_t;
-
-/** @brief Security keys. */
-typedef struct dm_sec_keyset
-{
-    union 
-    {
-        dm_enc_key_t       * p_enc_key;  /**< Pointer to Device Manager encryption information structure. */
-    } enc_key;
-    dm_id_key_t   * p_id_key;            /**< Identity key, or NULL. */
-    dm_sign_key_t * p_sign_key;          /**< Signing key, or NULL. */
-} dm_sec_keys_t;
-
-/** @brief Device Manager security key set. */
-typedef struct
-{
-  dm_sec_keys_t keys_periph;  /**< Keys distributed by the device in the Peripheral role. */
-  dm_sec_keys_t keys_central; /**< Keys distributed by the device in the Central role. */
-} dm_sec_keyset_t;
-
-/**
- * @brief Device Handle used for unique identification of each peer.
- *
- * @details This data type is used to uniquely identify each peer device. A peer device could be
- *          active and/or bonded. Therefore an instance for active and bonded is provided.
- *          However, the application is expected to treat this is an opaque structure and use this for
- *          all API interactions once stored on appropriate events.
- *          See \ref dm_events.
- */
-typedef struct device_handle
-{
-    dm_application_instance_t    appl_id;       /**< Identifies the application instances for the device that is being managed. */
-    dm_connection_instance_t     connection_id; /**< Identifies the active connection instance. */
-    dm_device_instance_t         device_id;     /**< Identifies peer instance in the data base. */
-    dm_service_instance_t        service_id;    /**< Service instance identifier. */
-} dm_handle_t;
-
-/**
- * @brief Definition of Data Context.
- *
- * @details Defines contextual data format, it consists of context data length and pointer to data.
- */
-typedef struct
-{
-    uint32_t  flags;  /**< Additional flags identifying data. */
-    uint32_t  len;    /**< Length of data. */
-    uint8_t * p_data; /**< Pointer to contextual data, a copy is made of the data. */
-} dm_context_t;
-
-
-/**
- * @brief Device Context.
- *
- * @details Defines "device context" type for a device managed by device manager.
- */
-typedef dm_context_t dm_device_context_t;
-
-/**
- * @brief Service Context.
- *
- * @details Service context data for a service identified by the 'service_type' field.
- */
-typedef struct
-{
-    service_type_t service_type; /**< Identifies the service/protocol to which the context data is related. */
-    dm_context_t   context_data; /**< Contains length and pointer to context data */
-} dm_service_context_t;
-
-/**
- * @brief Application context.
- *
- * @details The application context can be used by the application to map any application level
- *          information that is to be mapped with a particular peer.
- *          For bonded peers, this information will be stored by the bond manager persistently.
- *          Note that the device manager treats this information as an
- *          opaque block of bytes.
- *          Necessary APIs to get and set this context for a peer have been provided.
- */
-typedef dm_context_t dm_application_context_t;
-
-/**
- * @brief Event parameters.
- *
- * @details Defines event parameters for each of the events notified by the module.
- */
-typedef union
-{
-    ble_gap_evt_t            * p_gap_param;       /**< All events that are triggered in device manager as a result of GAP events, like connection, disconnection and security procedures are accompanied with GAP parameters. */
-    dm_application_context_t * p_app_context;     /**< All events that are associated with application context procedures of store, load, and deletion have this as event parameter. */
-    dm_service_context_t     * p_service_context; /**< All events that are associated with service context procedures of store, load and deletion have this as event parameter. */
-    dm_device_context_t      * p_device_context;  /**< All events that are associated with device context procedures of store, load and deletion have this as event parameter. */
-} dm_event_param_t;
-
-/**
- * @brief Asynchronous events details notified to the application by the module.
- *
- * @details Defines event type along with event parameters notified to the application by the
- *          module.
- */
-typedef struct
-{
-    uint8_t          event_id;       /**< Identifies the event. See \ref dm_events for details on event types and their significance. */
-    dm_event_param_t event_param;    /**< Event parameters. Can be NULL if the event does not have any parameters. */
-    uint16_t         event_paramlen; /**< Length of the event parameters, is zero if the event does not have any parameters. */
-} dm_event_t;
-
-/**
- * @brief Event notification callback registered by application with the module.
- *
- * @details Event notification callback registered by application with the module when registering
- *          the module using \ref dm_register API.
- *
- * @param[in] p_handle   Identifies the peer for which the event is being notified.
- * @param[in] p_event    Identifies the event, any associated parameters and parameter length.
- *                       See \ref dm_events for details on event types and their significance.
- * @param[in,out] event_result   Provide additional information on the event. 
- *                      In addition to SDK error codes there is also a return value
- *                      indicating if maximum number of connections has been reached when connecting or bonding.
- *
- * @retval NRF_SUCCESS on success, or a failure to indicate if it could handle the event
- *         successfully. There is no action taken in case application returns a failure.
- */
-typedef ret_code_t (*dm_event_cb_t)(dm_handle_t const * p_handle,
-                                    dm_event_t const  * p_event,
-                                    ret_code_t        event_result);
-
-/**
- * @brief Initialization Parameters.
- *
- * @details Indicates the application parameters. Currently this only encompasses clearing
- *          all persistent data.
- */
-typedef struct
-{
-    bool clear_persistent_data; /**< Set to true in case the module should clear all persistent data. */
-} dm_init_param_t;
-
-/**
- * @brief Application Registration Parameters.
- *
- * @details Parameters needed by the module when registering with it.
- */
-typedef struct
-{
-    dm_event_cb_t        evt_handler;  /**< Event Handler to be registered. It will receive asynchronous notification from the module, see \ref dm_events for asynchronous events. */
-    uint8_t              service_type; /**< Bit mask identifying services that the application intends to support for all peers. */
-    ble_gap_sec_params_t sec_param;    /**< Security parameters to be used for the application. */
-} dm_application_param_t;
-
-/**
- * @brief Defines possible security status/states.
- *
- * @details Defines possible security status/states of a link when requested by application using
- *          the \ref dm_security_status_req.
- */
-typedef enum
-{
-    NOT_ENCRYPTED,          /**< The link is not secured. */
-    ENCRYPTION_IN_PROGRESS, /**< Link security is being established.*/
-    ENCRYPTED               /**< The link is secure.*/
-} dm_security_status_t;
-/** @} */
-
-/**
- * @defgroup dm_api Device Module APIs
- *
- * @brief This section describes APIs exposed by the module.
- *
- * @details This section describes APIs exposed by the module. The APIs have been categorized to provide
- *          better and specific look up for developers. Categories are:
- *          - Set up APIs.
- *          - Context Management APIs.
- *          - Utility APIs.
- *
- *          MSCs describe usage of these APIs.  
- *          See @ref dm_msc.
- * @{
- */
-/**
- * @defgroup dm_setup_api Device Module Set-up APIs
- *
- * @brief Initialization & registration APIs that are pre-requisite for all other module procedures.
- * @details This section describes the Module Initialization and Registration APIs needed to be set up by
- *          the application before device manager can start managing devices and device contexts
- *          for the application.
- *
- * @{
- */
-
-/**
- * @brief Module Initialization Routine.
- *
- * @details Function for initializing the module. Must called before any other APIs of the module are used.
- *
- * @param[in] p_init_param Initialization parameters.
- *
- * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
- *
- * @note It is mandatory that pstorage is initialized before initializing this module.
- */
-ret_code_t dm_init(dm_init_param_t const * p_init_param);
-
-/**
- * @brief Function for registering the application.
- *
- * @details This routine is used by the application to register for asynchronous events with the
- *          device manager. During registration the application also indicates the services that it
- *          intends to support on this instance. It is possible to register multiple times with the
- *          device manager. At least one instance shall be registered with the device manager after
- *          the module has been initialized.
- *          Maximum number of application instances device manager can support is determined
- *          by DM_MAX_APPLICATIONS.
- *
- *          All applications must be registered before initiating or accepting connections from the peer.     
- *
- * @param[in]  p_appl_param    Application parameters.
- * @param[out] p_appl_instance Application Instance Identifier in case registration is successful.
- *
- * @retval NRF_SUCCESS             On success, else an error code indicating reason for failure.
- * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization.
- * @retval NRF_ERROR_NO_MEM        If module cannot support more applications.
- *
- * @note Currently only one application instance is supported by the module.
- */
-ret_code_t dm_register(dm_application_instance_t    * p_appl_instance,
-                       dm_application_param_t const * p_appl_param);
-
-/**
- * @brief Function for handling BLE events.
- *
- * @details BLE Event Handler for the module. This routine should be called from BLE stack event
- *          dispatcher for the module to work as expected.
- *
- * @param[in] p_ble_evt BLE stack event being dispatched to the function.
- *
- */
-void dm_ble_evt_handler(ble_evt_t * p_ble_evt);
-
-/** @} */
-
-
-/**
- * @defgroup dm_security_api APIs to set up or read status of security on a link.
- *
- * @brief This section describes APIs to set up Security. These APIs require that the peer is
- *        connected before the procedures can be requested.
- *
- * @details This group allows application to request security procedures
- *          or get the status of the security on a link.
- * @{
- */
-/**
- * @brief Function for requesting setting up security on a link.
- *
- * @details This API initiates security procedures with a peer device.
- *          @note For the GAP Central role, in case peer is not bonded, request to bond/pair is
- *          initiated. If it is bonded, the link is re-encrypted using the existing bond information.
- *          For the GAP peripheral role, a Slave security request is sent.
- * @details If a pairing procedure is initiated successfully, application is notified of
- *          @ref DM_EVT_SECURITY_SETUP_COMPLETE. A result indicating success or failure is notified along with the event.
- *          In case the link is re-encrypted using existing bond information, @ref DM_EVT_LINK_SECURED is
- *          notified to the application.
- *
- * @param[in] p_handle Identifies the link on which security is desired.
- *
- * @retval NRF_SUCCESS             On success, else an error code indicating reason for failure.
- * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
- *                                 application registration.
- * @retval NRF_ERROR_NULL          If p_handle is NULL.
- * @retval NRF_ERROR_INVALID_ADDR  If the peer is not identified by the handle provided by the application
- *                                 or if the peer is not connected when this procedure is requested.
- */
-ret_code_t dm_security_setup_req(dm_handle_t * p_handle);
-
-/**
- * @brief Function for reading the status of the security on a link.
- *
- * @details This API allows application to query status of security on a link.
- *
- * @param[in]  p_handle  Identifies the link on which security is desired.
- * @param[out] p_status  Pointer where security status is provided to the application.
- *                       See \ref dm_security_status_t for possible statuses that can be expected.
- *
- * @retval NRF_SUCCESS             Or appropriate error code indicating reason for failure.
- * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
- *                                 application registration.
- * @retval NRF_ERROR_NULL          If p_handle or p_status is NULL.
- * @retval NRF_ERROR_INVALID_ADDR  If peer is not identified by the handle provided by the application
- *                                 or if peer is not connected when this procedure is requested.
- */
-ret_code_t dm_security_status_req(dm_handle_t const * p_handle, dm_security_status_t * p_status);
-
-/**
- * @brief Function for creating the whitelist.
- *
- * @details This API allows application to create whitelist based on bonded peer devices in module
- *          data base.
- *
- * @param[in]  p_handle       Identifies the application requesting whitelist creation.
- * @param[in,out] p_whitelist Pointer where created whitelist is provided to the application.
- *
- * @note 'addr_count' and 'irk_count' fields of the structure should be populated with the maximum
- *       number of devices that the application wishes to request in the whitelist. 
- *       If the number of bonded devices is less than requested, the fields are updated with that number of devices.
- *       If the number of devices are more than requested, the module will populate the list
- *       with devices in the order the bond was established with the peer devices. Also, if this routine is
- *       called when a connection exists with one or more peer devices,
- *       those connected devices are not added to the whitelist.
- *
- * @retval NRF_SUCCESS             On success, else an error code indicating reason for failure.
- * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
- *                                 application registration.
- * @retval NRF_ERROR_NULL          If p_handle or p_whitelist is NULL.
- */
-ret_code_t dm_whitelist_create(dm_application_instance_t const * p_handle,
-                               ble_gap_whitelist_t             * p_whitelist);
-
-/** @} */
-
-
-/**
- * @defgroup dm_cntxt_mgmt_api Context Management APIs
- *
- * @brief Utility APIs offered by the device manager to get information about the peer if and
- *        when needed.
- *
- * @details This group of API allow the application to access information that is not required to be
- *          maintained by the application but may be needed. Hence it is possible to get the
- *          information from the module instead of mapping all the information with a device
- *          context.
- * @{
- */
-
-ret_code_t dm_device_add(dm_handle_t               * p_handle,
-                         dm_device_context_t const * p_context);
-
-/**
- * @brief Function for deleting a peer device context and all related information from the database.
- *
- * @details Delete peer device context and all related information from database. If
- *          this API returns NRF_SUCCESS, DM_EVT_DEVICE_CONTEXT_DELETED event is notified to the
- *          application. Event result notified along with the event indicates success or failure
- *          of this procedure.
- *
- * @param[in] p_handle Identifies the peer device to be deleted.
- *
- * @retval NRF_SUCCESS             on success, else an error code indicating reason for failure.
- * @retval NRF_ERROR_INVALID_STATE In the API is called without module initialization and/or
- *                                 application registration.
- * @retval NRF_ERROR_NULL          If p_handle is NULL.
- * @retval NRF_ERROR_INVALID_ADDR  If peer is not identified the handle provided by the application.
- *
- * @note Deleting device context results in deleting service and application context for the
- *       bonded device. The respective events DM_EVT_SERVICE_CONTEXT_DELETED and
- *       DM_EVT_APPL_CONTEXT_DELETED are not notified to the application.
- */
-ret_code_t dm_device_delete(dm_handle_t const * p_handle);
-
-/**
- * @brief Function for deleting all peer device context and all related information from the database.
- *
- * @details Delete peer device context and all related information from database. If
- *          this API returns NRF_SUCCESS, DM_EVT_DEVICE_CONTEXT_DELETED event is notified to the
- *          application for each device that is deleted from the data base. Event result
- *          notified along with the event indicates success or failure of this procedure.
- *
- * @param[in] p_handle Identifies application instance that is requesting
- *                     the deletion of all bonded devices.
- *
- * @retval NRF_SUCCESS             On success, else an error code indicating reason for failure.
- * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
- *                                 application registration.
- * @retval NRF_ERROR_NULL          If p_handle is NULL.
- * @retval NRF_ERROR_INVALID_ADDR  If peer is not identified the handle provided by the application.
- *
- * @note Deleting device context results in deleting both service and application context for the
- *       bonded device. The respective events DM_EVT_SERVICE_CONTEXT_DELETED and
- *       DM_EVT_APPL_CONTEXT_DELETED are not notified to the application.
- */
-ret_code_t dm_device_delete_all(dm_application_instance_t const * p_handle);
-
-/**
- * @brief Function for setting Service Context for a peer device identified by 'p_handle' parameter.
- *
- * @details This API allows application to Set Service Context for a peer device identified by the
- *          'p_handle' parameter. This API is useful when the Service Context cannot be requested
- *          from the SoftDevice, but needs to be assembled by the application or an another module.
- *          (or when service context is exchanged in an out of band way.)
- *          This API could also be used to trigger a storing of service context into persistent
- *          memory. If this is desired, a NULL pointer could be passed to the p_context.
- *
- * @param[in] p_handle  Identifies peer device for which the procedure is requested.
- * @param[in] p_context Service context being set. The context information includes length of
- *                      data and pointer to the contextual data being set. The memory pointed to by
- *                      the pointer to data is assumed to be resident when API is being called and
- *                      can be freed or reused once the set procedure is complete. Set procedure
- *                      completion is indicated by the event \ref DM_EVT_SERVICE_CONTEXT_STORED.
- *                      The Event result is notified along with the event and indicates success or failure of
- *                      this procedure.
- *
- * @retval NRF_SUCCESS             On success, else an error code indicating reason for failure.
- * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
- *                                 application registration.
- * @retval NRF_ERROR_NULL          If p_handle is NULL.
- * @retval NRF_ERROR_INVALID_ADDR  If the peer is not identified by the handle provided by the application.
- */
-ret_code_t dm_service_context_set(dm_handle_t const          * p_handle,
-                                  dm_service_context_t const * p_context);
-
-/**
- * @brief Function for getting Service Context for a peer device identified by 'p_handle' parameter.
- *
- * @details Get Service Context for a peer device identified by the 'p_handle' parameter. If
- *          this API returns NRF_SUCCESS, DM_EVT_SERVICE_CONTEXT_LOADED event is notified to the
- *          application. The event result is notified along with the event indicates success or failure
- *          of this procedure.
- *
- * @param[in] p_handle  Identifies peer device for which procedure is requested.
- * @param[in] p_context Application context being requested. The context information includes length
- *                      of the data and a pointer to the data. Note that requesting a 'get'
- *                      of application does not need to provide memory, the pointer to data will be
- *                      pointing to service data and hence no data movement is involved.
- *
- * @retval NRF_SUCCESS             On success, else an error code indicating reason for failure.
- * @retval NRF_ERROR_INVALID_STATE In case API is called without module initialization and/or
- *                                 application registration.
- * @retval NRF_ERROR_NULL          If p_handle is NULL.
- * @retval NRF_ERROR_INVALID_ADDR  If the peer is not identified by the handle provided by the application.
- */
-ret_code_t dm_service_context_get(dm_handle_t const    * p_handle,
-                                  dm_service_context_t * p_context);
-
-/**
- * @brief Function for deleting a Service Context for a peer device identified by the 'p_handle' parameter.
- *
- * @details This API allows application to delete a Service Context identified for a peer device
- *          identified by the 'p_handle' parameter. If this API returns NRF_SUCCESS,
- *          DM_EVT_SERVICE_CONTEXT_DELETED event is notified to the application. 
- *          Event result is notified along with the event and indicates success or failure of this
- *          procedure.
- *
- * @param[in] p_handle Identifies peer device for which procedure is requested.
- *
- * @retval NRF_SUCCESS             On success, else an error code indicating reason for failure.
- * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
- *                                 application registration.
- * @retval NRF_ERROR_NULL          If p_handle is NULL.
- * @retval NRF_ERROR_INVALID_ADDR  If the peer is not identified by the handle provided by the application.
- */
-ret_code_t dm_service_context_delete(dm_handle_t const * p_handle);
-
-/**
- * @brief Function for setting Application Context for a peer device identified by the 'p_handle' parameter.
- *
- * @details This application allows the setting of the application context for the peer device identified by
- *          the 'p_handle'. Application context is stored persistently by the module and can be
- *          requested by the application at any time using the \ref dm_application_context_get
- *          API. Note that this procedure is permitted only for bonded devices. If the
- *          device is not bonded, application context cannot be set. However, it is not mandatory
- *          that the bonded device is connected when requesting this procedure.
- *
- * @param[in] p_handle  Identifies peer device for which procedure is requested.
- *
- * @param[in] p_context Application context being set. The context information includes length of the
- *                      data and pointer to the contextual data being set. The memory pointed to by
- *                      the data pointer is assumed to be resident when API is being called and
- *                      can be freed or reused once the set procedure is complete. Set procedure
- *                      completion is notified by the event \ref DM_EVT_APPL_CONTEXT_STORED.
- *                      The event result is notified along with the event and indicates success or
- *                      failure of this procedure.
- *
- * @retval NRF_SUCCESS             On success, else an error code indicating reason for failure.
- * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
- *                                 application registration.
- * @retval NRF_ERROR_NULL          If p_handle and/or p_context is NULL.
- * @retval NRF_ERROR_INVALID_ADDR  If peer is not identified the handle provided by the application.
- *
- * @note The API returns FEATURE_NOT_ENABLED in case DEVICE_MANAGER_APP_CONTEXT_SIZE is set to zero.
- */
-ret_code_t dm_application_context_set(dm_handle_t const              * p_handle,
-                                      dm_application_context_t const * p_context);
-
-/**
- * @brief Function for getting Application Context for a peer device identified by the 'p_handle' parameter.
- *
- * @details Get Application Context for a peer device identified by the 'p_handle' parameter. If
- *          this API returns NRF_SUCCESS, DM_EVT_APPL_CONTEXT_LOADED event is notified to the
- *          application. Event result notified along with the event indicates success or failure
- *          of this procedure.
- *
- * @param[in] p_handle  Identifies peer device for which procedure is requested.
- * @param[in] p_context Application context being requested. The context information includes
- *                      length of data and pointer to the contextual data is provided.
- *
- * @retval NRF_SUCCESS             On success, else an error code indicating reason for failure.
- * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
- *                                 application registration.
- * @retval NRF_ERROR_NULL          If p_handle and/or p_context is NULL.
- * @retval NRF_ERROR_INVALID_ADDR  If the peer is not identified by the handle provided by the application.
- * @retval DM_NO_APP_CONTEXT       If no application context was set that can be fetched.
- *
- * @note The API returns FEATURE_NOT_ENABLED in case DEVICE_MANAGER_APP_CONTEXT_SIZE is set to
- *       zero.
- */
-ret_code_t dm_application_context_get(dm_handle_t const        * p_handle,
-                                      dm_application_context_t * p_context);
-
-/**
- * @brief Function for deleting Application Context for a peer device identified by the 'p_handle' parameter.
- *
- * @details Delete Application Context for a peer device identified by the 'p_handle' parameter. If
- *          this API returns NRF_SUCCESS, DM_EVT_APPL_CONTEXT_DELETED event is notified to the
- *          application. The event result notified along with the event and indicates success or failure
- *          of this procedure.
- *
- * @param[in] p_handle Identifies peer device for which procedure is requested.
- *
- * @retval NRF_SUCCESS             On success, else an error code indicating reason for failure.
- * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
- *                                 application registration.
- * @retval NRF_ERROR_NULL          If the p_handle is NULL.
- * @retval NRF_ERROR_INVALID_ADDR  If peer is not identified the handle provided by the application.
- * @retval DM_NO_APP_CONTEXT       If no application context was set that can be deleted.
- *
- * @note The API returns FEATURE_NOT_ENABLED if the DEVICE_MANAGER_APP_CONTEXT_SIZE is set to zero.
- */
-ret_code_t dm_application_context_delete(dm_handle_t const * p_handle);
-
-/** @} */
-
-
-/**
- * @defgroup utility_api Utility APIs
- * @{
- * @brief This section describes the utility APIs offered by the module.
- *
- * @details APIs defined in this section are utility or assisting/helper APIs.
- */
-/**
- * @brief Function for Setting/Copying Application instance to Device Manager handle.
- *
- * @param[in]  p_appl_instance Application instance to be set.
- * @param[out] p_handle        Device Manager handle for which the instance is to be copied.
- *
- * @retval NRF_SUCCESS             On success, else an error code indicating reason for failure.
- * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
- *                                 application registration.
- * @retval NRF_ERROR_NULL          If p_handle and/or p_addr is NULL.
- */
-ret_code_t dm_application_instance_set(dm_application_instance_t const * p_appl_instance,
-                                       dm_handle_t                     * p_handle);
-
-/**
- * @brief Function for getting a peer's device address.
- *
- * @param[in]  p_handle Identifies the peer device whose address is requested. Can not be NULL.
- * @param[out] p_addr   Pointer where address is to be copied. Can not be NULL.
- *
- * @retval NRF_SUCCESS             On success, else an error code indicating reason for failure.
- * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
- *                                 application registration.
- * @retval NRF_ERROR_NULL          If p_handle and/or p_addr is NULL.
- * @retval NRF_ERROR_NOT_FOUND     If the peer could not be identified.
- */
-ret_code_t dm_peer_addr_get(dm_handle_t const * p_handle,
-                            ble_gap_addr_t    * p_addr);
-
-/**
- * @brief Function for setting/updating a peer's device address.
- *
- * @param[in]  p_handle Identifies the peer device whose address is requested to be set/updated.
- * @param[out] p_addr   Address to be set/updated.
- *
- * @retval NRF_SUCCESS             On success, else an error code indicating reason for failure.
- * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
- *                                 application registration.
- * @retval NRF_ERROR_NULL          If p_handle and/or p_addr is NULL.
- * @retval NRF_ERROR_INVALID_ADDR  If the peer is not identified by the handle provided by the application.
- * @retval NRF_ERROR_INVALID_PARAM If this procedure is requested while connected to the peer or if the address
- *                                 type was set to BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE.
- *
- * @note Setting or updating a peer's device address is permitted 
- *       only for a peer that is bonded and disconnected.
- * @note Updated address is reflected only after DM_EVT_DEVICE_CONTEXT_STORED is notified to the
- *       application for this bonded device instance. In order to avoid abnormal behaviour, it is
- *       recommended to not invite/initiate connections on the updated address unless this event
- *       has been notified.
- */
-ret_code_t dm_peer_addr_set(dm_handle_t const    * p_handle,
-                            ble_gap_addr_t const * p_addr);
-
-/**
- * @brief Function for initializing Device Manager handle.
- *
- * @param[in] p_handle Device Manager handle to be initialized.
- *
- * @retval NRF_SUCCESS    On success.
- * @retval NRF_ERROR_NULL If p_handle is NULL.
- *
- * @note This routine is permitted before initialization of the module.
- */
-ret_code_t dm_handle_initialize(dm_handle_t * p_handle);
-
-/**
- * @brief Function for getting distributed keys for a device.
- *
- * @param[in]  p_handle   Device Manager handle identifying the peer.
- * @param[out] p_key_dist Pointer to distributed keys.
- *
- * @retval NRF_SUCCESS             On success, else an error code indicating reason for failure.
- * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
- *                                 application registration.
- * @retval NRF_ERROR_NULL          If the p_handle and/or p_key_dist pointer is NULL.
- * @retval NRF_ERROR_INVALID_ADDR  If the peer is not identified by the handle provided by the application.
- */
-ret_code_t dm_distributed_keys_get(dm_handle_t const * p_handle,
-                                   dm_sec_keyset_t   * p_key_dist);
-
-/**
- * @brief Function for getting the corresponding dm_handle_t based on the connection handle.
- *
- * @param[in]     conn_handle Connection handle as provided by the SoftDevice.
- * @param[in,out] p_handle    Pointer to the p_handle containg the application instance for the 
- *                            registered application. If the application instance is valid then 
- *                            the p_handle will be filled with requested data.
- *
- * @retval NRF_SUCCESS          On success, else an error code indicating reason for failure.
- * @retval NRF_ERROR_NULL       If the p_handle pointer is NULL.
- * @retval NRF_ERROR_NOT_FOUND  If no p_handle is found for the provided connection handle.
- */
-ret_code_t dm_handle_get(uint16_t conn_handle, dm_handle_t * p_handle);
-
-#ifdef __cplusplus
-}
-#endif
-
-/** @} */
-/** @} */
-/** @} */
-#endif // DEVICE_MANAGER_H__
--- a/source/nordic-sdk/components/ble/device_manager/device_manager_peripheral.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2932 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "device_manager.h"
-// #include "app_trace.h"
-#include "pstorage.h"
-#include "ble_hci.h"
-#include "app_error.h"
-
-#if defined ( __CC_ARM )
-    #ifndef __ALIGN
-        #define __ALIGN(x)      __align(x)                  /**< Forced aligment keyword for ARM Compiler */
-    #endif
-#elif defined ( __ICCARM__ )
-    #ifndef __ALIGN
-        #define __ALIGN(x)                                  /**< Forced aligment keyword for IAR Compiler */
-    #endif
-#elif defined   ( __GNUC__ )
-    #ifndef __ALIGN
-        #define __ALIGN(x)      __attribute__((aligned(x))) /**< Forced aligment keyword for GNU Compiler */
-    #endif
-#endif
-
-#define INVALID_ADDR_TYPE 0xFF   /**< Identifier for an invalid address type. */
-#define EDIV_INIT_VAL     0xFFFF /**< Initial value for diversifier. */
-
-/**
- * @defgroup device_manager_app_states Connection Manager Application States
- * @{
- */
-#define STATE_CONTROL_PROCEDURE_IN_PROGRESS 0x01 /**< State where a security procedure is ongoing. */
-#define STATE_QUEUED_CONTROL_REQUEST        0x02 /**< State where it is known if there is any queued security request or not. */
-/** @} */
-
-/**
- * @defgroup device_manager_conn_inst_states Connection Manager Connection Instances States.
- * @{
- */
-#define STATE_IDLE             0x01 /**< State where connection instance is free. */
-#define STATE_CONNECTED        0x02 /**< State where connection is successfully established. */
-#define STATE_PAIRING          0x04 /**< State where pairing procedure is in progress. This state is used for pairing and bonding, as pairing is needed for both. */
-#define STATE_BONDED           0x08 /**< State where device is bonded. */
-#define STATE_DISCONNECTING    0x10 /**< State where disconnection is in progress, application will be notified first, but no further active procedures on the link. */
-#define STATE_PAIRING_PENDING  0x20 /**< State where pairing request is pending on the link. */
-#define STATE_BOND_INFO_UPDATE 0x40 /**< State where information has been updated, update the flash. */
-#define STATE_LINK_ENCRYPTED   0x80 /**< State where link is encrypted. */
-/** @} */
-
-/**
- * @defgroup device_manager_peer_id_defines Peer Identification Information Defines.
- *
- * @brief These defines are used to know which of the peer identification is applicable for a peer.
- *
- * @details These defines are used for peer identification. Here, bit map is used because it is
- *          possible that the application has both IRK and address for identification.
- * @{
- */
-#define UNASSIGNED            0xFF /**< Peer instance is unassigned/unused. */
-#define IRK_ENTRY             0x01 /**< Peer instance has IRK as identification information. */
-#define ADDR_ENTRY            0x02 /**< Peer instance has address as identification information. */
-#define SERVICE_CONTEXT_ENTRY 0x04 /**< Peer instance has service context set. */
-#define APP_CONTEXT_ENTRY     0x08 /**< Peer instance has an application context set. */
-/** @} */
-
-/**@brief Device store state identifiers. */
-typedef enum
-{
-    STORE_ALL_CONTEXT, /**< Store all context. */
-    FIRST_BOND_STORE,  /**< Store bond. */
-    UPDATE_PEER_ADDR   /**< Update peer address. */
-} device_store_state_t;
-
-/**
- * @defgroup device_manager_context_offsets Context Offsets
- * @{
- *
- * @brief Context offsets each of the context information in persistent memory.
- *
- * @details Below is a layout showing how each how the context information is stored in persistent
- *          memory.
- *
- * All Device context is stored in the flash as follows:
- * +---------+---------+---------+------------------+----------------+--------------------+
- * | Block / Device ID + Layout of stored information in storage block                    |
- * +---------+---------+---------+------------------+----------------+--------------------+
- * | Block 0 | Device 0| Peer Id | Bond Information | Service Context| Application Context|
- * +---------+---------+---------+------------------+----------------+--------------------+
- * | Block 1 | Device 1| Peer Id | Bond Information | Service Context| Application Context|
- * +---------+---------+---------+------------------+----------------+--------------------+
- * |  ...              | ....                                                             |
- * +---------+---------+---------+------------------+----------------+--------------------+
- * | Block N | Device N| Peer Id | Bond Information | Service Context| Application Context|
- * +---------+---------+---------+------------------+----------------+--------------------+
- *
- * The following defines are used to get offset of each of the components within a block.
- */
-
-#define PEER_ID_STORAGE_OFFSET     0                                               /**< Offset at which peer id is stored in the block. */
-#define BOND_STORAGE_OFFSET        PEER_ID_SIZE                                    /**< Offset at which bond information is stored in the block. */
-#define SERVICE_STORAGE_OFFSET     (BOND_STORAGE_OFFSET + BOND_SIZE)               /**< Offset at which service context is stored in the block. */
-#define APP_CONTEXT_STORAGE_OFFSET (SERVICE_STORAGE_OFFSET + SERVICE_CONTEXT_SIZE) /**< Offset at which application context is stored in the block. */
-/** @} */
-
-/**
- * @defgroup device_manager_context_size Context size.
- * @{
- *
- * @brief This group defines the size of each of the context information.
- */
-#define PEER_ID_SIZE               (sizeof(peer_id_t))                                             /**< Size of peer identification information. */
-#define BOND_SIZE                  (sizeof(bond_context_t))                                        /**< Size of bond information. */
-#define DEVICE_CONTEXT_SIZE        (PEER_ID_SIZE + BOND_SIZE)                                      /**< Size of Device context, include peer identification and bond information. */
-#define GATTS_SERVICE_CONTEXT_SIZE (sizeof(dm_gatts_context_t))                                    /**< Size of GATTS service context. */
-#define GATTC_SERVICE_CONTEXT_SIZE (sizeof(dm_gatt_client_context_t))                              /**< Size of GATTC service context. */
-#define SERVICE_CONTEXT_SIZE       (GATTS_SERVICE_CONTEXT_SIZE + GATTC_SERVICE_CONTEXT_SIZE)       /**< Combined size of GATTS and GATTC service contexts. */
-#define APP_CONTEXT_MIN_SIZE       4                                                               /**< Minimum size for application context data. */
-#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0)
-#define APP_CONTEXT_SIZE           (sizeof(uint32_t) + DEVICE_MANAGER_APP_CONTEXT_SIZE)            /**< Size of application context including length field. */
-#else //DEVICE_MANAGER_APP_CONTEXT_SIZE
-#define APP_CONTEXT_SIZE           0                                                               /**< Size of application context. */
-#endif // DEVICE_MANAGER_APP_CONTEXT_SIZE
-#define ALL_CONTEXT_SIZE           (DEVICE_CONTEXT_SIZE + SERVICE_CONTEXT_SIZE + APP_CONTEXT_SIZE) /**< Size of all contexts. */
-/** @} */
-
-
-/**
- * @defgroup device_manager_log Module's Log Macros
- *
- * @details Macros used for creating module logs which can be useful in understanding handling
- *          of events or actions on API requests. These are intended for debugging purposes and
- *          can be disabled by defining the DM_DISABLE_LOGS.
- *
- * @note That if ENABLE_DEBUG_LOG_SUPPORT is disabled, having DM_DISABLE_LOGS has no effect.
- * @{
- */
-#define DM_DISABLE_LOGS        /**< Enable this macro to disable any logs from this module. */
-
-#ifndef DM_DISABLE_LOGS
-#define DM_LOG  app_trace_log  /**< Used for logging details. */
-#define DM_ERR  app_trace_log  /**< Used for logging errors in the module. */
-#define DM_TRC  app_trace_log  /**< Used for getting trace of execution in the module. */
-#define DM_DUMP app_trace_dump /**< Used for dumping octet information to get details of bond information etc. */
-#else //DM_DISABLE_LOGS
-#define DM_DUMP(...)           /**< Disables dumping of octet streams. */
-#define DM_LOG(...)            /**< Disables detailed logs. */
-#define DM_ERR(...)            /**< Disables error logs. */
-#define DM_TRC(...)            /**< Disables traces. */
-#endif //DM_DISABLE_LOGS
-/** @} */
-
-/**
- * @defgroup device_manager_mutex_lock_unlock Module's Mutex Lock/Unlock Macros.
- *
- * @details Macros used to lock and unlock modules. Currently the SDK does not use mutexes but
- *          framework is provided in case need arises to use an alternative architecture.
- * @{
- */
-#define DM_MUTEX_LOCK()   SDK_MUTEX_LOCK(m_dm_mutex)   /**< Lock module using mutex. */
-#define DM_MUTEX_UNLOCK() SDK_MUTEX_UNLOCK(m_dm_mutex) /**< Unlock module using mutex. */
-/** @} */
-
-
-/**
- * @defgroup device_manager_misc_defines Miscellaneous defines used across the module.
- * @{
- */
-#define DM_GATT_ATTR_SIZE            6                                                   /**< Size of each GATT attribute to be stored persistently. */
-#define DM_GATT_SERVER_ATTR_MAX_SIZE ((DM_GATT_ATTR_SIZE * DM_GATT_CCCD_COUNT) + 2) /**< Maximum size of GATT attributes to be stored.*/
-#define DM_SERVICE_CONTEXT_COUNT     (DM_PROTOCOL_CNTXT_ALL + 1)                         /**< Maximum number of service contexts. */
-#define DM_EVT_DEVICE_CONTEXT_BASE   0x20                                                /**< Base for device context base. */
-#define DM_EVT_SERVICE_CONTEXT_BASE  0x30                                                /**< Base for service context base. */
-#define DM_EVT_APP_CONTEXT_BASE      0x40                                                /**< Base for application context base. */
-#define DM_LOAD_OPERATION_ID         0x01                                                /**< Load operation identifier. */
-#define DM_STORE_OPERATION_ID        0x02                                                /**< Store operation identifier. */
-#define DM_CLEAR_OPERATION_ID        0x03                                                /**< Clear operation identifier. */
-/** @} */
-
-#define DM_GATTS_INVALID_SIZE        0xFFFFFFFF                                     /**< Identifer for GATTS invalid size. */
-
-/**
- * @defgroup api_param_check API Parameters check macros.
- *
- * @details Macros for verifying parameters passed to the module in the APIs. These macros
- *          could be mapped to nothing in the final version of the code in order to save execution 
- *          time and program size.
- * @{
- */
-
-//#define DM_DISABLE_API_PARAM_CHECK /**< Macro to disable API parameters check. */
-
-#ifndef DM_DISABLE_API_PARAM_CHECK
-
-/**@brief Macro for verifying NULL parameters are not passed to API.
- *
- * @param[in] PARAM Parameter checked for NULL.
- *
- * @retval (NRF_ERROR_NULL | DEVICE_MANAGER_ERR_BASE) when @ref PARAM is NULL.
- */
-#define NULL_PARAM_CHECK(PARAM)                            \
-    if ((PARAM) == NULL)                                   \
-    {                                                      \
-        return (NRF_ERROR_NULL | DEVICE_MANAGER_ERR_BASE); \
-    }
-/**@} */
-
-
-/**@brief Macro for verifying module's initialization status.
- *
- * @retval (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE) when module is not initialized.
- */
-#define VERIFY_MODULE_INITIALIZED()                                     \
-    do                                                                  \
-    {                                                                   \
-        if (!m_module_initialized)                                      \
-        {                                                               \
-            return (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE); \
-        }                                                               \
-    } while (0)
-
-
-/**@brief Macro for verifying module's initialization status. Returns in case it is not initialized.
- */
-#define VERIFY_MODULE_INITIALIZED_VOID() \
-    do                                   \
-    {                                    \
-        if (!m_module_initialized)       \
-        {                                \
-            return;                      \
-        }                                \
-    } while (0)
-
-
-/**@brief Macro for verifying that the application is registered.
- *
- * @param[in] X Application instance identifier.
- *
- * @retval (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE) when module API is called without
- *         registering an application with the module.
- */
-#define VERIFY_APP_REGISTERED(X)                                        \
-    do                                                                  \
-    {                                                                   \
-        if (((X) >= DEVICE_MANAGER_MAX_APPLICATIONS) ||                 \
-            (m_application_table[(X)].ntf_cb == NULL))                  \
-        {                                                               \
-            return (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE); \
-        }                                                               \
-    } while (0)
-
-
-/**@brief Macro for verifying that the application is registered. Returns in case it is not
- *        registered.
- *
- * @param[in] X Application instance identifier.
- */
-#define VERIFY_APP_REGISTERED_VOID(X)                   \
-    do                                                  \
-    {                                                   \
-        if (((X) >= DEVICE_MANAGER_MAX_APPLICATIONS) || \
-            (m_application_table[(X)].ntf_cb == NULL))  \
-        {                                               \
-            return;                                     \
-        }                                               \
-    } while (0)
-
-
-/**@brief Macro for verifying connection instance is allocated.
- *
- * @param[in] X Connection instance identifier.
- *
- * @retval (NRF_ERROR_INVALID_ADDR | DEVICE_MANAGER_ERR_BASE) when connection instance is not
- *         allocated.
- */
-#define VERIFY_CONNECTION_INSTANCE(X)                                  \
-    do                                                                 \
-    {                                                                  \
-        if (((X) >= DEVICE_MANAGER_MAX_CONNECTIONS) ||                 \
-            (m_connection_table[(X)].state == STATE_IDLE))             \
-        {                                                              \
-            return (NRF_ERROR_INVALID_ADDR | DEVICE_MANAGER_ERR_BASE); \
-        }                                                              \
-    } while (0)
-
-
-/**@brief Macro for verifying if device instance is allocated.
- *
- * @param[in] X Device instance identifier.
- *
- * @retval (NRF_ERROR_INVALID_ADDR | DEVICE_MANAGER_ERR_BASE) when device instance is not allocated.
- */
-#define VERIFY_DEVICE_INSTANCE(X)                                      \
-    do                                                                 \
-    {                                                                  \
-        if (((X) >= DEVICE_MANAGER_MAX_BONDS) ||                       \
-            (m_peer_table[(X)].id_bitmap == UNASSIGNED))               \
-        {                                                              \
-            return (NRF_ERROR_INVALID_ADDR | DEVICE_MANAGER_ERR_BASE); \
-        }                                                              \
-    } while (0)
-
-/**@brief Macro for verifying if device is bonded and thus can store data persistantly.
- *
- * @param[in] X Connection instance identifier.
- *
- * @retval (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE) when device is not bonded.
- */
-#define VERIFY_DEVICE_BOND(X)                                              \
-    do                                                                     \
-    {                                                                      \
-        if ((m_connection_table[(X)].state & STATE_BONDED) != STATE_BONDED)\
-        {                                                                  \
-            return (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE);    \
-        }                                                                  \
-    } while (0)
-#else
-#define NULL_PARAM_CHECK(X)
-#define VERIFY_MODULE_INITIALIZED()
-#define VERIFY_MODULE_INITIALIZED_VOID()
-#define VERIFY_APP_REGISTERED(X)
-#define VERIFY_APP_REGISTERED_VOID(X)
-#define VERIFY_CONNECTION_INSTANCE(X)
-#define VERIFY_DEVICE_INSTANCE(X)
-#endif //DM_DISABLE_API_PARAM_CHECK
-/** @} */
-
-#define INVALID_CONTEXT_LEN 0xFFFFFFFF /**< Identifier for invalid context length. */
-/**@brief Macro for checking that application context size is greater that minimal size.
- *
- * @param[in] X Size of application context.
- *
- * @retval (NRF_ERROR_INVALID_PARAM) when size is smaller than minimun required size.
- */
-#define SIZE_CHECK_APP_CONTEXT(X)                                      \
-    if ((X) < (APP_CONTEXT_MIN_SIZE))                                  \
-    {                                                                  \
-        return NRF_ERROR_INVALID_PARAM;                                \
-    }
-
-
-/**
- * @defgroup dm_data_types Module's internal data types.
- *
- * @brief This section describes a module's internal data structures.
- * @{
- */
-/**@brief Peer identification information.
- */
-typedef struct
-{ 
-    ble_gap_id_key_t peer_id;   /**< IRK and/or address of peer. */
-    uint16_t         ediv;      /**< Peer's encrypted diversifier. */
-    uint8_t          id_bitmap; /**< Contains information if above field is valid. */
-} peer_id_t;
-
-STATIC_ASSERT(sizeof(peer_id_t) % 4 == 0); /**< Check to ensure Peer identification information is a multiple of 4. */
-
-/**@brief Portion of bonding information exchanged by a device during bond creation that needs to
- *        be stored persistently.
- *
- * @note  An entry is not made in this table unless device is bonded.
- */
-typedef struct
-{
-    ble_gap_enc_key_t peer_enc_key; /**< Local LTK info, central IRK and address */
-} bond_context_t;
-
-STATIC_ASSERT(sizeof(bond_context_t) % 4 == 0); /**< Check to ensure bond information is a multiple of 4. */
-
-/**@brief GATT Server Attributes size and data.
- */
-typedef struct
-{
-    uint32_t flags;                                    /**< Flags identifying the stored attributes. */
-    uint32_t size;                                     /**< Size of stored attributes. */
-    uint8_t  attributes[DM_GATT_SERVER_ATTR_MAX_SIZE]; /**< Array to hold the server attributes. */
-} dm_gatts_context_t;
-
-STATIC_ASSERT(sizeof(dm_gatts_context_t) % 4 == 0); /**< Check to ensure GATT Server Attributes size and data information is a multiple of 4. */
-
-/**@brief GATT Client context information. Placeholder for now.
- */
-typedef struct
-{
-    void * p_dummy; /**< Placeholder, currently unused. */
-} dm_gatt_client_context_t;
-
-STATIC_ASSERT(sizeof(dm_gatt_client_context_t) % 4 == 0);  /**< Check to ensure GATT Client context information is a multiple of 4. */
-STATIC_ASSERT((DEVICE_MANAGER_APP_CONTEXT_SIZE % 4) == 0); /**< Check to ensure device manager application context information is a multiple of 4. */
-
-/**@brief Connection instance definition. Maintains information with respect to an active peer.
- */
-typedef struct
-{
-    ble_gap_addr_t peer_addr;     /**< Peer identification information. This information is retained as long as the connection session exists, once disconnected, for non-bonded devices this information is not stored persistently. */
-    uint16_t       conn_handle;   /**< Connection handle for the device. */
-    uint8_t        state;         /**< Link state. */
-    uint8_t        bonded_dev_id; /**< In case the device is bonded, this points to the corresponding bonded device. This index can be used to index service and bond context as well. */
-} connection_instance_t;
-
-/**@brief Application instance definition. Maintains information with respect to a registered
- *        application.
- */
-typedef struct
-{
-    dm_event_cb_t        ntf_cb;    /**< Callback registered with the application. */
-    ble_gap_sec_params_t sec_param; /**< Local security parameters registered by the application. */
-    uint8_t              state;     /**< Application state. Currently this is used only for knowing if any security procedure is in progress and/or a security procedure is pending to be requested. */
-    uint8_t              service;   /**< Service registered by the application. */
-} application_instance_t;
-
-/**@brief Function for performing necessary action of storing each of the service context as
- *        registered by the application.
- *
- * @param[in] p_block_handle Storage block identifier.
- * @param[in] p_handle       Device handle identifying device that is stored.
- *
- * @retval Operation result code.
- */
-typedef ret_code_t (* service_context_access_t)(pstorage_handle_t const * p_block_handle,
-                                                dm_handle_t const       * p_handle);
-
-/**@brief Function for performing necessary action of applying the context information.
- *
- * @param[in] p_handle Device handle identifying device that is stored.
- *
- * @retval Operation result code.
- */
-typedef ret_code_t (* service_context_apply_t)(dm_handle_t * p_handle);
-
-/**@brief Function for performing necessary functions of storing or updating.
- *
- * @param[in] p_dest Destination address where data is stored persistently.
- * @param[in] p_src  Source address containing data to be stored.
- * @param[in] size   Size of data to be stored expressed in bytes. Must be word aligned.
- * @param[in] offset Offset in bytes to be applied when writing to the block.
- *
- * @retval Operation result code.
- */
-typedef uint32_t (* storage_operation)(pstorage_handle_t * p_dest,
-                                       uint8_t           * p_src,
-                                       pstorage_size_t     size,
-                                       pstorage_size_t     offset);
-/** @} */
-
-/**
- * @defgroup dm_tables Module's internal tables.
- *
- * @brief This section describes the module's internal tables and the static global variables
- *        needed for its functionality.
- * @{
- */
-#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0)
-static uint8_t * m_app_context_table[DEVICE_MANAGER_MAX_BONDS];                     /**< Table to remember application contexts of bonded devices. */
-#endif //DEVICE_MANAGER_APP_CONTEXT_SIZE
-__ALIGN(sizeof(uint32_t))
-static peer_id_t              m_peer_table[DEVICE_MANAGER_MAX_BONDS] ;              /**< Table to maintain bonded devices' identification information, an instance is allocated in the table when a device is bonded and freed when bond information is deleted. */
-__ALIGN(sizeof(uint32_t))
-static bond_context_t         m_bond_table[DEVICE_MANAGER_MAX_CONNECTIONS];         /**< Table to maintain bond information for active peers. */
-static dm_gatts_context_t     m_gatts_table[DEVICE_MANAGER_MAX_CONNECTIONS];        /**< Table for service information for active connection instances. */
-static connection_instance_t  m_connection_table[DEVICE_MANAGER_MAX_CONNECTIONS];   /**< Table to maintain active peer information. An instance is allocated in the table when a new connection is established and freed on disconnection. */
-static application_instance_t m_application_table[DEVICE_MANAGER_MAX_APPLICATIONS]; /**< Table to maintain application instances. */
-static pstorage_handle_t      m_storage_handle;                                     /**< Persistent storage handle for blocks requested by the module. */
-static uint32_t               m_peer_addr_update;                                   /**< 32-bit bitmap to remember peer device address update. */
-static ble_gap_id_key_t       m_local_id_info;                                      /**< ID information of central in case resolvable address is used. */
-static bool                   m_module_initialized = false;                         /**< State indicating if module is initialized or not. */
-static uint8_t                m_irk_index_table[DEVICE_MANAGER_MAX_BONDS];          /**< List maintaining IRK index list. */
-
-SDK_MUTEX_DEFINE(m_dm_mutex) /**< Mutex variable. Currently unused, this declaration does not occupy any space in RAM. */
-/** @} */
-
-static __INLINE ret_code_t no_service_context_store(pstorage_handle_t const * p_block_handle,
-                                                    dm_handle_t const       * p_handle);
-
-static __INLINE ret_code_t gatts_context_store(pstorage_handle_t const * p_block_handle,
-                                               dm_handle_t const       * p_handle);
-
-static __INLINE ret_code_t gattc_context_store(pstorage_handle_t const * p_block_handle,
-                                               dm_handle_t const       * p_handle);
-
-static __INLINE ret_code_t gattsc_context_store(pstorage_handle_t const * p_block_handle,
-                                                dm_handle_t const       * p_handle);
-
-static __INLINE ret_code_t no_service_context_load(pstorage_handle_t const * p_block_handle,
-                                                   dm_handle_t const       * p_handle);
-
-static __INLINE ret_code_t gatts_context_load(pstorage_handle_t const * p_block_handle,
-                                              dm_handle_t const       * p_handle);
-
-static __INLINE ret_code_t gattc_context_load(pstorage_handle_t const * p_block_handle,
-                                              dm_handle_t const       * p_handle);
-
-static __INLINE ret_code_t gattsc_context_load(pstorage_handle_t const * p_block_handle,
-                                               dm_handle_t const       * p_handle);
-
-static __INLINE ret_code_t no_service_context_apply(dm_handle_t * p_handle);
-
-static __INLINE ret_code_t gatts_context_apply(dm_handle_t * p_handle);
-
-static __INLINE ret_code_t gattc_context_apply(dm_handle_t * p_handle);
-
-static __INLINE ret_code_t gattsc_context_apply(dm_handle_t * p_handle);
-
-
-/**< Array of function pointers based on the types of service registered. */
-const service_context_access_t m_service_context_store[DM_SERVICE_CONTEXT_COUNT] =
-{
-    no_service_context_store, /**< Dummy function, when there is no service context registered. */
-    gatts_context_store,      /**< GATT Server context store function. */
-    gattc_context_store,      /**< GATT Client context store function. */
-    gattsc_context_store      /**< GATT Server & Client context store function. */
-};
-
-
-/**< Array of function pointers based on the types of service registered. */
-const service_context_access_t m_service_context_load[DM_SERVICE_CONTEXT_COUNT] =
-{
-    no_service_context_load,  /**< Dummy function, when there is no service context registered. */
-    gatts_context_load,       /**< GATT Server context load function. */
-    gattc_context_load,       /**< GATT Client context load function. */
-    gattsc_context_load       /**< GATT Server & Client context load function. */
-};
-
-
-/**< Array of function pointers based on the types of service registered. */
-const service_context_apply_t m_service_context_apply[DM_SERVICE_CONTEXT_COUNT] =
-{
-    no_service_context_apply, /**< Dummy function, when there is no service context registered. */
-    gatts_context_apply,      /**< GATT Server context apply function. */
-    gattc_context_apply,      /**< GATT Client context apply function. */
-    gattsc_context_apply      /**< GATT Server & Client context apply function. */
-};
-
-
-const uint32_t m_context_init_len = 0xFFFFFFFF; /**< Constant used to update the initial value for context in the flash. */
-
-/**@brief Function for setting update status for the device identified by 'index'.
- *
- * @param[in] index Device identifier.
- */
-static __INLINE void update_status_bit_set(uint32_t index)
-{
-    m_peer_addr_update |= (BIT_0 << index);
-}
-
-
-/**@brief Function for resetting update status for device identified by 'index'.
- *
- * @param[in] index Device identifier.
- */
-static __INLINE void update_status_bit_reset(uint32_t index)
-{
-    m_peer_addr_update &= (~((uint32_t)BIT_0 << index));
-}
-
-
-/**@brief Function for providing update status for the device identified by 'index'.
- *
- * @param[in] index Device identifier.
- *
- * @retval true if the bit is set, false otherwise.
- */
-static __INLINE bool update_status_bit_is_set(uint32_t index)
-{
-    return ((m_peer_addr_update & (BIT_0 << index)) ? true : false);
-}
-
-
-/**@brief Function for initialiasing the application instance identified by 'index'.
- *
- * @param[in] index Device identifier.
- */
-static __INLINE void application_instance_init(uint32_t index)
-{
-    DM_TRC("[DM]: Initializing Application Instance 0x%08X.\r\n", index);
-
-    m_application_table[index].ntf_cb  = NULL;
-    m_application_table[index].state   = 0x00;
-    m_application_table[index].service = 0x00;
-}
-
-
-/**@brief Function for initialiasing the connection instance identified by 'index'.
- *
- * @param[in] index Device identifier.
- */
-static __INLINE void connection_instance_init(uint32_t index)
-{
-    DM_TRC("[DM]: Initializing Connection Instance 0x%08X.\r\n", index);
-    
-    m_connection_table[index].state         = STATE_IDLE;
-    m_connection_table[index].conn_handle   = BLE_CONN_HANDLE_INVALID;
-    m_connection_table[index].bonded_dev_id = DM_INVALID_ID;
-    
-    memset(&m_connection_table[index].peer_addr, 0, sizeof (ble_gap_addr_t));
-}
-
-
-/**@brief Function for initialiasing the peer device instance identified by 'index'.
- *
- * @param[in] index Device identifier.
- */
-static __INLINE void peer_instance_init(uint32_t index)
-{
-    DM_TRC("[DM]: Initializing Peer Instance 0x%08X.\r\n", index);
-    
-    memset(m_peer_table[index].peer_id.id_addr_info.addr, 0, BLE_GAP_ADDR_LEN);
-    memset(m_peer_table[index].peer_id.id_info.irk, 0, BLE_GAP_SEC_KEY_LEN);
-
-    //Initialize the address type to invalid.
-    m_peer_table[index].peer_id.id_addr_info.addr_type = INVALID_ADDR_TYPE;
-
-    //Initialize the identification bit map to unassigned.
-    m_peer_table[index].id_bitmap = UNASSIGNED;
-
-    // Initialize diversifier.
-    m_peer_table[index].ediv      = EDIV_INIT_VAL;
-
-
-    //Reset the status bit.
-    update_status_bit_reset(index);
-
-#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0)
-    //Initialize the application context for bond device.
-    m_app_context_table[index] = NULL;
-#endif //DEVICE_MANAGER_APP_CONTEXT_SIZE
-}
-
-
-/**@brief Function for searching connection instance matching the connection handle and the state
- *        requested.
- *
- * @details Connection handle and state information is used to get a connection instance, it
- *          is possible to ignore the connection handle by using BLE_CONN_HANDLE_INVALID.
- *
- * @param[in]  conn_handle Connection handle.
- * @param[in]  state       Connection instance state.
- * @param[out] p_instance  Connection instance.
- *
- * @retval NRF_SUCCESS             Operation success.
- * @retval NRF_ERROR_INVALID_STATE Operation failure. Invalid state
- * @retval NRF_ERROR_NOT_FOUND     Operation failure. Not found
- */
-static ret_code_t connection_instance_find(uint16_t   conn_handle,
-                                           uint8_t    state,
-                                           uint32_t * p_instance)
-{
-    ret_code_t err_code;
-    uint32_t   index;
-
-    err_code = NRF_ERROR_INVALID_STATE;
-
-    for (index = 0; index < DEVICE_MANAGER_MAX_CONNECTIONS; index++)
-    {
-        //Search only based on the state.
-        if (state & m_connection_table[index].state)
-        {
-            //Ignore the connection handle.
-            if ((conn_handle == BLE_CONN_HANDLE_INVALID) ||
-                (conn_handle == m_connection_table[index].conn_handle))
-            {
-                //Search for matching connection handle.
-                (*p_instance) = index;
-                err_code      = NRF_SUCCESS;
-
-                break;
-            }
-            else
-            {
-                err_code = NRF_ERROR_NOT_FOUND;
-            }
-        }
-    }
-
-    return err_code;
-}
-
-
-/**@brief Function for allocating device instance for a bonded device.
- *
- * @param[out] p_device_index Device index.
- * @param[in]  p_addr         Peer identification information.
- *
- * @retval NRF_SUCCESS            Operation success.
- * @retval DM_DEVICE_CONTEXT_FULL Operation failure.
- */
-static __INLINE ret_code_t device_instance_allocate(uint8_t *              p_device_index,
-                                                    ble_gap_addr_t const * p_addr)
-{
-    ret_code_t err_code;
-    uint32_t   index;
-
-    err_code = DM_DEVICE_CONTEXT_FULL;
-
-    for (index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++)
-    {
-        DM_TRC("[DM]:[DI 0x%02X]: Device type 0x%02X.\r\n",
-               index, m_peer_table[index].peer_id.id_addr_info.addr_type);
-        DM_TRC("[DM]: Device Addr 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X.\r\n",
-               m_peer_table[index].peer_id.id_addr_info.addr[0],
-               m_peer_table[index].peer_id.id_addr_info.addr[1],
-               m_peer_table[index].peer_id.id_addr_info.addr[2],
-               m_peer_table[index].peer_id.id_addr_info.addr[3],
-               m_peer_table[index].peer_id.id_addr_info.addr[4],
-               m_peer_table[index].peer_id.id_addr_info.addr[5]);
-
-        if (m_peer_table[index].id_bitmap == UNASSIGNED)
-        {
-            if (p_addr->addr_type != BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE)
-            {
-                m_peer_table[index].id_bitmap            &= (~ADDR_ENTRY);
-                m_peer_table[index].peer_id.id_addr_info  = (*p_addr);
-            }
-            else
-            {
-                m_peer_table[index].id_bitmap &= (~IRK_ENTRY);
-            }
-
-            (*p_device_index) = index;
-            err_code          = NRF_SUCCESS;
-
-            DM_LOG("[DM]: Allocated device instance 0x%02X\r\n", index);
-            
-            break;
-        }
-    }
-
-    return err_code;
-}
-
-
-/**@brief Function for freeing a device instance allocated for bonded device.
- *
- * @param[in] device_index Device index.
- *
- * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
- */
-static __INLINE ret_code_t device_instance_free(uint32_t device_index)
-{
-    ret_code_t        err_code;
-    pstorage_handle_t block_handle;
-
-    //Get the block handle.
-    err_code = pstorage_block_identifier_get(&m_storage_handle, device_index, &block_handle);
-
-    if (err_code == NRF_SUCCESS)
-    {
-        DM_TRC("[DM]:[DI 0x%02X]: Freeing Instance.\r\n", device_index);
-
-        //Request clearing of the block.
-        err_code = pstorage_clear(&block_handle, ALL_CONTEXT_SIZE);
-
-        if (err_code == NRF_SUCCESS)
-        {
-            peer_instance_init(device_index);
-        }
-    }
-
-    return err_code;
-}
-
-
-/**@brief Function for searching for the device in the bonded device list.
- *
- * @param[in]  p_addr         Peer identification information.
- * @param[out] p_device_index Device index.
- *
- * @retval NRF_SUCCESS         Operation success.
- * @retval NRF_ERROR_NOT_FOUND Operation failure.
- */
-static ret_code_t device_instance_find(ble_gap_addr_t const * p_addr, uint32_t * p_device_index, uint16_t ediv)
-{
-    ret_code_t err_code;
-    uint32_t   index;
-
-    err_code = NRF_ERROR_NOT_FOUND;
-    
-    DM_TRC("[DM]: Searching for device 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X.\r\n",
-           p_addr->addr[0], 
-           p_addr->addr[1], 
-           p_addr->addr[2], 
-           p_addr->addr[3],
-           p_addr->addr[4], 
-           p_addr->addr[5]);
-
-    for (index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++)
-    {
-        DM_TRC("[DM]:[DI 0x%02X]: Device type 0x%02X.\r\n",
-               index, m_peer_table[index].peer_id.id_addr_info.addr_type);
-        DM_TRC("[DM]: Device Addr 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X.\r\n",
-               m_peer_table[index].peer_id.id_addr_info.addr[0],
-               m_peer_table[index].peer_id.id_addr_info.addr[1],
-               m_peer_table[index].peer_id.id_addr_info.addr[2],
-               m_peer_table[index].peer_id.id_addr_info.addr[3],
-               m_peer_table[index].peer_id.id_addr_info.addr[4],
-               m_peer_table[index].peer_id.id_addr_info.addr[5]);
-
-        if (((NULL == p_addr) && (ediv == m_peer_table[index].ediv)) ||
-            ((NULL != p_addr) && (memcmp(&m_peer_table[index].peer_id.id_addr_info, p_addr, sizeof(ble_gap_addr_t)) == 0)))
-        {
-            DM_LOG("[DM]: Found device at instance 0x%02X\r\n", index);
-
-            (*p_device_index) = index;
-            err_code          = NRF_SUCCESS;
-
-            break;
-        }
-    }
-
-    return err_code;
-}
-
-
-/**@brief Function for notifying connection manager event to the application.
- *
- * @param[in] p_handle     Device handle identifying device.
- * @param[in] p_event      Connection manager event details.
- * @param[in] event_result Event result code.
- */
-static __INLINE void app_evt_notify(dm_handle_t const * const p_handle,
-                                    dm_event_t const * const  p_event,
-                                    uint32_t                  event_result)
-{
-    dm_event_cb_t app_cb = m_application_table[0].ntf_cb;
-
-    DM_MUTEX_UNLOCK();
-
-    DM_TRC("[DM]: Notifying application of event 0x%02X\r\n", p_event->event_id);
-
-    //No need to do any kind of return value processing thus can be supressed.
-    UNUSED_VARIABLE(app_cb(p_handle, p_event, event_result));
-
-    DM_MUTEX_LOCK();
-}
-
-
-/**@brief Function for allocating instance.
- *
- * @details The instance identifier is provided in the 'p_instance' parameter if the routine
- *          succeeds.
- *
- * @param[out] p_instance Connection instance.
- *
- * @retval NRF_SUCCESS      Operation success.
- * @retval NRF_ERROR_NO_MEM Operation failure. No memory.
- */
-static __INLINE uint32_t connection_instance_allocate(uint32_t * p_instance)
-{
-    uint32_t err_code;
-
-    DM_TRC("[DM]: Request to allocation connection instance\r\n");
-
-    err_code = connection_instance_find(BLE_CONN_HANDLE_INVALID, STATE_IDLE, p_instance);
-
-    if (err_code == NRF_SUCCESS)
-    {
-        DM_LOG("[DM]:[%02X]: Connection Instance Allocated.\r\n", (*p_instance));        
-        m_connection_table[*p_instance].state = STATE_CONNECTED;
-    }
-    else
-    {
-        DM_LOG("[DM]: No free connection instances available\r\n");        
-        err_code = NRF_ERROR_NO_MEM;
-    }
-
-    return err_code;
-}
-
-
-/**@brief Function for freeing instance. Instance identifier is provided in the parameter
- *        'p_instance' in case the routine succeeds.
- *
- * @param[in] p_instance Connection instance.
- */
-static __INLINE void connection_instance_free(uint32_t const * p_instance)
-{
-    DM_TRC("[DM]:[CI 0x%02X]: Freeing connection instance\r\n", (*p_instance));
-
-    if (m_connection_table[*p_instance].state != STATE_IDLE)
-    {
-        DM_LOG("[DM]:[%02X]: Freed connection instance.\r\n", (*p_instance));
-        connection_instance_init(*p_instance);
-    }
-}
-
-
-/**@brief Function for storage operation dummy handler.
- *
- * @param[in] p_dest Destination address where data is to be stored persistently.
- * @param[in] p_src  Source address containing data to be stored. API assumes this to be resident
- *                   memory and no intermediate copy of data is made by the API.
- * @param[in] size   Size of data to be stored expressed in bytes. Should be word aligned.
- * @param[in] offset Offset in bytes to be applied when writing to the block.
- *                   For example, if within a block of 100 bytes, application wishes to
- *                   write 20 bytes at offset of 12, then this field should be set to 12.
- *                   Should be word aligned.
- *
- * @retval NRF_SUCCESS Operation success.
- */
-static uint32_t storage_operation_dummy_handler(pstorage_handle_t * p_dest,
-                                                uint8_t           * p_src,
-                                                pstorage_size_t     size,
-                                                pstorage_size_t     offset)
-{
-    return NRF_SUCCESS;
-}
-
-
-/**@brief Function for saving the device context persistently.
- *
- * @param[in] p_handle Device handle identifying device.
- * @param[in] state    Device store state.
- */
-static __INLINE void device_context_store(dm_handle_t const * p_handle, device_store_state_t state)
-{
-    pstorage_handle_t block_handle;
-    storage_operation store_fn;
-    ret_code_t        err_code;
-
-    DM_LOG("[DM]: --> device_context_store\r\n");
-
-    err_code = pstorage_block_identifier_get(&m_storage_handle,
-                                             p_handle->device_id,
-                                             &block_handle);
-
-    if (err_code == NRF_SUCCESS)
-    {
-        if ((STATE_BOND_INFO_UPDATE ==
-             (m_connection_table[p_handle->connection_id].state & STATE_BOND_INFO_UPDATE)) ||
-            (state == UPDATE_PEER_ADDR))
-        {
-            DM_LOG("[DM]:[DI %02X]:[CI %02X]: -> Updating bonding information.\r\n",
-                   p_handle->device_id, p_handle->connection_id);
-
-            store_fn = pstorage_update;
-        }
-        else if (state == FIRST_BOND_STORE)
-        {
-            DM_LOG("[DM]:[DI %02X]:[CI %02X]: -> Storing bonding information.\r\n",
-                   p_handle->device_id, p_handle->connection_id);
-
-            store_fn = pstorage_store;
-        }
-        else
-        {
-            DM_LOG("[DM]:[DI %02X]:[CI %02X]: -> No update in bonding information.\r\n",
-                   p_handle->device_id, p_handle->connection_id);
-
-            //No operation needed.
-            store_fn = storage_operation_dummy_handler;
-        }
-
-        //Store the peer id.
-        err_code = store_fn(&block_handle,
-                            (uint8_t *)&m_peer_table[p_handle->device_id],
-                            PEER_ID_SIZE,
-                            PEER_ID_STORAGE_OFFSET);
-
-        if ((err_code == NRF_SUCCESS) && (state != UPDATE_PEER_ADDR))
-        {
-            m_connection_table[p_handle->connection_id].state &= (~STATE_BOND_INFO_UPDATE);
-
-            //Store the bond information.
-            err_code = store_fn(&block_handle,
-                                (uint8_t *)&m_bond_table[p_handle->connection_id],
-                                BOND_SIZE,
-                                BOND_STORAGE_OFFSET);
-
-            if (err_code != NRF_SUCCESS)
-            {
-                DM_ERR("[DM]:[0x%02X]:Failed to store bond information, reason 0x%08X\r\n",
-                       p_handle->device_id, err_code);
-            }
-        }
-
-        if (state != UPDATE_PEER_ADDR)
-        {
-            //Store the service information
-            err_code = m_service_context_store[m_application_table[p_handle->appl_id].service]
-                    (
-                        &block_handle,
-                        p_handle
-                    );
-
-            if (err_code != NRF_SUCCESS)
-            {
-                //Notify application of an error event.
-                DM_ERR("[DM]: Failed to store service context, reason %08X\r\n", err_code);
-            }
-        }
-    }
-
-    if (err_code != NRF_SUCCESS)
-    {
-        //Notify application of an error event.
-        DM_ERR("[DM]: Failed to store device context, reason %08X\r\n", err_code);
-    }
-}
-
-
-/**@brief Function for storing when there is no service registered.
- *
- * @param[in] p_block_handle Storage block identifier.
- * @param[in] p_handle       Device handle identifying device that is loaded.
- *
- * @retval NRF_SUCCESS
- */
-static __INLINE ret_code_t no_service_context_store(pstorage_handle_t const * p_block_handle,
-                                                    dm_handle_t const       * p_handle)
-{
-    DM_LOG("[DM]: --> no_service_context_store\r\n");
-
-    return NRF_SUCCESS;
-}
-
-
-/**@brief Function for storing GATT Server context.
- *
- * @param[in] p_block_handle Storage block identifier.
- * @param[in] p_handle       Device handle identifying device that is stored.
- *
- * @retval NRF_SUCCESS Operation success.
- */
-static __INLINE ret_code_t gatts_context_store(pstorage_handle_t const * p_block_handle,
-                                               dm_handle_t const       * p_handle)
-{
-    storage_operation store_fn;
-    uint32_t          attr_flags = BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS | BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS;
-    uint16_t          attr_len   = DM_GATT_SERVER_ATTR_MAX_SIZE;
-    uint8_t           sys_data[DM_GATT_SERVER_ATTR_MAX_SIZE];
-
-    DM_LOG("[DM]: --> gatts_context_store\r\n");
-
-    uint32_t err_code = sd_ble_gatts_sys_attr_get(
-        m_connection_table[p_handle->connection_id].conn_handle,
-        sys_data,
-        &attr_len,
-        attr_flags);
-
-    if (err_code == NRF_SUCCESS)
-    {
-        if (memcmp(m_gatts_table[p_handle->connection_id].attributes, sys_data, attr_len) == 0)
-        {
-            //No store operation is needed.
-            DM_LOG("[DM]:[0x%02X]: No change in GATTS Context information.\r\n",
-                   p_handle->device_id);
-
-            if ((m_connection_table[p_handle->connection_id].state & STATE_CONNECTED) !=
-                STATE_CONNECTED)
-            {
-                DM_LOG("[DM]:[0x%02X]: Resetting GATTS for active instance.\r\n",
-                       p_handle->connection_id);
-
-                //Reset GATTS information for the current context.
-                memset(&m_gatts_table[p_handle->connection_id], 0, sizeof(dm_gatts_context_t));
-            }
-        }
-        else
-        {
-            if (m_gatts_table[p_handle->connection_id].size != 0)
-            {
-                //There is data already stored in persistent memory, therefore an update is needed.
-                DM_LOG("[DM]:[0x%02X]: Updating stored service context\r\n", p_handle->device_id);
-
-                store_fn = pstorage_update;
-            }
-            else
-            {
-                //Fresh write, a store is needed.
-                DM_LOG("[DM]:[0x%02X]: Storing service context\r\n", p_handle->device_id);
-
-                store_fn = pstorage_store;
-            }
-
-            m_gatts_table[p_handle->connection_id].flags = attr_flags;
-            m_gatts_table[p_handle->connection_id].size  = attr_len;
-            memcpy(m_gatts_table[p_handle->connection_id].attributes, sys_data, attr_len);
-
-            DM_DUMP((uint8_t *)&m_gatts_table[p_handle->connection_id], sizeof(dm_gatts_context_t));
-
-            DM_LOG("[DM]:[0x%02X]: GATTS Data size 0x%08X\r\n",
-                   p_handle->device_id,
-                   m_gatts_table[p_handle->connection_id].size);
-
-            //Store GATTS information.
-            err_code = store_fn((pstorage_handle_t *)p_block_handle,
-                                (uint8_t *)&m_gatts_table[p_handle->connection_id],
-                                GATTS_SERVICE_CONTEXT_SIZE,
-                                SERVICE_STORAGE_OFFSET);
-
-            if (err_code != NRF_SUCCESS)
-            {
-                DM_ERR("[DM]:[0x%02X]:Failed to store service context, reason 0x%08X\r\n",
-                       p_handle->device_id,
-                       err_code);
-            }
-            else
-            {
-                DM_LOG("[DM]: Service context successfully stored.\r\n");
-            }
-        }
-    }
-
-    return NRF_SUCCESS;
-}
-
-
-/**@brief Function for storing GATT Client context.
- *
- * @param[in] p_block_handle Storage block identifier.
- * @param[in] p_handle       Device handle identifying device that is stored.
- *
- * @retval NRF_SUCCESS Operation success.
- */
-static __INLINE ret_code_t gattc_context_store(pstorage_handle_t const * p_block_handle,
-                                               dm_handle_t const       * p_handle)
-{
-    DM_LOG("[DM]: --> gattc_context_store\r\n");
-
-    return NRF_SUCCESS;
-}
-
-
-/**@brief Function for storing GATT Server & Client context.
- *
- * @param[in] p_block_handle Storage block identifier.
- * @param[in] p_handle       Device handle identifying device that is stored.
- *
- * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
- */
-static __INLINE ret_code_t gattsc_context_store(pstorage_handle_t const * p_block_handle,
-                                                dm_handle_t const       * p_handle)
-{
-    DM_LOG("[DM]: --> gattsc_context_store\r\n");
-
-    ret_code_t err_code = gatts_context_store(p_block_handle, p_handle);
-
-    if (NRF_SUCCESS == err_code)
-    {
-        err_code = gattc_context_store(p_block_handle, p_handle);
-    }
-
-    return err_code;
-}
-
-
-/**@brief Function for loading when there is no service registered.
- *
- * @param[in] p_block_handle Storage block identifier.
- * @param[in] p_handle       Device handle identifying device that is loaded.
- *
- * @retval NRF_SUCCESS
- */
-static __INLINE ret_code_t no_service_context_load(pstorage_handle_t const * p_block_handle,
-                                                   dm_handle_t const       * p_handle)
-{
-    DM_LOG("[DM]: --> no_service_context_load\r\n");
-
-    return NRF_SUCCESS;
-}
-
-
-/**@brief Function for loading GATT Server context.
- *
- * @param[in] p_block_handle Storage block identifier.
- * @param[in] p_handle       Device handle identifying device that is loaded.
- *
- * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
- */
-static __INLINE ret_code_t gatts_context_load(pstorage_handle_t const * p_block_handle,
-                                              dm_handle_t const       * p_handle)
-{
-    DM_LOG("[DM]:[CI 0x%02X]:[DI 0x%02X]: --> gatts_context_load\r\n",
-           p_handle->connection_id,
-           p_handle->device_id);
-
-    ret_code_t err_code = pstorage_load((uint8_t *)&m_gatts_table[p_handle->connection_id],
-                                        (pstorage_handle_t *)p_block_handle,
-                                        GATTS_SERVICE_CONTEXT_SIZE,
-                                        SERVICE_STORAGE_OFFSET);
-
-    if (err_code == NRF_SUCCESS)
-    {
-        DM_LOG("[DM]:[%02X]:[Block ID 0x%08X]: Service context loaded, size 0x%08X\r\n",
-               p_handle->connection_id,
-               p_block_handle->block_id,
-               m_gatts_table[p_handle->connection_id].size);
-        DM_DUMP((uint8_t *)&m_gatts_table[p_handle->connection_id], sizeof(dm_gatts_context_t));
-
-        if (m_gatts_table[p_handle->connection_id].size == DM_GATTS_INVALID_SIZE)
-        {
-            m_gatts_table[p_handle->connection_id].size = 0;
-        }
-    }
-    else
-    {
-        DM_ERR("[DM]:[%02X]: Failed to load Service context, reason %08X\r\n",
-               p_handle->connection_id,
-               err_code);
-    }
-
-    return err_code;
-}
-
-
-/**@brief Function for loading GATT Client context.
- *
- * @param[in] p_block_handle Storage block identifier.
- * @param[in] p_handle       Device handle identifying device that is loaded.
- *
- * @retval NRF_SUCCESS
- */
-static __INLINE ret_code_t gattc_context_load(pstorage_handle_t const * p_block_handle,
-                                              dm_handle_t const       * p_handle)
-{
-    DM_LOG("[DM]: --> gattc_context_load\r\n");
-
-    return NRF_SUCCESS;
-}
-
-
-/**@brief Function for loading GATT Server & Client context.
- *
- * @param[in] p_block_handle Storage block identifier.
- * @param[in] p_handle       Device handle identifying device that is loaded.
- *
- * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
- */
-static __INLINE ret_code_t gattsc_context_load(pstorage_handle_t const * p_block_handle,
-                                               dm_handle_t const       * p_handle)
-{
-    DM_LOG("[DM]: --> gattsc_context_load\r\n");
-
-    ret_code_t err_code = gatts_context_load(p_block_handle, p_handle);
-
-    if (NRF_SUCCESS == err_code)
-    {
-        err_code = gattc_context_load(p_block_handle, p_handle);
-    }
-
-    return err_code;
-}
-
-
-/**@brief Function for applying when there is no service registered.
- *
- * @param[in] p_handle Device handle identifying device that is applied.
- *
- * @retval NRF_SUCCESS
- */
-static __INLINE ret_code_t no_service_context_apply(dm_handle_t * p_handle)
-{
-    DM_LOG("[DM]: --> no_service_context_apply\r\n");
-    DM_LOG("[DM]:[CI 0x%02X]: No Service context\r\n", p_handle->connection_id);
-
-    return NRF_SUCCESS;
-}
-
-
-/**@brief Function for applying GATT Server context.
- *
- * @param[in] p_handle Device handle identifying device that is applied.
- *
- * @retval NRF_SUCCESS                    On success.
- * @retval DM_SERVICE_CONTEXT_NOT_APPLIED On failure.
- */
-static __INLINE ret_code_t gatts_context_apply(dm_handle_t * p_handle)
-{
-    uint32_t err_code;
-
-    uint8_t * p_gatts_context = NULL;
-    uint16_t  context_len     = 0;
-    uint32_t  context_flags   = 0;
-
-    DM_LOG("[DM]: --> gatts_context_apply\r\n");
-    DM_LOG("[DM]:[CI 0x%02X]: State 0x%02X, Size 0x%08X\r\n",
-           p_handle->connection_id,
-           m_connection_table[p_handle->connection_id].state,
-           m_gatts_table[p_handle->connection_id].size);
-
-    if ((m_gatts_table[p_handle->connection_id].size != 0) &&
-        (
-            ((m_connection_table[p_handle->connection_id].state & STATE_LINK_ENCRYPTED) == STATE_LINK_ENCRYPTED) &&
-            ((m_connection_table[p_handle->connection_id].state & STATE_BOND_INFO_UPDATE)
-             != STATE_BOND_INFO_UPDATE)
-        )
-       )
-    {
-        DM_LOG("[DM]: Setting stored context.\r\n");
-
-        p_gatts_context = &m_gatts_table[p_handle->connection_id].attributes[0];
-        context_len     = m_gatts_table[p_handle->connection_id].size;
-        context_flags   = m_gatts_table[p_handle->connection_id].flags;
-    }
-
-    err_code = sd_ble_gatts_sys_attr_set(m_connection_table[p_handle->connection_id].conn_handle,
-                                         p_gatts_context,
-                                         context_len,
-                                         context_flags);
-
-    if (err_code == NRF_ERROR_INVALID_DATA)
-    {
-        // Indication that the ATT table has changed. Restore the system attributes to system
-        // services only and send a service changed indication if possible.
-        context_flags = BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS;
-        err_code      = sd_ble_gatts_sys_attr_set(m_connection_table[p_handle->connection_id].conn_handle,
-                                                  p_gatts_context,
-                                                  context_len,
-                                                  context_flags);
-    }
-
-    if (err_code != NRF_SUCCESS)
-    {
-        DM_LOG("[DM]: Failed to set system attributes, reason 0x%08X.\r\n", err_code);
-
-        err_code = DM_SERVICE_CONTEXT_NOT_APPLIED;
-    }
-
-    if (context_flags == BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS)
-    {
-        err_code = sd_ble_gatts_service_changed(m_connection_table[p_handle->connection_id].conn_handle,
-                                                0x000C,
-                                                0xFFFF);
-        if (err_code != NRF_SUCCESS)
-        {
-            DM_LOG("[DM]: Failed to send Service Changed indication, reason 0x%08X.\r\n", err_code);
-            if ((err_code != BLE_ERROR_INVALID_CONN_HANDLE) &&
-                (err_code != NRF_ERROR_INVALID_STATE) &&
-                (err_code != BLE_ERROR_NO_TX_BUFFERS) &&
-                (err_code != NRF_ERROR_BUSY))
-            {
-                // Those errors can be expected when sending trying to send Service Changed
-                // Indication if the CCCD is not set to indicate. Thus set the returning error
-                //  code to success.
-                err_code = NRF_SUCCESS;
-            }
-            else
-            {
-                err_code = DM_SERVICE_CONTEXT_NOT_APPLIED;
-            }
-        }
-    }
-
-    return err_code;
-}
-
-
-/**@brief Function for applying GATT Client context.
- *
- * @param[in] p_handle Device handle identifying device that is applied.
- *
- * @retval NRF_SUCCESS On success.
- */
-static __INLINE ret_code_t gattc_context_apply(dm_handle_t * p_handle)
-{
-    DM_LOG("[DM]: --> gattc_context_apply\r\n");
-
-    return NRF_SUCCESS;
-}
-
-
-/**@brief Function for applying GATT Server & Client context.
- *
- * @param[in] p_handle Device handle identifying device that is applied.
- *
- * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
- */
-static __INLINE ret_code_t gattsc_context_apply(dm_handle_t * p_handle)
-{
-    uint32_t err_code;
-
-    DM_LOG("[DM]: --> gattsc_context_apply\r\n");
-
-    err_code = gatts_context_apply(p_handle);
-
-    if (err_code == NRF_SUCCESS)
-    {
-        err_code = gattc_context_apply(p_handle);
-    }
-
-    return err_code;
-}
-
-
-/**@brief Function for pstorage module callback.
- *
- * @param[in] p_handle Identifies module and block for which callback is received.
- * @param[in] op_code  Identifies the operation for which the event is notified.
- * @param[in] result   Identifies the result of flash access operation.
- *                     NRF_SUCCESS implies, operation succeeded.
- * @param[in] p_data   Identifies the application data pointer. In case of store operation, this
- *                     points to the resident source of application memory that application can now
- *                     free or reuse. In case of clear, this is NULL as no application pointer is
- *                     needed for this operation.
- * @param[in] data_len Length of data provided by the application for the operation.
- */
-static void dm_pstorage_cb_handler(pstorage_handle_t * p_handle,
-                                   uint8_t             op_code,
-                                   uint32_t            result,
-                                   uint8_t           * p_data,
-                                   uint32_t            data_len)
-{
-    VERIFY_APP_REGISTERED_VOID(0);
-
-    if (data_len > ALL_CONTEXT_SIZE)
-    {
-        //Clearing of all bonds at initialization, no event is generated.
-        return;
-    }
-
-    DM_MUTEX_LOCK();
-
-    dm_event_t        dm_event;
-    dm_handle_t       dm_handle;
-    dm_context_t      context_data;
-    pstorage_handle_t block_handle;
-    uint32_t          index_count;
-    uint32_t          err_code;
-
-    bool app_notify = true;
-
-    err_code = dm_handle_initialize(&dm_handle);
-    APP_ERROR_CHECK(err_code);
-
-    dm_handle.appl_id = 0;
-    dm_event.event_id = 0x00;
-
-    //Construct the event which it is related to.
-
-    //Initialize context data information and length.
-    context_data.p_data = p_data;
-    context_data.len    = data_len;
-
-    for (uint32_t index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++)
-    {
-        err_code = pstorage_block_identifier_get(&m_storage_handle, index, &block_handle);
-        if ((err_code == NRF_SUCCESS) &&
-            (
-                (memcmp(p_handle, &block_handle, sizeof(pstorage_handle_t)) == 0)
-            )
-           )
-        {
-            dm_handle.device_id = index;
-            break;
-        }
-    }
-
-    if (dm_handle.device_id != DM_INVALID_ID)
-    {
-        if (op_code == PSTORAGE_CLEAR_OP_CODE)
-        {
-            if (data_len == ALL_CONTEXT_SIZE)
-            {
-                dm_event.event_id = DM_EVT_DEVICE_CONTEXT_BASE;
-            }
-            else
-            {
-                dm_event.event_id = DM_EVT_APP_CONTEXT_BASE;
-            }
-        }
-        else
-        {
-            //Update or store operation.
-            //Context is identified based on the pointer value. Device context, application context
-            //and service context all have their own value range.
-            index_count = ((uint32_t)(p_data - (uint8_t *)m_peer_table)) / PEER_ID_SIZE;
-
-            if (index_count < DEVICE_MANAGER_MAX_BONDS)
-            {
-                dm_event.event_param.p_device_context = &context_data;
-
-                //Only the peer identification is stored, not bond information. Hence do not notify
-                //the application yet, unless the store operation resulted in a failure.
-                if ((result == NRF_SUCCESS) &&
-                    (
-                        (update_status_bit_is_set(dm_handle.device_id) == false)
-                    )
-                   )
-                {
-                    app_notify = false;
-                }
-                else
-                {
-                    //Reset update status since update is complete.
-                    update_status_bit_reset(dm_handle.device_id);
-
-                    //Notify application of error in storing the context.
-                    dm_event.event_id = DM_EVT_DEVICE_CONTEXT_BASE;
-                }
-            }
-            else
-            {
-                index_count = ((uint32_t)(p_data - (uint8_t *)m_bond_table)) / BOND_SIZE;
-
-                if (index_count < DEVICE_MANAGER_MAX_CONNECTIONS)
-                {
-                    DM_LOG("[DM]:[0x%02X]:[0x%02X]: Bond context Event\r\n",
-                           dm_handle.device_id,
-                           dm_handle.connection_id);
-
-                    dm_event.event_param.p_device_context = &context_data;
-                    dm_event.event_id                     = DM_EVT_DEVICE_CONTEXT_BASE;
-                    dm_handle.connection_id               = index_count;
-
-                    ble_gap_sec_keyset_t keys_exchanged;
-                    keys_exchanged.keys_central.p_enc_key = NULL;
-                    keys_exchanged.keys_central.p_id_key  = &m_local_id_info;
-                    keys_exchanged.keys_periph.p_enc_key  = &m_bond_table[index_count].peer_enc_key;
-                    keys_exchanged.keys_periph.p_id_key   =
-                        &m_peer_table[dm_handle.device_id].peer_id;
-
-                    //Context information updated to provide the keys.
-                    context_data.p_data = (uint8_t *)&keys_exchanged;
-                    context_data.len    = sizeof(ble_gap_sec_keyset_t);
-                }
-                else
-                {
-                    index_count = ((uint32_t)(p_data - (uint8_t *)m_gatts_table)) /
-                                  GATTS_SERVICE_CONTEXT_SIZE;
-
-                    if (index_count < DEVICE_MANAGER_MAX_CONNECTIONS)
-                    {
-                        DM_LOG("[DM]:[0x%02X]:[0x%02X]: Service context Event\r\n",
-                               dm_handle.device_id,
-                               dm_handle.connection_id);
-
-                        //Notify application.
-                        dm_event.event_id       = DM_EVT_SERVICE_CONTEXT_BASE;
-                        dm_handle.connection_id = index_count;
-                        dm_handle.service_id    = DM_PROTOCOL_CNTXT_GATT_SRVR_ID;
-
-                        //Reset the service context now that it was successfully written to the
-                        //application and the link is disconnected.
-                        if ((m_connection_table[index_count].state & STATE_CONNECTED) !=
-                            STATE_CONNECTED)
-                        {
-                            DM_LOG("[DM]:[0x%02X]:[0x%02X]: Resetting bond information for "
-                                   "active instance.\r\n",
-                                   dm_handle.device_id,
-                                   dm_handle.connection_id);
-
-                            memset(&m_gatts_table[dm_handle.connection_id],
-                                   0,
-                                   sizeof(dm_gatts_context_t));
-                        }
-                    }
-                    else
-                    {
-                        DM_LOG("[DM]:[0x%02X]:[0x%02X]: App context Event\r\n",
-                               dm_handle.device_id,
-                               dm_handle.connection_id);
-
-                        app_notify        = false;
-                        dm_event.event_id = DM_EVT_APP_CONTEXT_BASE;
-#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0)
-
-                        if (p_data == (uint8_t *)(&m_context_init_len))
-                        {
-                            //Context data is deleted.
-                            //This is a workaround to get the right event as on delete operation
-                            //update operation is used instead of clear.
-                            op_code    = PSTORAGE_CLEAR_OP_CODE;
-                            app_notify = true;
-                        }
-                        else if (m_app_context_table[dm_handle.device_id] == p_data)
-                        {
-                            app_notify                         = true;
-                            dm_event.event_param.p_app_context = &context_data;
-
-                            //Verify if the device is connected, if yes set connection instance.
-                            for (uint32_t index = 0;
-                                 index < DEVICE_MANAGER_MAX_CONNECTIONS;
-                                 index++)
-                            {
-                                if (dm_handle.device_id == m_connection_table[index].bonded_dev_id)
-                                {
-                                    dm_handle.connection_id = index;
-                                    break;
-                                }
-                            }
-                        }
-                        else
-                        {
-                            //No implementation needed.
-                        }
-#endif //DEVICE_MANAGER_APP_CONTEXT_SIZE
-                    }
-                }
-            }
-        }
-
-        if (app_notify == true)
-        {
-            if (op_code == PSTORAGE_CLEAR_OP_CODE)
-            {
-                dm_event.event_id |= DM_CLEAR_OPERATION_ID;
-            }
-            else if (op_code == PSTORAGE_LOAD_OP_CODE)
-            {
-                dm_event.event_id |= DM_LOAD_OPERATION_ID;
-            }
-            else
-            {
-                dm_event.event_id |= DM_STORE_OPERATION_ID;
-            }
-
-            dm_event.event_param.p_app_context = &context_data;
-            app_evt_notify(&dm_handle, &dm_event, result);
-        }
-    }
-
-    DM_MUTEX_UNLOCK();
-}
-
-
-ret_code_t dm_init(dm_init_param_t const * const p_init_param)
-{
-    pstorage_module_param_t param;
-    pstorage_handle_t       block_handle;
-    ret_code_t              err_code;
-    uint32_t                index;
-
-    DM_LOG("[DM]: >> dm_init.\r\n");
-
-    NULL_PARAM_CHECK(p_init_param);
-
-    SDK_MUTEX_INIT(m_dm_mutex);
-
-    DM_MUTEX_LOCK();
-
-    for (index = 0; index < DEVICE_MANAGER_MAX_APPLICATIONS; index++)
-    {
-        application_instance_init(index);
-    }
-
-    for (index = 0; index < DEVICE_MANAGER_MAX_CONNECTIONS; index++)
-    {
-        connection_instance_init(index);
-    }
-
-    memset(m_gatts_table, 0, sizeof(m_gatts_table));
-
-    //Initialization of all device instances.
-    for (index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++)
-    {
-        peer_instance_init(index);
-        m_irk_index_table[index] = DM_INVALID_ID;
-    }
-
-    //All context with respect to a particular device is stored contiguously.
-    param.block_size  = ALL_CONTEXT_SIZE;
-    param.block_count = DEVICE_MANAGER_MAX_BONDS;
-    param.cb          = dm_pstorage_cb_handler;
-
-    err_code = pstorage_register(&param, &m_storage_handle);
-
-    if (err_code == NRF_SUCCESS)
-    {
-        m_module_initialized = true;
-
-        if (p_init_param->clear_persistent_data == false)
-        {
-            DM_LOG("[DM]: Storage handle 0x%08X.\r\n", m_storage_handle.block_id);
-
-            //Copy bonded peer device address and IRK to RAM table.
-
-            //Bonded devices are stored in range (0,DEVICE_MANAGER_MAX_BONDS-1). The remaining
-            //range is for active connections that may or may not be bonded.
-            for (index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++)
-            {
-                err_code = pstorage_block_identifier_get(&m_storage_handle, index, &block_handle);
-
-                //Issue read request if you successfully get the block identifier.
-                if (err_code == NRF_SUCCESS)
-                {
-                    DM_TRC("[DM]:[0x%02X]: Block handle 0x%08X.\r\n", index, block_handle.block_id);
-
-                    err_code = pstorage_load((uint8_t *)&m_peer_table[index],
-                                             &block_handle,
-                                             sizeof(peer_id_t),
-                                             0);
-
-                    if (err_code != NRF_SUCCESS)
-                    {
-                        // In case a peer device could not be loaded successfully, rest of the
-                        // initialization procedure are skipped and an error is sent to the
-                        // application.
-                        DM_ERR(
-                            "[DM]: Failed to load peer device %08X from storage, reason %08X.\r\n",
-                            index,
-                            err_code);
-
-                        m_module_initialized = false;
-                        break;
-                    }
-                    else
-                    {
-                        DM_TRC("[DM]:[DI 0x%02X]: Device type 0x%02X.\r\n",
-                               index,
-                               m_peer_table[index].peer_id.id_addr_info.addr_type);
-                        DM_TRC("[DM]: Device Addr 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X.\r\n",
-                               m_peer_table[index].peer_id.id_addr_info.addr[0],
-                               m_peer_table[index].peer_id.id_addr_info.addr[1],
-                               m_peer_table[index].peer_id.id_addr_info.addr[2],
-                               m_peer_table[index].peer_id.id_addr_info.addr[3],
-                               m_peer_table[index].peer_id.id_addr_info.addr[4],
-                               m_peer_table[index].peer_id.id_addr_info.addr[5]);
-                    }
-                }
-                else
-                {
-                    //In case a peer device could not be loaded successfully, rest of the
-                    //initialization procedure are skipped and an error is sent to the application.
-                    DM_LOG("[DM]: Failed to get block handle for instance %08X, reason %08X.\r\n",
-                           index,
-                           err_code);
-
-                    m_module_initialized = false;
-                    break;
-                }
-            }
-        }
-        else
-        {
-            err_code = pstorage_clear(&m_storage_handle, (param.block_size * param.block_count));
-            DM_ERR("[DM]: Successfully requested clear of persistent data.\r\n");
-        }
-    }
-    else
-    {
-        DM_ERR("[DM]: Failed to register with storage module, reason 0x%08X.\r\n", err_code);
-    }
-
-    DM_MUTEX_UNLOCK();
-
-    DM_TRC("[DM]: << dm_init.\r\n");
-
-    return err_code;
-}
-
-
-ret_code_t dm_register(dm_application_instance_t    * p_appl_instance,
-                       dm_application_param_t const * p_appl_param)
-{
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_appl_instance);
-    NULL_PARAM_CHECK(p_appl_param);
-    NULL_PARAM_CHECK(p_appl_param->evt_handler);
-
-    DM_MUTEX_LOCK();
-
-    DM_LOG("[DM]: >> dm_register.\r\n");
-
-    uint32_t err_code;
-
-    //Verify if an application instance is available. Currently only one instance is supported.
-    if (m_application_table[0].ntf_cb == NULL)
-    {
-        DM_LOG("[DM]: Application Instance allocated.\r\n");
-
-        //Mark instance as allocated.
-        m_application_table[0].ntf_cb    = p_appl_param->evt_handler;
-        m_application_table[0].sec_param = p_appl_param->sec_param;
-        m_application_table[0].service   = p_appl_param->service_type;
-
-        m_application_table[0].sec_param.kdist_central.enc  = 0;
-        m_application_table[0].sec_param.kdist_central.id   = 1;
-        m_application_table[0].sec_param.kdist_central.sign = 0;
-        m_application_table[0].sec_param.kdist_periph.enc   = 1;
-        m_application_table[0].sec_param.kdist_periph.id    = 1;
-        m_application_table[0].sec_param.kdist_periph.sign  = 0;
-        //Populate application's instance variable with the assigned allocation instance.
-        *p_appl_instance = 0;
-        err_code         = NRF_SUCCESS;
-    }
-    else
-    {
-        err_code = (NRF_ERROR_NO_MEM | DEVICE_MANAGER_ERR_BASE);
-    }
-
-    DM_MUTEX_UNLOCK();
-
-    DM_TRC("[DM]: << dm_register.\r\n");
-
-    return err_code;
-}
-
-
-ret_code_t dm_security_setup_req(dm_handle_t * p_handle)
-{
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_handle);
-    VERIFY_APP_REGISTERED(p_handle->appl_id);
-    VERIFY_CONNECTION_INSTANCE(p_handle->connection_id);
-
-    DM_MUTEX_LOCK();
-
-    DM_LOG("[DM]: >> dm_security_setup_req\r\n");
-
-    uint32_t err_code = (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE);
-
-    if ((m_connection_table[p_handle->connection_id].state & STATE_CONNECTED) == STATE_CONNECTED)
-    {
-        err_code = sd_ble_gap_authenticate(m_connection_table[p_handle->connection_id].conn_handle,
-                                           &m_application_table[0].sec_param);
-    }
-
-    DM_TRC("[DM]: << dm_security_setup_req, 0x%08X\r\n", err_code);
-
-    DM_MUTEX_UNLOCK();
-
-    return err_code;
-}
-
-
-ret_code_t dm_security_status_req(dm_handle_t const    * p_handle,
-                                  dm_security_status_t * p_status)
-{
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_handle);
-    NULL_PARAM_CHECK(p_status);
-    VERIFY_APP_REGISTERED(p_handle->appl_id);
-    VERIFY_CONNECTION_INSTANCE(p_handle->connection_id);
-
-    DM_MUTEX_LOCK();
-
-    DM_LOG("[DM]: >> dm_security_status_req\r\n");
-
-    if ((m_connection_table[p_handle->connection_id].state & STATE_PAIRING) ||
-        (m_connection_table[p_handle->connection_id].state & STATE_PAIRING_PENDING))
-    {
-        (*p_status) = ENCRYPTION_IN_PROGRESS;
-    }
-    else if (m_connection_table[p_handle->connection_id].state & STATE_LINK_ENCRYPTED)
-    {
-        (*p_status) = ENCRYPTED;
-    }
-    else
-    {
-        (*p_status) = NOT_ENCRYPTED;
-    }
-
-    DM_TRC("[DM]: << dm_security_status_req\r\n");
-
-    DM_MUTEX_UNLOCK();
-
-    return NRF_SUCCESS;
-}
-
-
-ret_code_t dm_whitelist_create(dm_application_instance_t const * p_handle,
-                               ble_gap_whitelist_t             * p_whitelist)
-{
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_handle);
-    NULL_PARAM_CHECK(p_whitelist);
-    NULL_PARAM_CHECK(p_whitelist->pp_addrs);
-    NULL_PARAM_CHECK(p_whitelist->pp_irks);
-    VERIFY_APP_REGISTERED(*p_handle);
-
-    DM_MUTEX_LOCK();
-
-    DM_LOG("[DM]: >> dm_whitelist_create\r\n");
-
-    uint32_t addr_count = 0;
-    uint32_t irk_count  = 0;
-    bool     connected  = false;
-
-    for (uint32_t index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++)
-    {
-        connected = false;
-
-        for (uint32_t c_index = 0; c_index < DEVICE_MANAGER_MAX_CONNECTIONS; c_index++)
-        {
-            if ((index == m_connection_table[c_index].bonded_dev_id) &&
-                ((m_connection_table[c_index].state & STATE_CONNECTED) == STATE_CONNECTED))
-            {
-                connected = true;
-                break;
-            }
-        }
-
-        if (connected == false)
-        {
-            if ((irk_count < p_whitelist->irk_count) &&
-                ((m_peer_table[index].id_bitmap & IRK_ENTRY) == 0))
-            {
-                p_whitelist->pp_irks[irk_count] = &m_peer_table[index].peer_id.id_info;
-                m_irk_index_table[irk_count]    = index;
-                irk_count++;
-            }
-
-            if ((addr_count < p_whitelist->addr_count) &&
-                (m_peer_table[index].id_bitmap & ADDR_ENTRY) == 0)
-            {
-                p_whitelist->pp_addrs[addr_count] = &m_peer_table[index].peer_id.id_addr_info;
-                addr_count++;
-            }
-        }
-    }
-
-    p_whitelist->addr_count = addr_count;
-    p_whitelist->irk_count  = irk_count;
-
-    DM_LOG("[DM]: Created whitelist, number of IRK = 0x%02X, number of addr = 0x%02X\r\n",
-           irk_count,
-           addr_count);
-
-    DM_TRC("[DM]: << dm_whitelist_create\r\n");
-
-    DM_MUTEX_UNLOCK();
-
-    return NRF_SUCCESS;
-}
-
-
-ret_code_t dm_device_add(dm_handle_t               * p_handle,
-                         dm_device_context_t const * p_context)
-{
-    return (API_NOT_IMPLEMENTED | DEVICE_MANAGER_ERR_BASE);
-}
-
-
-ret_code_t dm_device_delete(dm_handle_t const * p_handle)
-{
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_handle);
-    VERIFY_APP_REGISTERED(p_handle->appl_id);
-    VERIFY_DEVICE_INSTANCE(p_handle->device_id);
-
-    DM_MUTEX_LOCK();
-
-    DM_TRC("[DM]: >> dm_device_delete\r\n");
-
-    uint32_t err_code = device_instance_free(p_handle->device_id);
-
-    DM_TRC("[DM]: << dm_device_delete\r\n");
-
-    DM_MUTEX_UNLOCK();
-
-    return err_code;
-}
-
-
-ret_code_t dm_device_delete_all(dm_application_instance_t const * p_handle)
-{
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_handle);
-    VERIFY_APP_REGISTERED((*p_handle));
-
-    DM_MUTEX_LOCK();
-
-    uint32_t err_code = NRF_SUCCESS;
-
-    DM_TRC("[DM]: >> dm_device_delete_all\r\n");
-
-    for (uint32_t index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++)
-    {
-        if (m_peer_table[index].id_bitmap != UNASSIGNED)
-        {
-            err_code = device_instance_free(index);
-        }
-    }
-
-    DM_TRC("[DM]: << dm_device_delete_all\r\n");
-
-    DM_MUTEX_UNLOCK();
-
-    return err_code;
-}
-
-
-ret_code_t dm_service_context_set(dm_handle_t const          * p_handle,
-                                  dm_service_context_t const * p_context)
-{
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_handle);
-    NULL_PARAM_CHECK(p_context);
-    VERIFY_APP_REGISTERED(p_handle->appl_id);
-    VERIFY_CONNECTION_INSTANCE(p_handle->connection_id);
-    VERIFY_DEVICE_INSTANCE(p_handle->device_id);
-
-    DM_MUTEX_LOCK();
-
-    DM_TRC("[DM]: >> dm_service_context_set\r\n");
-
-    if ((p_context->context_data.p_data != NULL) &&
-        (
-            (p_context->context_data.len != 0) &&
-            (p_context->context_data.len < DM_GATT_SERVER_ATTR_MAX_SIZE)
-        )
-       )
-    {
-        if (p_context->service_type == DM_PROTOCOL_CNTXT_GATT_SRVR_ID)
-        {
-            memcpy(m_gatts_table[p_handle->connection_id].attributes,
-                   p_context->context_data.p_data,
-                   p_context->context_data.len);
-        }
-    }
-
-    pstorage_handle_t block_handle;
-    uint32_t          err_code = pstorage_block_identifier_get(&m_storage_handle,
-                                                               p_handle->device_id,
-                                                               &block_handle);
-
-    err_code = m_service_context_store[p_context->service_type](&block_handle, p_handle);
-
-    DM_TRC("[DM]: << dm_service_context_set\r\n");
-
-    DM_MUTEX_UNLOCK();
-
-    return err_code;
-}
-
-
-ret_code_t dm_service_context_get(dm_handle_t const    * p_handle,
-                                  dm_service_context_t * p_context)
-{
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_handle);
-    NULL_PARAM_CHECK(p_context);
-    VERIFY_APP_REGISTERED(p_handle->appl_id);
-    VERIFY_DEVICE_INSTANCE(p_handle->device_id);
-
-    if ((m_connection_table[p_handle->connection_id].state & STATE_CONNECTED) != STATE_CONNECTED)
-    {
-        DM_TRC("[DM]: Device must be connected to get context. \r\n");
-
-        return (FEATURE_NOT_ENABLED | DEVICE_MANAGER_ERR_BASE);
-    }
-
-    DM_MUTEX_LOCK();
-
-    DM_TRC("[DM]: >> dm_service_context_get\r\n");
-
-    if ((p_context->context_data.p_data == NULL) &&
-        (p_context->context_data.len < DM_GATT_SERVER_ATTR_MAX_SIZE))
-    {
-        if (p_context->service_type == DM_PROTOCOL_CNTXT_GATT_SRVR_ID)
-        {
-            p_context->context_data.p_data = m_gatts_table[p_handle->connection_id].attributes;
-            p_context->context_data.len    = m_gatts_table[p_handle->connection_id].size;
-        }
-    }
-
-    pstorage_handle_t block_handle;
-    uint32_t          err_code = pstorage_block_identifier_get(&m_storage_handle,
-                                                               p_handle->device_id,
-                                                               &block_handle);
-
-    err_code = m_service_context_load[p_context->service_type](&block_handle, p_handle);
-
-    DM_TRC("[DM]: << dm_service_context_get\r\n");
-
-    DM_MUTEX_UNLOCK();
-
-    return err_code;
-}
-
-
-ret_code_t dm_service_context_delete(dm_handle_t const * p_handle)
-{
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_handle);
-    VERIFY_APP_REGISTERED(p_handle->appl_id);
-    VERIFY_DEVICE_INSTANCE(p_handle->device_id);
-
-    DM_LOG("[DM]: Context delete is not supported yet.\r\n");
-
-    return (API_NOT_IMPLEMENTED | DEVICE_MANAGER_ERR_BASE);
-}
-
-
-ret_code_t dm_application_context_set(dm_handle_t const              * p_handle,
-                                      dm_application_context_t const * p_context)
-{
-#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0)
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_handle);
-    NULL_PARAM_CHECK(p_context);
-    NULL_PARAM_CHECK(p_context->p_data);
-    VERIFY_APP_REGISTERED(p_handle->appl_id);
-    VERIFY_DEVICE_INSTANCE(p_handle->device_id);
-    VERIFY_DEVICE_BOND(p_handle->connection_id);
-    SIZE_CHECK_APP_CONTEXT(p_context->len);
-
-    DM_MUTEX_LOCK();
-
-    DM_TRC("[DM]: >> dm_application_context_set\r\n");
-
-    uint32_t          err_code;
-    uint32_t          context_len;
-    pstorage_handle_t block_handle;
-
-    storage_operation store_fn = pstorage_store;
-
-    err_code = pstorage_block_identifier_get(&m_storage_handle,
-                                             p_handle->device_id,
-                                             &block_handle);
-
-    if (err_code == NRF_SUCCESS)
-    {
-        err_code = pstorage_load((uint8_t *)&context_len,
-                                 &block_handle,
-                                 sizeof(uint32_t),
-                                 APP_CONTEXT_STORAGE_OFFSET);
-
-        if ((err_code == NRF_SUCCESS) && (context_len != INVALID_CONTEXT_LEN))
-        {
-            //Data already exists. Need an update.
-            store_fn = pstorage_update;
-
-            DM_LOG("[DM]:[DI 0x%02X]: Updating existing application context, existing len 0x%08X, "
-                   "new length 0x%08X.\r\n",
-                   p_handle->device_id,
-                   context_len,
-                   p_context->len);
-        }
-        else
-        {
-            DM_LOG("[DM]: Storing application context.\r\n");
-        }
-
-        //Store/update context length.
-        err_code = store_fn(&block_handle,
-                            (uint8_t *)(&p_context->len),
-                            sizeof(uint32_t),
-                            APP_CONTEXT_STORAGE_OFFSET);
-
-        if (err_code == NRF_SUCCESS)
-        {
-            //Update context data is used for application context as flash is never
-            //cleared if a delete of application context is called.
-            err_code = pstorage_update(&block_handle,
-                                       p_context->p_data,
-                                       DEVICE_MANAGER_APP_CONTEXT_SIZE,
-                                       (APP_CONTEXT_STORAGE_OFFSET + sizeof(uint32_t)));
-            if (err_code == NRF_SUCCESS)
-            {
-                m_app_context_table[p_handle->device_id] = p_context->p_data;
-            }
-        }
-    }
-
-    DM_TRC("[DM]: << dm_application_context_set\r\n");
-
-    DM_MUTEX_UNLOCK();
-
-    return err_code;
-
-#else //DEVICE_MANAGER_APP_CONTEXT_SIZE
-    return (FEATURE_NOT_ENABLED | DEVICE_MANAGER_ERR_BASE);
-#endif //DEVICE_MANAGER_APP_CONTEXT_SIZE
-}
-
-
-ret_code_t dm_application_context_get(dm_handle_t const        * p_handle,
-                                      dm_application_context_t * p_context)
-{
-#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0)
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_handle);
-    NULL_PARAM_CHECK(p_context);
-    VERIFY_APP_REGISTERED(p_handle->appl_id);
-    VERIFY_DEVICE_INSTANCE(p_handle->device_id);
-
-    DM_MUTEX_LOCK();
-
-    DM_TRC("[DM]: >> dm_application_context_get\r\n");
-
-    uint32_t          context_len;
-    uint32_t          err_code;
-    pstorage_handle_t block_handle;
-
-    //Check if the context exists.
-    if (NULL == p_context->p_data)
-    {
-        p_context->p_data = m_app_context_table[p_handle->device_id];
-    }
-    else
-    {
-        m_app_context_table[p_handle->device_id] = p_context->p_data;
-    }
-
-    err_code = pstorage_block_identifier_get(&m_storage_handle,
-                                             p_handle->device_id,
-                                             &block_handle);
-
-    if (err_code == NRF_SUCCESS)
-    {
-        err_code = pstorage_load((uint8_t *)&context_len,
-                                 &block_handle,
-                                 sizeof(uint32_t),
-                                 APP_CONTEXT_STORAGE_OFFSET);
-
-        if ((err_code == NRF_SUCCESS) && (context_len != INVALID_CONTEXT_LEN))
-        {
-            err_code = pstorage_load(p_context->p_data,
-                                     &block_handle,
-                                     DEVICE_MANAGER_APP_CONTEXT_SIZE,
-                                     (APP_CONTEXT_STORAGE_OFFSET + sizeof(uint32_t)));
-            if (err_code == NRF_SUCCESS)
-            {
-                p_context->len = context_len;
-            }
-        }
-        else
-        {
-            err_code = DM_NO_APP_CONTEXT;
-        }
-    }
-
-    DM_TRC("[DM]: << dm_application_context_get\r\n");
-
-    DM_MUTEX_UNLOCK();
-
-    return err_code;
-
-#else //DEVICE_MANAGER_APP_CONTEXT_SIZE
-    return (FEATURE_NOT_ENABLED | DEVICE_MANAGER_ERR_BASE);
-#endif //DEVICE_MANAGER_APP_CONTEXT_SIZE
-}
-
-
-ret_code_t dm_application_context_delete(const dm_handle_t * p_handle)
-{
-#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0)
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_handle);
-    VERIFY_APP_REGISTERED(p_handle->appl_id);
-    VERIFY_DEVICE_INSTANCE(p_handle->device_id);
-
-    DM_MUTEX_LOCK();
-
-    DM_TRC("[DM]: >> dm_application_context_delete\r\n");
-
-    uint32_t          err_code;
-    uint32_t          context_len;
-    pstorage_handle_t block_handle;
-
-    err_code = pstorage_block_identifier_get(&m_storage_handle,
-                                             p_handle->device_id,
-                                             &block_handle);
-
-    if (err_code == NRF_SUCCESS)
-    {
-        err_code = pstorage_load((uint8_t *)&context_len,
-                                 &block_handle,
-                                 sizeof(uint32_t),
-                                 APP_CONTEXT_STORAGE_OFFSET);
-
-        if (context_len != m_context_init_len)
-        {
-            err_code = pstorage_update(&block_handle,
-                                       (uint8_t *)&m_context_init_len,
-                                       sizeof(uint32_t),
-                                       APP_CONTEXT_STORAGE_OFFSET);
-
-            if (err_code != NRF_SUCCESS)
-            {
-                DM_ERR("[DM]: Failed to delete application context, reason 0x%08X\r\n", err_code);
-            }
-            else
-            {
-                m_app_context_table[p_handle->device_id] = NULL;
-            }
-        }
-    }
-
-    DM_TRC("[DM]: << dm_application_context_delete\r\n");
-
-    DM_MUTEX_UNLOCK();
-
-    return err_code;
-#else //DEVICE_MANAGER_APP_CONTEXT_SIZE
-    return (FEATURE_NOT_ENABLED | DEVICE_MANAGER_ERR_BASE);
-#endif //DEVICE_MANAGER_APP_CONTEXT_SIZE
-}
-
-
-ret_code_t dm_application_instance_set(dm_application_instance_t const * p_appl_instance,
-                                       dm_handle_t                     * p_handle)
-{
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_handle);
-    NULL_PARAM_CHECK(p_appl_instance);
-    VERIFY_APP_REGISTERED((*p_appl_instance));
-
-    p_handle->appl_id = (*p_appl_instance);
-
-    return NRF_SUCCESS;
-}
-
-
-uint32_t dm_handle_initialize(dm_handle_t * p_handle)
-{
-    NULL_PARAM_CHECK(p_handle);
-
-    p_handle->appl_id       = DM_INVALID_ID;
-    p_handle->connection_id = DM_INVALID_ID;
-    p_handle->device_id     = DM_INVALID_ID;
-    p_handle->service_id    = DM_INVALID_ID;
-
-    return NRF_SUCCESS;
-}
-
-
-ret_code_t dm_peer_addr_set(dm_handle_t const    * p_handle,
-                            ble_gap_addr_t const * p_addr)
-{
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_handle);
-    NULL_PARAM_CHECK(p_addr);
-    VERIFY_APP_REGISTERED(p_handle->appl_id);
-    VERIFY_DEVICE_INSTANCE(p_handle->device_id);
-
-    DM_MUTEX_LOCK();
-
-    DM_TRC("[DM]: >> dm_peer_addr_set\r\n");
-
-    ret_code_t err_code;
-
-    if ((p_handle->connection_id == DM_INVALID_ID) &&
-        (p_addr->addr_type != BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE))
-    {
-        m_peer_table[p_handle->device_id].peer_id.id_addr_info = (*p_addr);
-        update_status_bit_set(p_handle->device_id);
-        device_context_store(p_handle, UPDATE_PEER_ADDR);
-        err_code = NRF_SUCCESS;
-    }
-    else
-    {
-        err_code = (NRF_ERROR_INVALID_PARAM | DEVICE_MANAGER_ERR_BASE);
-    }
-
-    DM_TRC("[DM]: << dm_peer_addr_set\r\n");
-
-    DM_MUTEX_UNLOCK();
-
-    return err_code;
-}
-
-
-ret_code_t dm_peer_addr_get(dm_handle_t const * p_handle,
-                            ble_gap_addr_t    * p_addr)
-{
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_handle);
-    NULL_PARAM_CHECK(p_addr);
-    VERIFY_APP_REGISTERED(p_handle->appl_id);
-
-    DM_MUTEX_LOCK();
-
-    DM_TRC("[DM]: >> dm_peer_addr_get\r\n");
-
-    ret_code_t err_code;
-
-    err_code = (NRF_ERROR_NOT_FOUND | DEVICE_MANAGER_ERR_BASE);
-
-    if (p_handle->device_id == DM_INVALID_ID)
-    {
-        if ((p_handle->connection_id != DM_INVALID_ID) &&
-            ((m_connection_table[p_handle->connection_id].state & STATE_CONNECTED) ==
-             STATE_CONNECTED))
-        {
-            DM_TRC("[DM]:[CI 0x%02X]: Address get for non bonded active connection.\r\n",
-                   p_handle->connection_id);
-
-            (*p_addr) = m_connection_table[p_handle->connection_id].peer_addr;
-            err_code  = NRF_SUCCESS;
-        }
-    }
-    else
-    {
-        if ((m_peer_table[p_handle->device_id].id_bitmap & ADDR_ENTRY) == 0)
-        {
-            DM_TRC("[DM]:[DI 0x%02X]: Address get for bonded device.\r\n",
-                   p_handle->device_id);
-
-            (*p_addr) = m_peer_table[p_handle->device_id].peer_id.id_addr_info;
-            err_code  = NRF_SUCCESS;
-        }
-    }
-
-    DM_TRC("[DM]: << dm_peer_addr_get\r\n");
-
-    DM_MUTEX_UNLOCK();
-
-    return err_code;
-}
-
-
-ret_code_t dm_distributed_keys_get(dm_handle_t const * p_handle,
-                                   dm_sec_keyset_t   * p_key_dist)
-{
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_handle);
-    NULL_PARAM_CHECK(p_key_dist);
-    VERIFY_APP_REGISTERED(p_handle->appl_id);
-    VERIFY_DEVICE_INSTANCE(p_handle->device_id);
-
-    DM_MUTEX_LOCK();
-
-    DM_TRC("[DM]: >> dm_distributed_keys_get\r\n");
-
-    ret_code_t        err_code;
-    ble_gap_enc_key_t peer_enc_key;
-    pstorage_handle_t block_handle;
-
-    err_code                                   = NRF_ERROR_NOT_FOUND;
-    p_key_dist->keys_central.enc_key.p_enc_key = NULL;
-    p_key_dist->keys_central.p_id_key          = (dm_id_key_t *)&m_peer_table[p_handle->device_id].peer_id;
-    p_key_dist->keys_central.p_sign_key        = NULL;
-    p_key_dist->keys_periph.p_id_key           = (dm_id_key_t *)&m_local_id_info;
-    p_key_dist->keys_periph.p_sign_key         = NULL;
-    p_key_dist->keys_periph.enc_key.p_enc_key  = (dm_enc_key_t *)&peer_enc_key;
-
-    if ((m_peer_table[p_handle->device_id].id_bitmap & IRK_ENTRY) == 0)
-    {
-//        p_key_dist->keys_periph.p_id_key->id_addr_info.addr_type = INVALID_ADDR_TYPE;
-    }
-
-    err_code = pstorage_block_identifier_get(&m_storage_handle, p_handle->device_id, &block_handle);
-    if (err_code == NRF_SUCCESS)
-    {
-
-        err_code = pstorage_load((uint8_t *)&peer_enc_key,
-                                 &block_handle,
-                                 BOND_SIZE,
-                                 BOND_STORAGE_OFFSET);
-
-        if (err_code == NRF_SUCCESS)
-        {
-            p_key_dist->keys_central.enc_key.p_enc_key = NULL;
-            p_key_dist->keys_central.p_id_key          = (dm_id_key_t *)&m_peer_table[p_handle->device_id].peer_id;
-            p_key_dist->keys_central.p_sign_key        = NULL;
-            p_key_dist->keys_periph.p_id_key           = (dm_id_key_t *)&m_local_id_info;
-            p_key_dist->keys_periph.p_sign_key         = NULL;
-            p_key_dist->keys_periph.enc_key.p_enc_key  = (dm_enc_key_t *)&peer_enc_key;
-        }
-    }
-
-    DM_TRC("[DM]: << dm_distributed_keys_get\r\n");
-
-    DM_MUTEX_UNLOCK();
-
-    return err_code;
-}
-
-
-/**@brief Function for loading bond information for a connection instance.
- */
-void bond_data_load(dm_handle_t * p_handle)
-{
-    pstorage_handle_t block_handle;
-
-    uint32_t err_code = pstorage_block_identifier_get(&m_storage_handle,
-                                                       p_handle->device_id,
-                                                       &block_handle);
-    if (err_code == NRF_SUCCESS)
-    {
-        DM_LOG(
-            "[DM]:[%02X]:[Block ID 0x%08X]:Loading bond information at %p, size 0x%08X, offset 0x%08X.\r\n",
-            p_handle->connection_id,
-            block_handle.block_id,
-            &m_bond_table[p_handle->connection_id],
-            BOND_SIZE,
-            BOND_STORAGE_OFFSET);
-
-        err_code = pstorage_load((uint8_t *)&m_bond_table[p_handle->connection_id],
-                                 &block_handle,
-                                 BOND_SIZE,
-                                 BOND_STORAGE_OFFSET);
-
-        if (err_code != NRF_SUCCESS)
-        {
-            DM_ERR("[DM]:[%02X]: Failed to load Bond information, reason %08X\r\n",
-                   p_handle->connection_id,
-                   err_code);
-        }
-
-        DM_LOG(
-            "[DM]:[%02X]:Loading service context at %p, size 0x%08X, offset 0x%08X.\r\n",
-            p_handle->connection_id,
-            &m_gatts_table[p_handle->connection_id],
-            sizeof(dm_gatts_context_t),
-            SERVICE_STORAGE_OFFSET);
-
-        err_code = m_service_context_load[m_application_table[0].service](
-            &block_handle,
-            p_handle);
-
-        if (err_code != NRF_SUCCESS)
-        {
-            DM_ERR(
-                "[DM]:[%02X]: Failed to load service information, reason %08X\r\n",
-                p_handle->connection_id,
-                err_code);
-        }
-    }
-    else
-    {
-        DM_ERR("[DM]:[%02X]: Failed to get block identifier for "
-               "device %08X, reason %08X.\r\n", p_handle->connection_id, p_handle->device_id, err_code);
-    }
-}
-
-
-void dm_ble_evt_handler(ble_evt_t * p_ble_evt)
-{
-    uint32_t    err_code;
-    uint32_t    index;
-    uint32_t    device_index        = DM_INVALID_ID;
-    bool        notify_app          = false;
-    dm_handle_t handle;
-    dm_event_t  event;
-    uint32_t    event_result;
-    ble_gap_enc_info_t * p_enc_info = NULL;
-
-    VERIFY_MODULE_INITIALIZED_VOID();
-    VERIFY_APP_REGISTERED_VOID(0);
-    DM_MUTEX_LOCK();
-
-    err_code = dm_handle_initialize(&handle);
-    APP_ERROR_CHECK(err_code);
-
-    event_result                    = NRF_SUCCESS;
-    err_code                        = NRF_SUCCESS;
-    event.event_param.p_gap_param   = &p_ble_evt->evt.gap_evt;
-    event.event_paramlen            = sizeof(ble_gap_evt_t);
-    handle.device_id                = DM_INVALID_ID;
-    handle.appl_id                  = 0;
-    index                           = 0x00;
-
-    if (p_ble_evt->header.evt_id != BLE_GAP_EVT_CONNECTED)
-    {
-        err_code = connection_instance_find(p_ble_evt->evt.gap_evt.conn_handle,
-                                            STATE_CONNECTED,
-                                            &index);
-
-        if (err_code == NRF_SUCCESS)
-        {
-            handle.device_id     = m_connection_table[index].bonded_dev_id;
-            handle.connection_id = index;
-        }
-    }
-
-    switch (p_ble_evt->header.evt_id)
-    {
-        case BLE_GAP_EVT_CONNECTED:
-            //Allocate connection instance for a new connection.
-            err_code = connection_instance_allocate(&index);
-
-            //Connection instance is successfully allocated.
-            if (err_code == NRF_SUCCESS)
-            {
-                //Application notification related information.
-                notify_app           = true;
-                event.event_id       = DM_EVT_CONNECTION;
-                handle.connection_id = index;
-
-                m_connection_table[index].conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
-                m_connection_table[index].state       = STATE_CONNECTED;
-                m_connection_table[index].peer_addr   =
-                    p_ble_evt->evt.gap_evt.params.connected.peer_addr;
-
-                if (p_ble_evt->evt.gap_evt.params.connected.irk_match == 1)
-                {
-                    if (m_irk_index_table[p_ble_evt->evt.gap_evt.params.connected.irk_match_idx] != DM_INVALID_ID)
-                    {
-                        device_index = m_irk_index_table[p_ble_evt->evt.gap_evt.params.connected.irk_match_idx];
-                        err_code = NRF_SUCCESS;
-                    }
-                }
-                else
-                {
-                    //Use the device address to check if the device exists in the bonded device list.
-                    err_code = device_instance_find(&p_ble_evt->evt.gap_evt.params.connected.peer_addr,
-                                                    &device_index, EDIV_INIT_VAL);
-                }
-
-                if (err_code == NRF_SUCCESS)
-                {
-                    m_connection_table[index].bonded_dev_id = device_index;
-                    m_connection_table[index].state        |= STATE_BONDED;
-                    handle.device_id                        = device_index;
-
-                    bond_data_load(&handle);
-                }
-            }
-            break;
-
-        case BLE_GAP_EVT_DISCONNECTED:
-            //Disconnection could be peer or self initiated hence disconnecting and connecting
-            //both states are permitted, however, connection handle must be known.
-            DM_LOG("[DM]: Disconnect Reason 0x%04X\r\n",
-                   p_ble_evt->evt.gap_evt.params.disconnected.reason);
-
-            m_connection_table[index].state &= (~STATE_CONNECTED);
-
-            if ((m_connection_table[index].state & STATE_BONDED) == STATE_BONDED)
-            {
-                if ((m_connection_table[index].state & STATE_LINK_ENCRYPTED) == STATE_LINK_ENCRYPTED)
-                {
-                    //Write bond information persistently.
-                    device_context_store(&handle, STORE_ALL_CONTEXT);
-                }
-            }
-            else
-            {
-                //Free any allocated instances for devices that is not bonded.
-                if (handle.device_id != DM_INVALID_ID)
-                {
-                    peer_instance_init(handle.device_id);
-                    handle.device_id = DM_INVALID_ID;
-                }
-            }
-
-            m_connection_table[index].state = STATE_DISCONNECTING;
-            notify_app                      = true;
-            event.event_id                  = DM_EVT_DISCONNECTION;
-
-            break;
-
-        case BLE_GAP_EVT_SEC_INFO_REQUEST:
-            DM_LOG("[DM]: >> BLE_GAP_EVT_SEC_INFO_REQUEST\r\n");
-
-            //If the device is already bonded, respond with existing info, else NULL.
-            if (m_connection_table[index].bonded_dev_id == DM_INVALID_ID)
-            {
-                //Find device based on div.
-                err_code = device_instance_find(NULL,&device_index, p_ble_evt->evt.gap_evt.params.sec_info_request.master_id.ediv);
-                if (err_code == NRF_SUCCESS)
-                {
-                    //Load needed bonding information.
-                    m_connection_table[index].bonded_dev_id = device_index;
-                    m_connection_table[index].state        |= STATE_BONDED;
-                    handle.device_id                        = device_index;
-                    bond_data_load(&handle);
-                }
-            }
-
-            if (m_connection_table[index].bonded_dev_id != DM_INVALID_ID)
-            {
-                p_enc_info = &m_bond_table[index].peer_enc_key.enc_info;
-                DM_DUMP((uint8_t *)p_enc_info, sizeof(ble_gap_enc_info_t));
-            }
-
-            err_code = sd_ble_gap_sec_info_reply(p_ble_evt->evt.gap_evt.conn_handle,
-                                                 p_enc_info,
-                                                 &m_peer_table[index].peer_id.id_info,
-                                                 NULL);
-
-            if (err_code != NRF_SUCCESS)
-            {
-                DM_ERR("[DM]:[CI %02X]:[DI %02X]: Security information response failed, reason "
-                       "0x%08X\r\n", index, m_connection_table[index].bonded_dev_id, err_code);
-            }
-            break;
-
-        case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
-            DM_LOG("[DM]: >> BLE_GAP_EVT_SEC_PARAMS_REQUEST\r\n");
-
-            event.event_id = DM_EVT_SECURITY_SETUP;
-
-            m_connection_table[index].state |= STATE_PAIRING;
-            notify_app                       = true;
-
-            if (m_connection_table[index].bonded_dev_id == DM_INVALID_ID)
-            {
-                //Assign a peer index as a new bond or update existing bonds.
-                err_code = device_instance_allocate((uint8_t *)&device_index,
-                                                    &m_connection_table[index].peer_addr);
-
-                //Allocation successful.
-                if (err_code == NRF_SUCCESS)
-                {
-                    DM_LOG("[DM]:[CI 0x%02X]:[DI 0x%02X]: Bonded!\r\n",index, device_index);
-
-                    handle.device_id                        = device_index;
-                    m_connection_table[index].bonded_dev_id = device_index;
-                }
-                else
-                {
-                    DM_LOG("[DM]: Security parameter request failed, reason 0x%08X.\r\n", err_code);
-                    event_result = err_code;
-                    notify_app   = true;
-                }
-            }
-            else
-            {
-                //Bond/key refresh.
-                event.event_id = DM_EVT_SECURITY_SETUP_REFRESH;
-                memset(m_gatts_table[index].attributes, 0, DM_GATT_SERVER_ATTR_MAX_SIZE);
-
-                //Set the update flag for bond data.
-                m_connection_table[index].state |= STATE_BOND_INFO_UPDATE;
-            }
-
-            ble_gap_sec_keyset_t keys_exchanged;
-
-            DM_LOG("[DM]: 0x%02X, 0x%02X, 0x%02X, 0x%02X\r\n",
-                   p_ble_evt->evt.gap_evt.params.sec_params_request.peer_params.kdist_periph.enc,
-                   p_ble_evt->evt.gap_evt.params.sec_params_request.peer_params.kdist_central.id,
-                   p_ble_evt->evt.gap_evt.params.sec_params_request.peer_params.kdist_periph.sign,
-                   p_ble_evt->evt.gap_evt.params.sec_params_request.peer_params.bond);
-
-            keys_exchanged.keys_central.p_enc_key  = NULL;
-            keys_exchanged.keys_central.p_id_key   = &m_peer_table[m_connection_table[index].bonded_dev_id].peer_id; 
-            keys_exchanged.keys_central.p_sign_key = NULL;
-            keys_exchanged.keys_periph.p_enc_key   = &m_bond_table[index].peer_enc_key;
-            keys_exchanged.keys_periph.p_id_key    = NULL;
-            keys_exchanged.keys_periph.p_sign_key  = NULL;
-
-            err_code = sd_ble_gap_sec_params_reply(p_ble_evt->evt.gap_evt.conn_handle,
-                                                   BLE_GAP_SEC_STATUS_SUCCESS,
-                                                   &m_application_table[0].sec_param, 
-                                                   &keys_exchanged);
-
-            if (err_code != NRF_SUCCESS)
-            {
-                DM_LOG("[DM]: Security parameter reply request failed, reason 0x%08X.\r\n", err_code);
-                event_result = err_code;
-                notify_app   = false;
-            }
-            break;
-
-        case BLE_GAP_EVT_AUTH_STATUS:
-        {
-            DM_LOG("[DM]: >> BLE_GAP_EVT_AUTH_STATUS, status %08X\r\n",
-                   p_ble_evt->evt.gap_evt.params.auth_status.auth_status);
-
-            m_application_table[0].state    &= (~STATE_CONTROL_PROCEDURE_IN_PROGRESS);
-            m_connection_table[index].state &= (~STATE_PAIRING);
-            event.event_id                   = DM_EVT_SECURITY_SETUP_COMPLETE;
-            notify_app                       = true;
-
-            if (p_ble_evt->evt.gap_evt.params.auth_status.auth_status != BLE_GAP_SEC_STATUS_SUCCESS)
-            {
-                // Free the allocation as bonding failed.
-                ret_code_t result = device_instance_free(m_connection_table[index].bonded_dev_id);
-                (void) result;
-                event_result = p_ble_evt->evt.gap_evt.params.auth_status.auth_status;
-            }
-            else
-            {
-                DM_DUMP((uint8_t *)&p_ble_evt->evt.gap_evt.params.auth_status,
-                        sizeof(ble_gap_evt_auth_status_t));
-                DM_DUMP((uint8_t *)&m_bond_table[index], sizeof(bond_context_t));
-
-                if (p_ble_evt->evt.gap_evt.params.auth_status.bonded == 1)
-                {
-                    if (handle.device_id != DM_INVALID_ID)
-                    {
-                        m_connection_table[index].state |= STATE_BONDED;
-
-                        //IRK and/or public address is shared, update it.
-                        if (p_ble_evt->evt.gap_evt.params.auth_status.kdist_central.id == 1)
-                        {
-                            m_peer_table[handle.device_id].id_bitmap &= (~IRK_ENTRY);
-                        }
-
-                        if (m_connection_table[index].bonded_dev_id != DM_INVALID_ID)
-                        {
-                            DM_LOG("[DM]:[CI 0x%02X]:[DI 0x%02X]: Bonded!\r\n",
-                                   index,
-                                   handle.device_id);
-
-                            if (m_connection_table[index].peer_addr.addr_type !=
-                                BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE)
-                            {
-                               m_peer_table[handle.device_id].peer_id.id_addr_info =
-                                    m_connection_table[index].peer_addr;
-                               m_peer_table[handle.device_id].id_bitmap &= (~ADDR_ENTRY);
-
-                               DM_DUMP((uint8_t *)&m_peer_table[handle.device_id].peer_id.id_addr_info,
-                                       sizeof(m_peer_table[handle.device_id].peer_id.id_addr_info));
-                            }
-                            else
-                            {
-                                // Here we must fetch the keys from the keyset distributed.
-                                m_peer_table[handle.device_id].ediv       = m_bond_table[index].peer_enc_key.master_id.ediv;
-                                m_peer_table[handle.device_id].id_bitmap &= (~IRK_ENTRY);
-                            }
-
-                            device_context_store(&handle, FIRST_BOND_STORE);
-                        }
-                    }
-                }
-                else
-                {
-                    //Pairing request, no need to touch the bonding info.
-                }
-            }
-            break;
-        }
-
-        case BLE_GAP_EVT_CONN_SEC_UPDATE:
-            DM_LOG("[DM]: >> BLE_GAP_EVT_CONN_SEC_UPDATE, Mode 0x%02X, Level 0x%02X\r\n",
-                   p_ble_evt->evt.gap_evt.params.conn_sec_update.conn_sec.sec_mode.sm,
-                   p_ble_evt->evt.gap_evt.params.conn_sec_update.conn_sec.sec_mode.lv);
-
-            if ((p_ble_evt->evt.gap_evt.params.conn_sec_update.conn_sec.sec_mode.lv == 1) &&
-                (p_ble_evt->evt.gap_evt.params.conn_sec_update.conn_sec.sec_mode.sm == 1) &&
-                ((m_connection_table[index].state & STATE_BONDED) == STATE_BONDED))
-            {
-                //Lost bond case, generate a security refresh event!
-                memset(m_gatts_table[index].attributes, 0, DM_GATT_SERVER_ATTR_MAX_SIZE);
-                
-                event.event_id                   = DM_EVT_SECURITY_SETUP_REFRESH;
-                m_connection_table[index].state |= STATE_PAIRING_PENDING;
-                m_connection_table[index].state |= STATE_BOND_INFO_UPDATE;
-                m_application_table[0].state    |= STATE_QUEUED_CONTROL_REQUEST;
-            }
-            else
-            {
-                m_connection_table[index].state |= STATE_LINK_ENCRYPTED;
-                event.event_id                   = DM_EVT_LINK_SECURED;
-
-                //Apply service context.
-                err_code = m_service_context_apply[m_application_table[0].service](&handle);
-
-                if (err_code != NRF_SUCCESS)
-                {
-                    DM_ERR("[DM]:[CI 0x%02X]:[DI 0x%02X]: Failed to apply service context\r\n",
-                            handle.connection_id, 
-                            handle.device_id);
-
-                    event_result = DM_SERVICE_CONTEXT_NOT_APPLIED;
-                }
-            }
-            event_result = NRF_SUCCESS;
-            notify_app   = true;
-            
-            break;
-
-        case BLE_GATTS_EVT_SYS_ATTR_MISSING:
-            DM_LOG("[DM]: >> BLE_GATTS_EVT_SYS_ATTR_MISSING\r\n");
-
-            //Apply service context.
-            event_result = m_service_context_apply[m_application_table[0].service](&handle);
-            break;
-
-        case BLE_GAP_EVT_SEC_REQUEST:
-            DM_LOG("[DM]: >> BLE_GAP_EVT_SEC_REQUEST\r\n");
-            
-            //Verify if the device is already bonded, and if it is bonded, initiate encryption.
-            //If the device is not bonded, an instance needs to be allocated in order to initiate 
-            //bonding. The application have to initiate the procedure, the module will not do this 
-            //automatically.
-            event.event_id = DM_EVT_SECURITY_SETUP;
-            notify_app     = true;
-            
-            break;
-
-        default:
-            break;
-    }
-
-    if (notify_app)
-    {
-        app_evt_notify(&handle, &event, event_result);
-
-        //Freeing the instance after the event is notified so the application can get the context.
-        if (event.event_id == DM_EVT_DISCONNECTION)
-        {
-            //Free the instance.
-            connection_instance_free(&index);
-        }
-    }
-
-    UNUSED_VARIABLE(err_code);
-
-    DM_MUTEX_UNLOCK();
-}
-
-
-ret_code_t dm_handle_get(uint16_t conn_handle, dm_handle_t * p_handle)
-{
-    ret_code_t err_code;
-    uint32_t   index;
-
-    NULL_PARAM_CHECK(p_handle);
-    VERIFY_APP_REGISTERED(p_handle->appl_id);
-
-    p_handle->device_id  = DM_INVALID_ID;
-
-    err_code = NRF_ERROR_NOT_FOUND;
-
-    for (index = 0; index < DEVICE_MANAGER_MAX_CONNECTIONS; index++)
-    {
-        //Search for matching connection handle.
-        if (conn_handle == m_connection_table[index].conn_handle)
-        {
-            p_handle->connection_id = index;
-            p_handle->device_id     = m_connection_table[index].bonded_dev_id;
-
-            err_code = NRF_SUCCESS;
-            break;
-        }
-    }
-    return err_code;
-}
\ No newline at end of file
--- a/source/nordic-sdk/components/drivers_nrf/ble_flash/ble_flash.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,307 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "ble_flash.h"
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include "nrf_soc.h"
-#include "nordic_common.h"
-#include "nrf_error.h"
-#include "nrf.h"
-#include "nrf51_bitfields.h"
-#include "app_util.h"
-
-
-static volatile bool m_radio_active = false;  /**< TRUE if radio is active (or about to become active), FALSE otherwise. */
-
-
-uint16_t ble_flash_crc16_compute(uint8_t * p_data, uint16_t size, uint16_t * p_crc)
-{
-    uint16_t i;
-    uint16_t crc = (p_crc == NULL) ? 0xffff : *p_crc;
-
-    for (i = 0; i < size; i++)
-    {
-        crc  = (unsigned char)(crc >> 8) | (crc << 8);
-        crc ^= p_data[i];
-        crc ^= (unsigned char)(crc & 0xff) >> 4;
-        crc ^= (crc << 8) << 4;
-        crc ^= ((crc & 0xff) << 4) << 1;
-    }
-    return crc;
-}
-
-
-/**@brief Function for erasing a page in flash.
- * 
- * @param[in]  p_page  Pointer to first word in page to be erased.
- */
-static void flash_page_erase(uint32_t * p_page)
-{
-    // Turn on flash erase enable and wait until the NVMC is ready.
-    NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Een << NVMC_CONFIG_WEN_Pos);
-    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
-    {
-        // Do nothing.
-    }
-
-    // Erase page.
-    NRF_NVMC->ERASEPAGE = (uint32_t)p_page;
-    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
-    {
-        // Do nothing.
-    }
-
-    // Turn off flash erase enable and wait until the NVMC is ready.
-    NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
-    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
-    {
-        // Do nothing
-    }
-}
-
-
-/**@brief Function for writing one word to flash. Unprotected write, which can interfere with radio communication.
- *
- * @details This function DOES NOT use the m_radio_active variable, but will force the write even
- *          when the radio is active. To be used only from @ref ble_flash_page_write.
- *
- * @note Flash location to be written must have been erased previously.
- *
- * @param[in]  p_address   Pointer to flash location to be written.
- * @param[in]  value       Value to write to flash.
- */
-static void flash_word_unprotected_write(uint32_t * p_address, uint32_t value)
-{
-    // Turn on flash write enable and wait until the NVMC is ready.
-    NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos);
-    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
-    {
-        // Do nothing.
-    }
-    *p_address = value;
-    
-    // Wait flash write to finish
-    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
-    {
-        // Do nothing.
-    }
-
-    // Turn off flash write enable and wait until the NVMC is ready.
-    NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
-    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
-    {
-        // Do nothing.
-    }
-}
-
-
-/**@brief Function for writing one word to flash.
- *
- * @note Flash location to be written must have been erased previously.
- *
- * @param[in]  p_address   Pointer to flash location to be written.
- * @param[in]  value       Value to write to flash.
- */
-static void flash_word_write(uint32_t * p_address, uint32_t value)
-{
-    // If radio is active, wait for it to become inactive.
-    while (m_radio_active)
-    {
-        // Do nothing (just wait for radio to become inactive).
-        (void) sd_app_evt_wait();
-    }
-
-    // Turn on flash write enable and wait until the NVMC is ready.
-    NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos);
-    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
-    {
-        // Do nothing.
-    }
-
-    *p_address = value;
-    // Wait flash write to finish
-    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
-    {
-        // Do nothing.
-    }
-    // Turn off flash write enable and wait until the NVMC is ready.
-    NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
-    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
-    {
-        // Do nothing
-    }
-}
-
-
-uint32_t ble_flash_word_write(uint32_t * p_address, uint32_t value)
-{
-    flash_word_write(p_address, value);
-    return NRF_SUCCESS;
-}
-
-
-uint32_t ble_flash_block_write(uint32_t * p_address, uint32_t * p_in_array, uint16_t word_count)
-{
-    uint16_t i;
-
-    for (i = 0; i < word_count; i++)
-    {
-        flash_word_write(p_address, p_in_array[i]);
-        p_address++;
-    }
-
-    return NRF_SUCCESS;
-}
-
-
-uint32_t ble_flash_page_erase(uint8_t page_num)
-{
-    uint32_t * p_page = (uint32_t *)(BLE_FLASH_PAGE_SIZE * page_num);
-    flash_page_erase(p_page);
-
-    return NRF_SUCCESS;
-}
-
-
-uint32_t ble_flash_page_write(uint8_t page_num, uint32_t * p_in_array, uint8_t word_count)
-{
-    int        i;
-    uint32_t * p_page;
-    uint32_t * p_curr_addr;
-    uint16_t   in_data_crc;
-    uint16_t   flash_crc;
-    uint32_t   flash_header;
-
-    p_page      = (uint32_t *)(BLE_FLASH_PAGE_SIZE * page_num);
-    p_curr_addr = p_page;
-
-    // Calculate CRC of the data to write.
-    in_data_crc = ble_flash_crc16_compute((uint8_t *)p_in_array,
-                                          word_count * sizeof(uint32_t),
-                                          NULL);
-
-    // Compare the calculated to the one in flash.
-    flash_header = *p_curr_addr;
-    flash_crc    = (uint16_t)flash_header;
-
-    if (flash_crc == in_data_crc)
-    {
-        // Data is the same as the data already stored in flash, return without modifying flash.
-        return NRF_SUCCESS;
-    }
-
-    // Erase flash page
-    flash_page_erase(p_page);
-
-    // Reserve space for magic number (for detecting if flash content is valid).
-    p_curr_addr++;
-
-    // Reserve space for saving word_count.
-    p_curr_addr++;
-
-    // Write data
-    for (i = 0; i < word_count; i++)
-    {
-        flash_word_unprotected_write(p_curr_addr, p_in_array[i]);
-        p_curr_addr++;
-    }
-
-    // Write number of elements.
-    flash_word_write(p_page + 1, (uint32_t)(word_count));
-
-    // Write magic number and CRC to indicate that flash content is valid.
-    flash_header = BLE_FLASH_MAGIC_NUMBER | (uint32_t)in_data_crc;
-    flash_word_write(p_page, flash_header);
-
-    return NRF_SUCCESS;
-}
-
-
-uint32_t ble_flash_page_read(uint8_t page_num, uint32_t * p_out_array, uint8_t * p_word_count)
-{
-    int        byte_count;
-    uint32_t * p_page;
-    uint32_t * p_curr_addr;
-    uint32_t   flash_header;
-    uint32_t   calc_header;
-    uint16_t   calc_crc;
-    uint32_t   tmp;
-
-    p_page      = (uint32_t *)(BLE_FLASH_PAGE_SIZE * page_num);    
-    p_curr_addr = p_page;
-
-    // Check if block is valid
-    flash_header = *p_curr_addr;
-    tmp = flash_header & 0xFFFF0000;
-    if (tmp != BLE_FLASH_MAGIC_NUMBER)
-    {
-        *p_word_count = 0;
-        return NRF_ERROR_NOT_FOUND;
-    }
-    p_curr_addr++;
-
-    // Read number of elements
-    *p_word_count = (uint8_t)(*(p_curr_addr));
-    p_curr_addr++;
-
-    // Read data
-    byte_count = (*p_word_count) * sizeof(uint32_t);
-    memcpy(p_out_array, p_curr_addr, byte_count);
-
-    // Check CRC
-    calc_crc = ble_flash_crc16_compute((uint8_t *)p_out_array,
-                                       (*p_word_count) * sizeof(uint32_t),
-                                       NULL);
-    calc_header = BLE_FLASH_MAGIC_NUMBER | (uint32_t)calc_crc;
-
-    if (calc_header != flash_header)
-    {
-        return NRF_ERROR_NOT_FOUND;
-    }
-
-    return NRF_SUCCESS;
-}
-
-
-uint32_t ble_flash_page_addr(uint8_t page_num, uint32_t ** pp_page_addr)
-{
-    *pp_page_addr = (uint32_t *)(BLE_FLASH_PAGE_SIZE * page_num);
-    return NRF_SUCCESS;
-}
-
-
-void ble_flash_on_radio_active_evt(bool radio_active)
-{
-    m_radio_active = radio_active;
-}
\ No newline at end of file
--- a/source/nordic-sdk/components/drivers_nrf/ble_flash/ble_flash.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,162 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/** @file
- *
- * @defgroup ble_flash_module Flash Manager
- * @{
- * @ingroup ble_sdk_lib
- * @brief Module for accessing flash memory.
- *
- * @details It contains functions for reading, writing and erasing one page in flash.
- *
- *          The module uses the first 32 bits of the flash page to write a magic number in order to
- *          determine if the page has been written or not.
- *
- * @note Be careful not to use a page number in the SoftDevice area (which currently occupies the
- *       range 0 to 127), or in your application space! In both cases, this would end up
- *       with a hard fault.
- */
-
-#ifndef BLE_FLASH_H__
-#define BLE_FLASH_H__
-
-#include <stdint.h>
-#include <stdbool.h>
-#include <nrf51.h>
-
-#define BLE_FLASH_PAGE_SIZE     ((uint16_t)NRF_FICR->CODEPAGESIZE)  /**< Size of one flash page. */
-#define BLE_FLASH_MAGIC_NUMBER  0x45DE0000                          /**< Magic value to identify if flash contains valid data. */
-#define BLE_FLASH_EMPTY_MASK    0xFFFFFFFF                          /**< Bit mask that defines an empty address in flash. */
-
-
-/**@brief Macro for getting the end of the flash available for application.
- * 
- * @details    The result flash page number indicates the end boundary of the flash available 
- *             to the application. If a bootloader is used, the end will be the start of the 
- *             bootloader region. Otherwise, the end will be the size of the flash. 
- */
-#define BLE_FLASH_PAGE_END \
-    ((NRF_UICR->BOOTLOADERADDR != BLE_FLASH_EMPTY_MASK) \
-        ? (NRF_UICR->BOOTLOADERADDR / BLE_FLASH_PAGE_SIZE) \
-        : NRF_FICR->CODESIZE)
-
-/**@brief Function for erasing the specified flash page, and then writes the given data to this page.
- *
- * @warning This operation blocks the CPU. DO NOT use while in a connection!
- *
- * @param[in]  page_num     Page number to update.
- * @param[in]  p_in_array   Pointer to a RAM area containing the elements to write in flash.
- *                          This area has to be 32 bits aligned.
- * @param[in]  word_count   Number of 32 bits words to write in flash.
- *
- * @return     NRF_SUCCESS on successful flash write, otherwise an error code.
- */
-uint32_t ble_flash_page_write(uint8_t page_num, uint32_t * p_in_array, uint8_t word_count);
-
-/**@brief Function for reading data from flash to RAM.
- *
- * @param[in]  page_num       Page number to read.
- * @param[out] p_out_array    Pointer to a RAM area where the found data will be written. 
- *                            This area has to be 32 bits aligned.
- * @param[out] p_word_count   Number of 32 bits words read.
- *
- * @return     NRF_SUCCESS on successful upload, NRF_ERROR_NOT_FOUND if no valid data has been found
- *             in flash (first 32 bits not equal to the MAGIC_NUMBER+CRC).
- */
-uint32_t ble_flash_page_read(uint8_t page_num, uint32_t * p_out_array, uint8_t * p_word_count);
-
-/**@brief Function for erasing a flash page.
- *
- * @note This operation blocks the CPU, so it should not be done while the radio is running!
- *
- * @param[in]  page_num   Page number to erase.
- *
- * @return     NRF_SUCCESS on success, an error_code otherwise.
- */
-uint32_t ble_flash_page_erase(uint8_t page_num);
-
-/**@brief Function for writing one word to flash.
- *
- * @note Flash location to be written must have been erased previously.
- *
- * @param[in]  p_address   Pointer to flash location to be written.
- * @param[in]  value       Value to write to flash.
- *
- * @return     NRF_SUCCESS.
- */
-uint32_t ble_flash_word_write(uint32_t * p_address, uint32_t value);
-
-/**@brief Function for writing a data block to flash.
- *
- * @note Flash locations to be written must have been erased previously.
- *
- * @param[in]  p_address    Pointer to start of flash location to be written.
- * @param[in]  p_in_array   Pointer to start of flash block to be written.
- * @param[in]  word_count   Number of words to be written.
- *
- * @return     NRF_SUCCESS.
- */
-uint32_t ble_flash_block_write(uint32_t * p_address, uint32_t * p_in_array, uint16_t word_count);
-
-/**@brief Function for computing pointer to start of specified flash page.
- *
- * @param[in]  page_num       Page number.
- * @param[out] pp_page_addr   Pointer to start of flash page.
- *
- * @return     NRF_SUCCESS.
- */
-uint32_t ble_flash_page_addr(uint8_t page_num, uint32_t ** pp_page_addr);
-
-/**@brief Function for calculating a 16 bit CRC using the CRC-16-CCITT scheme.
- * 
- * @param[in]  p_data   Pointer to data on which the CRC is to be calulated.
- * @param[in]  size     Number of bytes on which the CRC is to be calulated.
- * @param[in]  p_crc    Initial CRC value (if NULL, a preset value is used as the initial value).
- *
- * @return     Calculated CRC.
- */
-uint16_t ble_flash_crc16_compute(uint8_t * p_data, uint16_t size, uint16_t * p_crc);
-
-/**@brief Function for handling flashing module Radio Notification event.
- *
- * @note For flash writing to work safely while in a connection or while advertising, this function
- *       MUST be called from the Radio Notification module's event handler (see
- *       @ref ble_radio_notification for details).
- *
- * @param[in]  radio_active   TRUE if radio is active (or about to become active), FALSE otherwise.
- */
-void ble_flash_on_radio_active_evt(bool radio_active);
-
-#endif // BLE_FLASH_H__
-
-/** @} */
\ No newline at end of file
--- a/source/nordic-sdk/components/drivers_nrf/hal/compiler_abstraction.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nordic-sdk/components/drivers_nrf/hal/compiler_abstraction.h	Wed Apr 06 22:39:17 2016 +0100
@@ -37,50 +37,63 @@
 #if defined ( __CC_ARM )
     
     #ifndef __ASM
-        #define __ASM               __asm                       /*!< asm keyword for ARM Compiler */
+        #define __ASM               __asm                       
     #endif
     
     #ifndef __INLINE
-        #define __INLINE            __inline                    /*!< inline keyword for ARM Compiler */
+        #define __INLINE            __inline                    
     #endif
     
     #ifndef __WEAK
-        #define __WEAK              __weak                      /*!< weak keyword for ARM Compiler */
+        #define __WEAK              __weak                      
     #endif
     
-    #define GET_SP()                __current_sp()              /*!> read current SP function for ARM Compiler */
+    #ifndef __ALIGN
+        #define __ALIGN(n)          __align(n)                  
+    #endif
+    
+    #define GET_SP()                __current_sp()              
   
 #elif defined ( __ICCARM__ )
     
     #ifndef __ASM
-        #define __ASM               __asm                       /*!< asm keyword for IAR Compiler */
+        #define __ASM               __asm                       
     #endif
     
     #ifndef __INLINE
-        #define __INLINE            inline                      /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
+        #define __INLINE            inline                      
     #endif
     
     #ifndef __WEAK
-        #define __WEAK              __weak                      /*!> define weak function for IAR Compiler */
+        #define __WEAK              __weak                      
+    #endif
+
+    /* Not defined for IAR since it requires a new line to work, and C preprocessor does not allow that. */
+    #ifndef __ALIGN
+        #define __ALIGN(n)          
     #endif
     
-    #define GET_SP()                __get_SP()                  /*!> read current SP function for IAR Compiler */
+    #define GET_SP()                __get_SP()                  
     
 #elif defined   ( __GNUC__ )
     
     #ifndef __ASM
-        #define __ASM               __asm__                     /*!< asm keyword for GNU Compiler */
+        #define __ASM               __asm                       
     #endif
     
     #ifndef __INLINE
-        #define __INLINE            inline                      /*!< inline keyword for GNU Compiler */
+        #define __INLINE            inline                      
     #endif
     
     #ifndef __WEAK
-        #define __WEAK              __attribute__((weak))       /*!< weak keyword for GNU Compiler */
+        #define __WEAK              __attribute__((weak))       
     #endif
     
-    #define GET_SP()                gcc_current_sp()            /*!> read current SP function for GNU Compiler */
+    #ifndef __ALIGN
+        #define __ALIGN(n)          __attribute__((aligned(n))) 
+    #endif
+    
+    #define GET_SP()                gcc_current_sp()            
 
     static inline unsigned int gcc_current_sp(void)
     {
@@ -91,18 +104,22 @@
 #elif defined   ( __TASKING__ )
         
     #ifndef __ASM        
-        #define __ASM               __asm                       /*!< asm keyword for TASKING Compiler */
+        #define __ASM               __asm                      
     #endif
     
     #ifndef __INLINE
-        #define __INLINE            inline                      /*!< inline keyword for TASKING Compiler */
+        #define __INLINE            inline                     
     #endif
     
     #ifndef __WEAK
-        #define __WEAK              __attribute__((weak))       /*!< weak keyword for TASKING Compiler */
+        #define __WEAK              __attribute__((weak))      
     #endif
     
-    #define GET_SP()                __get_MSP()                 /*!> read current SP function for TASKING Compiler */
+    #ifndef __ALIGN
+        #define __ALIGN(n)          __align(n)                  
+    #endif
+    
+    #define GET_SP()                __get_MSP()                
     
 #endif
 
--- a/source/nordic-sdk/components/drivers_nrf/hal/nrf.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nordic-sdk/components/drivers_nrf/hal/nrf.h	Wed Apr 06 22:39:17 2016 +0100
@@ -29,22 +29,29 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
+
 #ifndef NRF_H
 #define NRF_H
 
-#ifndef _WIN32
+#if defined(_WIN32)         
+    /* Do not include nrf51 specific files when building for PC host */
+#elif defined(__unix)       
+    /* Do not include nrf51 specific files when building for PC host */
+#elif defined(__APPLE__)    
+    /* Do not include nrf51 specific files when building for PC host */
+#else
 
-/* Family selection for main includes. NRF51 must be selected. */
-#ifdef NRF51
-    #include "nrf51.h"
-    #include "nrf51_bitfields.h"
-    #include "nrf51_deprecated.h"
-#else
-    #error "Device family must be defined. See nrf.h."
-#endif /* NRF51 */
+    /* Family selection for family includes. */
+    #if defined (NRF51)
+        #include "nrf51.h"
+        #include "nrf51_bitfields.h"
+        #include "nrf51_deprecated.h"
+    #else
+        #error "Device family must be defined. See nrf.h."
+    #endif /* NRF51 */
 
-#include "compiler_abstraction.h"
+    #include "compiler_abstraction.h"
 
-#endif /* _WIN32 */
+#endif /* _WIN32 || __unix || __APPLE__ */
 
 #endif /* NRF_H */
--- a/source/nordic-sdk/components/drivers_nrf/hal/nrf51.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nordic-sdk/components/drivers_nrf/hal/nrf51.h	Wed Apr 06 22:39:17 2016 +0100
@@ -30,10 +30,6 @@
  *
  */
 
-/** @addtogroup nRF51
-  * @{
-  */
-
 #ifndef NRF51_H
 #define NRF51_H
 
@@ -53,7 +49,7 @@
   DebugMonitor_IRQn             =  -4,              /*!<  12  Debug Monitor                                                    */
   PendSV_IRQn                   =  -2,              /*!<  14  Pendable request for system service                              */
   SysTick_IRQn                  =  -1,              /*!<  15  System Tick Timer                                                */
-/* ----------------------  nRF51 Specific Interrupt Numbers  ---------------------- */
+/* ----------------------  nrf51 Specific Interrupt Numbers  ---------------------- */
   POWER_CLOCK_IRQn              =   0,              /*!<   0  POWER_CLOCK                                                      */
   RADIO_IRQn                    =   1,              /*!<   1  RADIO                                                            */
   UART0_IRQn                    =   2,              /*!<   2  UART0                                                            */
@@ -99,7 +95,7 @@
 /** @} */ /* End of group Configuration_of_CMSIS */
 
 #include "core_cm0.h"                               /*!< Cortex-M0 processor and core peripherals                              */
-#include "system_nrf51.h"                           /*!< nRF51 System                                                          */
+#include "system_nrf51.h"                           /*!< nrf51 System                                                          */
 
 
 /* ================================================================================ */
@@ -166,15 +162,6 @@
   __IO uint32_t  TEP;                               /*!< Channel task end-point.                                               */
 } PPI_CH_Type;
 
-typedef struct {
-  __I  uint32_t  PART;                              /*!< Part code                                                             */
-  __I  uint32_t  VARIANT;                           /*!< Part variant                                                          */
-  __I  uint32_t  PACKAGE;                           /*!< Package option                                                        */
-  __I  uint32_t  RAM;                               /*!< RAM variant                                                           */
-  __I  uint32_t  FLASH;                             /*!< Flash variant                                                         */
-  __I  uint32_t  RESERVED[3];                       /*!< Reserved                                                              */
-} FICR_INFO_Type;
-
 
 /* ================================================================================ */
 /* ================                      POWER                     ================ */
@@ -349,7 +336,7 @@
   __IO uint32_t  EVENTS_RSSIEND;                    /*!< Sampling of the receive signal strength complete. A new RSSI
                                                          sample is ready for readout at the RSSISAMPLE register.               */
   __I  uint32_t  RESERVED1[2];
-  __IO uint32_t  EVENTS_BCMATCH;                    /*!< Bit counter reached bit count value specified in BC register.         */
+  __IO uint32_t  EVENTS_BCMATCH;                    /*!< Bit counter reached bit count value specified in BCC register.        */
   __I  uint32_t  RESERVED2[53];
   __IO uint32_t  SHORTS;                            /*!< Shortcuts for the radio.                                              */
   __I  uint32_t  RESERVED3[64];
@@ -426,16 +413,14 @@
   __IO uint32_t  EVENTS_ERROR;                      /*!< Error detected.                                                       */
   __I  uint32_t  RESERVED4[7];
   __IO uint32_t  EVENTS_RXTO;                       /*!< Receiver timeout.                                                     */
-  __I  uint32_t  RESERVED5[46];
-  __IO uint32_t  SHORTS;                            /*!< Shortcuts for UART.                                                   */
-  __I  uint32_t  RESERVED6[64];
+  __I  uint32_t  RESERVED5[111];
   __IO uint32_t  INTENSET;                          /*!< Interrupt enable set register.                                        */
   __IO uint32_t  INTENCLR;                          /*!< Interrupt enable clear register.                                      */
-  __I  uint32_t  RESERVED7[93];
+  __I  uint32_t  RESERVED6[93];
   __IO uint32_t  ERRORSRC;                          /*!< Error source. Write error field to 1 to clear error.                  */
-  __I  uint32_t  RESERVED8[31];
+  __I  uint32_t  RESERVED7[31];
   __IO uint32_t  ENABLE;                            /*!< Enable UART and acquire IOs.                                          */
-  __I  uint32_t  RESERVED9;
+  __I  uint32_t  RESERVED8;
   __IO uint32_t  PSELRTS;                           /*!< Pin select for RTS.                                                   */
   __IO uint32_t  PSELTXD;                           /*!< Pin select for TXD.                                                   */
   __IO uint32_t  PSELCTS;                           /*!< Pin select for CTS.                                                   */
@@ -444,11 +429,11 @@
                                                          Once read the character is consumed. If read when no character
                                                           available, the UART will stop working.                               */
   __O  uint32_t  TXD;                               /*!< TXD register.                                                         */
-  __I  uint32_t  RESERVED10;
+  __I  uint32_t  RESERVED9;
   __IO uint32_t  BAUDRATE;                          /*!< UART Baudrate.                                                        */
-  __I  uint32_t  RESERVED11[17];
+  __I  uint32_t  RESERVED10[17];
   __IO uint32_t  CONFIG;                            /*!< Configuration of parity and hardware flow control register.           */
-  __I  uint32_t  RESERVED12[675];
+  __I  uint32_t  RESERVED11[675];
   __IO uint32_t  POWER;                             /*!< Peripheral power control.                                             */
 } NRF_UART_Type;
 
@@ -626,20 +611,17 @@
   __IO uint32_t  ENABLE;                            /*!< Enable SPIM.                                                          */
   __I  uint32_t  RESERVED10;
   SPIM_PSEL_Type PSEL;                              /*!< Pin select configuration.                                             */
-  __I  uint32_t  RESERVED11;
-  __I  uint32_t  RXDDATA;                           /*!< RXD register.                                                         */
-  __IO uint32_t  TXDDATA;                           /*!< TXD register.                                                         */
-  __I  uint32_t  RESERVED12;
+  __I  uint32_t  RESERVED11[4];
   __IO uint32_t  FREQUENCY;                         /*!< SPI frequency.                                                        */
-  __I  uint32_t  RESERVED13[3];
+  __I  uint32_t  RESERVED12[3];
   SPIM_RXD_Type RXD;                                /*!< RXD EasyDMA configuration and status.                                 */
-  __I  uint32_t  RESERVED14;
+  __I  uint32_t  RESERVED13;
   SPIM_TXD_Type TXD;                                /*!< TXD EasyDMA configuration and status.                                 */
-  __I  uint32_t  RESERVED15;
+  __I  uint32_t  RESERVED14;
   __IO uint32_t  CONFIG;                            /*!< Configuration register.                                               */
-  __I  uint32_t  RESERVED16[26];
+  __I  uint32_t  RESERVED15[26];
   __IO uint32_t  ORC;                               /*!< Over-read character.                                                  */
-  __I  uint32_t  RESERVED17[654];
+  __I  uint32_t  RESERVED16[654];
   __IO uint32_t  POWER;                             /*!< Peripheral power control.                                             */
 } NRF_SPIM_Type;
 
@@ -1070,9 +1052,13 @@
   __I  uint32_t  READY;                             /*!< Ready flag.                                                           */
   __I  uint32_t  RESERVED1[64];
   __IO uint32_t  CONFIG;                            /*!< Configuration register.                                               */
-  __IO uint32_t  ERASEPAGE;                         /*!< Register for erasing a non-protected non-volatile memory page.        */
+  
+  union {
+    __IO uint32_t  ERASEPCR1;                       /*!< Register for erasing a non-protected non-volatile memory page.        */
+    __IO uint32_t  ERASEPAGE;                       /*!< Register for erasing a non-protected non-volatile memory page.        */
+  };
   __IO uint32_t  ERASEALL;                          /*!< Register for erasing all non-volatile user memory.                    */
-  __IO uint32_t  ERASEPROTECTEDPAGE;                /*!< Register for erasing a protected non-volatile memory page.            */
+  __IO uint32_t  ERASEPCR0;                         /*!< Register for erasing a protected non-volatile memory page.            */
   __IO uint32_t  ERASEUICR;                         /*!< Register for start erasing User Information Congfiguration Registers. */
 } NRF_NVMC_Type;
 
@@ -1138,7 +1124,6 @@
   __I  uint32_t  RESERVED5[10];
   __I  uint32_t  BLE_1MBIT[5];                      /*!< Override values for the OVERRIDEn registers in RADIO for BLE_1Mbit
                                                          mode.                                                                 */
-  FICR_INFO_Type INFO;                              /*!< Device info                                                           */
 } NRF_FICR_Type;
 
 
@@ -1157,7 +1142,13 @@
   __IO uint32_t  XTALFREQ;                          /*!< Reset value for CLOCK XTALFREQ register.                              */
   __I  uint32_t  RESERVED0;
   __I  uint32_t  FWID;                              /*!< Firmware ID.                                                          */
-  __IO uint32_t  BOOTLOADERADDR;                    /*!< Bootloader start address.                                             */
+  
+  union {
+    __IO uint32_t  NRFFW[15];                       /*!< Reserved for Nordic firmware design.                                  */
+    __IO uint32_t  BOOTLOADERADDR;                  /*!< Bootloader start address.                                             */
+  };
+  __IO uint32_t  NRFHW[12];                         /*!< Reserved for Nordic hardware design.                                  */
+  __IO uint32_t  CUSTOMER[32];                      /*!< Reserved for customer.                                                */
 } NRF_UICR_Type;
 
 
@@ -1283,7 +1274,7 @@
 
 
 /** @} */ /* End of group Device_Peripheral_Registers */
-/** @} */ /* End of group nRF51 */
+/** @} */ /* End of group nrf51 */
 /** @} */ /* End of group Nordic Semiconductor */
 
 #ifdef __cplusplus
@@ -1291,4 +1282,4 @@
 #endif
 
 
-#endif  /* nRF51_H */
+#endif  /* nrf51_H */
--- a/source/nordic-sdk/components/drivers_nrf/hal/nrf51_bitfields.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nordic-sdk/components/drivers_nrf/hal/nrf51_bitfields.h	Wed Apr 06 22:39:17 2016 +0100
@@ -32,9 +32,7 @@
 #ifndef __NRF51_BITS_H
 #define __NRF51_BITS_H
 
-/*lint ++flb "Enter library region */
-
-#include <core_cm0.h>
+/*lint ++flb "Enter library region" */
 
 /* Peripheral: AAR */
 /* Description: Accelerated Address Resolver. */
@@ -822,6 +820,7 @@
 #define AMLI_RAMPRI_AAR_RAM0_Pri12 (0xCUL) /*!< Priority 12. */
 #define AMLI_RAMPRI_AAR_RAM0_Pri14 (0xEUL) /*!< Priority 14. */
 
+
 /* Peripheral: CCM */
 /* Description: AES CCM Mode Encryption. */
 
@@ -1066,8 +1065,8 @@
 /* Bits 7..0 : External Xtal frequency selection. */
 #define CLOCK_XTALFREQ_XTALFREQ_Pos (0UL) /*!< Position of XTALFREQ field. */
 #define CLOCK_XTALFREQ_XTALFREQ_Msk (0xFFUL << CLOCK_XTALFREQ_XTALFREQ_Pos) /*!< Bit mask of XTALFREQ field. */
+#define CLOCK_XTALFREQ_XTALFREQ_32MHz (0x00UL) /*!< 32MHz xtal is used as source for the HFCLK oscillator. */
 #define CLOCK_XTALFREQ_XTALFREQ_16MHz (0xFFUL) /*!< 16MHz xtal is used as source for the HFCLK oscillator. */
-#define CLOCK_XTALFREQ_XTALFREQ_32MHz (0x00UL) /*!< 32MHz xtal is used as source for the HFCLK oscillator. */
 
 
 /* Peripheral: ECB */
@@ -1126,8 +1125,8 @@
 /* Bits 7..0 : Pre-programmed factory code present. */
 #define FICR_PPFC_PPFC_Pos (0UL) /*!< Position of PPFC field. */
 #define FICR_PPFC_PPFC_Msk (0xFFUL << FICR_PPFC_PPFC_Pos) /*!< Bit mask of PPFC field. */
+#define FICR_PPFC_PPFC_Present (0x00UL) /*!< Present. */
 #define FICR_PPFC_PPFC_NotPresent (0xFFUL) /*!< Not present. */
-#define FICR_PPFC_PPFC_Present (0x00UL) /*!< Present. */
 
 /* Register: FICR_CONFIGID */
 /* Description: Configuration identifier. */
@@ -1164,60 +1163,6 @@
 #define FICR_OVERRIDEEN_NRF_1MBIT_Override (0UL) /*!< Override the default values for NRF_1Mbit mode. */
 #define FICR_OVERRIDEEN_NRF_1MBIT_NotOverride (1UL) /*!< Do not override the default values for NRF_1Mbit mode. */
 
-/* Register: FICR_INFO_PART */
-/* Description: Part code */
-
-/* Bits 31..0 : Part code */
-#define FICR_INFO_PART_PART_Pos (0UL) /*!< Position of PART field. */
-#define FICR_INFO_PART_PART_Msk (0xFFFFFFFFUL << FICR_INFO_PART_PART_Pos) /*!< Bit mask of PART field. */
-#define FICR_INFO_PART_PART_N51822 (0x51822UL) /*!< nRF51822 */
-#define FICR_INFO_PART_PART_N51422 (0x51422UL) /*!< nRF51422 */
-#define FICR_INFO_PART_PART_Unspecified (0xFFFFFFFFUL) /*!< Unspecified */
-
-/* Register: FICR_INFO_VARIANT */
-/* Description: Part variant */
-
-/* Bits 31..0 : Part variant */
-#define FICR_INFO_VARIANT_VARIANT_Pos (0UL) /*!< Position of VARIANT field. */
-#define FICR_INFO_VARIANT_VARIANT_Msk (0xFFFFFFFFUL << FICR_INFO_VARIANT_VARIANT_Pos) /*!< Bit mask of VARIANT field. */
-#define FICR_INFO_VARIANT_VARIANT_nRF51C (0x1002UL) /*!< nRF51-C (XLR3) */
-#define FICR_INFO_VARIANT_VARIANT_nRF51D (0x1003UL) /*!< nRF51-D (L3) */
-#define FICR_INFO_VARIANT_VARIANT_nRF51E (0x1004UL) /*!< nRF51-E (XLR3P) */
-#define FICR_INFO_VARIANT_VARIANT_Unspecified (0xFFFFFFFFUL) /*!< Unspecified */
-
-/* Register: FICR_INFO_PACKAGE */
-/* Description: Package option */
-
-/* Bits 31..0 : Package option */
-#define FICR_INFO_PACKAGE_PACKAGE_Pos (0UL) /*!< Position of PACKAGE field. */
-#define FICR_INFO_PACKAGE_PACKAGE_Msk (0xFFFFFFFFUL << FICR_INFO_PACKAGE_PACKAGE_Pos) /*!< Bit mask of PACKAGE field. */
-#define FICR_INFO_PACKAGE_PACKAGE_QFN48 (0x0000UL) /*!< 48-pin QFN with 31 GPIO */
-#define FICR_INFO_PACKAGE_PACKAGE_nRF51CSP56A (0x1000UL) /*!< nRF51x22 CDxx - WLCSP 56 balls */
-#define FICR_INFO_PACKAGE_PACKAGE_nRF51CSP62A (0x1001UL) /*!< nRF51x22 CExx - WLCSP 62 balls */
-#define FICR_INFO_PACKAGE_PACKAGE_nRF51CSP62B (0x1002UL) /*!< nRF51x22 CFxx - WLCSP 62 balls */
-#define FICR_INFO_PACKAGE_PACKAGE_nRF51CSP62C (0x1003UL) /*!< nRF51x22 CTxx - WLCSP 62 balls */
-#define FICR_INFO_PACKAGE_PACKAGE_Unspecified (0xFFFFFFFFUL) /*!< Unspecified */
-
-/* Register: FICR_INFO_RAM */
-/* Description: RAM variant */
-
-/* Bits 31..0 : RAM variant */
-#define FICR_INFO_RAM_RAM_Pos (0UL) /*!< Position of RAM field. */
-#define FICR_INFO_RAM_RAM_Msk (0xFFFFFFFFUL << FICR_INFO_RAM_RAM_Pos) /*!< Bit mask of RAM field. */
-#define FICR_INFO_RAM_RAM_Unspecified (0xFFFFFFFFUL) /*!< Unspecified */
-#define FICR_INFO_RAM_RAM_K16 (16UL) /*!< 16 kByte RAM. */
-#define FICR_INFO_RAM_RAM_K32 (32UL) /*!< 32 kByte RAM. */
-
-/* Register: FICR_INFO_FLASH */
-/* Description: Flash variant */
-
-/* Bits 31..0 : Flash variant */
-#define FICR_INFO_FLASH_FLASH_Pos (0UL) /*!< Position of FLASH field. */
-#define FICR_INFO_FLASH_FLASH_Msk (0xFFFFFFFFUL << FICR_INFO_FLASH_FLASH_Pos) /*!< Bit mask of FLASH field. */
-#define FICR_INFO_FLASH_FLASH_Unspecified (0xFFFFFFFFUL) /*!< Unspecified */
-#define FICR_INFO_FLASH_FLASH_K128 (128UL) /*!< 128 kByte FLASH. */
-#define FICR_INFO_FLASH_FLASH_K256 (256UL) /*!< 256 kByte FLASH. */
-
 
 /* Peripheral: GPIO */
 /* Description: General purpose input and output. */
@@ -2848,6 +2793,7 @@
 /* Bits 17..16 : Effects on output when in Task mode, or events on input that generates an event. */
 #define GPIOTE_CONFIG_POLARITY_Pos (16UL) /*!< Position of POLARITY field. */
 #define GPIOTE_CONFIG_POLARITY_Msk (0x3UL << GPIOTE_CONFIG_POLARITY_Pos) /*!< Bit mask of POLARITY field. */
+#define GPIOTE_CONFIG_POLARITY_None (0x00UL) /*!< No task or event. */
 #define GPIOTE_CONFIG_POLARITY_LoToHi (0x01UL) /*!< Low to high. */
 #define GPIOTE_CONFIG_POLARITY_HiToLo (0x02UL) /*!< High to low. */
 #define GPIOTE_CONFIG_POLARITY_Toggle (0x03UL) /*!< Toggle. */
@@ -3722,30 +3668,44 @@
 /* Bit 18 : Reset from wake-up from OFF mode detected by entering into debug interface mode. */
 #define POWER_RESETREAS_DIF_Pos (18UL) /*!< Position of DIF field. */
 #define POWER_RESETREAS_DIF_Msk (0x1UL << POWER_RESETREAS_DIF_Pos) /*!< Bit mask of DIF field. */
+#define POWER_RESETREAS_DIF_NotDetected (0UL) /*!< Reset not detected. */
+#define POWER_RESETREAS_DIF_Detected (1UL) /*!< Reset detected. */
 
 /* Bit 17 : Reset from wake-up from OFF mode detected by the use of ANADETECT signal from LPCOMP. */
 #define POWER_RESETREAS_LPCOMP_Pos (17UL) /*!< Position of LPCOMP field. */
 #define POWER_RESETREAS_LPCOMP_Msk (0x1UL << POWER_RESETREAS_LPCOMP_Pos) /*!< Bit mask of LPCOMP field. */
+#define POWER_RESETREAS_LPCOMP_NotDetected (0UL) /*!< Reset not detected. */
+#define POWER_RESETREAS_LPCOMP_Detected (1UL) /*!< Reset detected. */
 
 /* Bit 16 : Reset from wake-up from OFF mode detected by the use of DETECT signal from GPIO. */
 #define POWER_RESETREAS_OFF_Pos (16UL) /*!< Position of OFF field. */
 #define POWER_RESETREAS_OFF_Msk (0x1UL << POWER_RESETREAS_OFF_Pos) /*!< Bit mask of OFF field. */
+#define POWER_RESETREAS_OFF_NotDetected (0UL) /*!< Reset not detected. */
+#define POWER_RESETREAS_OFF_Detected (1UL) /*!< Reset detected. */
 
 /* Bit 3 : Reset from CPU lock-up detected. */
 #define POWER_RESETREAS_LOCKUP_Pos (3UL) /*!< Position of LOCKUP field. */
 #define POWER_RESETREAS_LOCKUP_Msk (0x1UL << POWER_RESETREAS_LOCKUP_Pos) /*!< Bit mask of LOCKUP field. */
+#define POWER_RESETREAS_LOCKUP_NotDetected (0UL) /*!< Reset not detected. */
+#define POWER_RESETREAS_LOCKUP_Detected (1UL) /*!< Reset detected. */
 
 /* Bit 2 : Reset from AIRCR.SYSRESETREQ detected. */
 #define POWER_RESETREAS_SREQ_Pos (2UL) /*!< Position of SREQ field. */
 #define POWER_RESETREAS_SREQ_Msk (0x1UL << POWER_RESETREAS_SREQ_Pos) /*!< Bit mask of SREQ field. */
+#define POWER_RESETREAS_SREQ_NotDetected (0UL) /*!< Reset not detected. */
+#define POWER_RESETREAS_SREQ_Detected (1UL) /*!< Reset detected. */
 
 /* Bit 1 : Reset from watchdog detected. */
 #define POWER_RESETREAS_DOG_Pos (1UL) /*!< Position of DOG field. */
 #define POWER_RESETREAS_DOG_Msk (0x1UL << POWER_RESETREAS_DOG_Pos) /*!< Bit mask of DOG field. */
+#define POWER_RESETREAS_DOG_NotDetected (0UL) /*!< Reset not detected. */
+#define POWER_RESETREAS_DOG_Detected (1UL) /*!< Reset detected. */
 
 /* Bit 0 : Reset from pin-reset detected. */
 #define POWER_RESETREAS_RESETPIN_Pos (0UL) /*!< Position of RESETPIN field. */
 #define POWER_RESETREAS_RESETPIN_Msk (0x1UL << POWER_RESETREAS_RESETPIN_Pos) /*!< Bit mask of RESETPIN field. */
+#define POWER_RESETREAS_RESETPIN_NotDetected (0UL) /*!< Reset not detected. */
+#define POWER_RESETREAS_RESETPIN_Detected (1UL) /*!< Reset detected. */
 
 /* Register: POWER_RAMSTATUS */
 /* Description: Ram status register. */
@@ -5215,14 +5175,14 @@
 /* Bits 7..0 : Radio output power. Decision point: TXEN task. */
 #define RADIO_TXPOWER_TXPOWER_Pos (0UL) /*!< Position of TXPOWER field. */
 #define RADIO_TXPOWER_TXPOWER_Msk (0xFFUL << RADIO_TXPOWER_TXPOWER_Pos) /*!< Bit mask of TXPOWER field. */
+#define RADIO_TXPOWER_TXPOWER_0dBm (0x00UL) /*!< 0dBm. */
 #define RADIO_TXPOWER_TXPOWER_Pos4dBm (0x04UL) /*!< +4dBm. */
-#define RADIO_TXPOWER_TXPOWER_0dBm (0x00UL) /*!< 0dBm. */
-#define RADIO_TXPOWER_TXPOWER_Neg4dBm (0xFCUL) /*!< -4dBm. */
+#define RADIO_TXPOWER_TXPOWER_Neg30dBm (0xD8UL) /*!< -30dBm. */
+#define RADIO_TXPOWER_TXPOWER_Neg20dBm (0xECUL) /*!< -20dBm. */
+#define RADIO_TXPOWER_TXPOWER_Neg16dBm (0xF0UL) /*!< -16dBm. */
+#define RADIO_TXPOWER_TXPOWER_Neg12dBm (0xF4UL) /*!< -12dBm. */
 #define RADIO_TXPOWER_TXPOWER_Neg8dBm (0xF8UL) /*!< -8dBm. */
-#define RADIO_TXPOWER_TXPOWER_Neg12dBm (0xF4UL) /*!< -12dBm. */
-#define RADIO_TXPOWER_TXPOWER_Neg16dBm (0xF0UL) /*!< -16dBm. */
-#define RADIO_TXPOWER_TXPOWER_Neg20dBm (0xECUL) /*!< -20dBm. */
-#define RADIO_TXPOWER_TXPOWER_Neg30dBm (0xD8UL) /*!< -30dBm. */
+#define RADIO_TXPOWER_TXPOWER_Neg4dBm (0xFCUL) /*!< -4dBm. */
 
 /* Register: RADIO_MODE */
 /* Description: Data rate and modulation. */
@@ -6096,20 +6056,6 @@
 #define SPIM_ENABLE_ENABLE_Disabled (0x00UL) /*!< Disabled SPIM. */
 #define SPIM_ENABLE_ENABLE_Enabled (0x07UL) /*!< Enable SPIM. */
 
-/* Register: SPIM_RXDDATA */
-/* Description: RXD register. */
-
-/* Bits 7..0 : RX data received. Double buffered. */
-#define SPIM_RXDDATA_RXD_Pos (0UL) /*!< Position of RXD field. */
-#define SPIM_RXDDATA_RXD_Msk (0xFFUL << SPIM_RXDDATA_RXD_Pos) /*!< Bit mask of RXD field. */
-
-/* Register: SPIM_TXDDATA */
-/* Description: TXD register. */
-
-/* Bits 7..0 : TX data to send. Double buffered. */
-#define SPIM_TXDDATA_TXD_Pos (0UL) /*!< Position of TXD field. */
-#define SPIM_TXDDATA_TXD_Msk (0xFFUL << SPIM_TXDDATA_TXD_Pos) /*!< Bit mask of TXD field. */
-
 /* Register: SPIM_FREQUENCY */
 /* Description: SPI frequency. */
 
@@ -6124,43 +6070,6 @@
 #define SPIM_FREQUENCY_FREQUENCY_M4 (0x40000000UL) /*!< 4 Mbps. */
 #define SPIM_FREQUENCY_FREQUENCY_M8 (0x80000000UL) /*!< 8 Mbps. */
 
-/* Register: SPIM_CONFIG */
-/* Description: Configuration register. */
-
-/* Bit 2 : Serial clock (SCK) polarity. */
-#define SPIM_CONFIG_CPOL_Pos (2UL) /*!< Position of CPOL field. */
-#define SPIM_CONFIG_CPOL_Msk (0x1UL << SPIM_CONFIG_CPOL_Pos) /*!< Bit mask of CPOL field. */
-#define SPIM_CONFIG_CPOL_ActiveHigh (0UL) /*!< Active high. */
-#define SPIM_CONFIG_CPOL_ActiveLow (1UL) /*!< Active low. */
-
-/* Bit 1 : Serial clock (SCK) phase. */
-#define SPIM_CONFIG_CPHA_Pos (1UL) /*!< Position of CPHA field. */
-#define SPIM_CONFIG_CPHA_Msk (0x1UL << SPIM_CONFIG_CPHA_Pos) /*!< Bit mask of CPHA field. */
-#define SPIM_CONFIG_CPHA_Leading (0UL) /*!< Sample on leading edge of the clock. Shift serial data on trailing edge. */
-#define SPIM_CONFIG_CPHA_Trailing (1UL) /*!< Sample on trailing edge of the clock. Shift serial data on leading edge. */
-
-/* Bit 0 : Bit order. */
-#define SPIM_CONFIG_ORDER_Pos (0UL) /*!< Position of ORDER field. */
-#define SPIM_CONFIG_ORDER_Msk (0x1UL << SPIM_CONFIG_ORDER_Pos) /*!< Bit mask of ORDER field. */
-#define SPIM_CONFIG_ORDER_MsbFirst (0UL) /*!< Most significant bit transmitted out first. */
-#define SPIM_CONFIG_ORDER_LsbFirst (1UL) /*!< Least significant bit transmitted out first. */
-
-/* Register: SPIM_ORC */
-/* Description: Over-read character. */
-
-/* Bits 7..0 : Over-read character. */
-#define SPIM_ORC_ORC_Pos (0UL) /*!< Position of ORC field. */
-#define SPIM_ORC_ORC_Msk (0xFFUL << SPIM_ORC_ORC_Pos) /*!< Bit mask of ORC field. */
-
-/* Register: SPIM_POWER */
-/* Description: Peripheral power control. */
-
-/* Bit 0 : Peripheral power control. */
-#define SPIM_POWER_POWER_Pos (0UL) /*!< Position of POWER field. */
-#define SPIM_POWER_POWER_Msk (0x1UL << SPIM_POWER_POWER_Pos) /*!< Bit mask of POWER field. */
-#define SPIM_POWER_POWER_Disabled (0UL) /*!< Module power disabled. */
-#define SPIM_POWER_POWER_Enabled (1UL) /*!< Module power enabled. */
-
 /* Register: SPIM_RXD_PTR */
 /* Description: Data pointer. */
 
@@ -6203,6 +6112,43 @@
 #define SPIM_TXD_AMOUNT_AMOUNT_Pos (0UL) /*!< Position of AMOUNT field. */
 #define SPIM_TXD_AMOUNT_AMOUNT_Msk (0xFFUL << SPIM_TXD_AMOUNT_AMOUNT_Pos) /*!< Bit mask of AMOUNT field. */
 
+/* Register: SPIM_CONFIG */
+/* Description: Configuration register. */
+
+/* Bit 2 : Serial clock (SCK) polarity. */
+#define SPIM_CONFIG_CPOL_Pos (2UL) /*!< Position of CPOL field. */
+#define SPIM_CONFIG_CPOL_Msk (0x1UL << SPIM_CONFIG_CPOL_Pos) /*!< Bit mask of CPOL field. */
+#define SPIM_CONFIG_CPOL_ActiveHigh (0UL) /*!< Active high. */
+#define SPIM_CONFIG_CPOL_ActiveLow (1UL) /*!< Active low. */
+
+/* Bit 1 : Serial clock (SCK) phase. */
+#define SPIM_CONFIG_CPHA_Pos (1UL) /*!< Position of CPHA field. */
+#define SPIM_CONFIG_CPHA_Msk (0x1UL << SPIM_CONFIG_CPHA_Pos) /*!< Bit mask of CPHA field. */
+#define SPIM_CONFIG_CPHA_Leading (0UL) /*!< Sample on leading edge of the clock. Shift serial data on trailing edge. */
+#define SPIM_CONFIG_CPHA_Trailing (1UL) /*!< Sample on trailing edge of the clock. Shift serial data on leading edge. */
+
+/* Bit 0 : Bit order. */
+#define SPIM_CONFIG_ORDER_Pos (0UL) /*!< Position of ORDER field. */
+#define SPIM_CONFIG_ORDER_Msk (0x1UL << SPIM_CONFIG_ORDER_Pos) /*!< Bit mask of ORDER field. */
+#define SPIM_CONFIG_ORDER_MsbFirst (0UL) /*!< Most significant bit transmitted out first. */
+#define SPIM_CONFIG_ORDER_LsbFirst (1UL) /*!< Least significant bit transmitted out first. */
+
+/* Register: SPIM_ORC */
+/* Description: Over-read character. */
+
+/* Bits 7..0 : Over-read character. */
+#define SPIM_ORC_ORC_Pos (0UL) /*!< Position of ORC field. */
+#define SPIM_ORC_ORC_Msk (0xFFUL << SPIM_ORC_ORC_Pos) /*!< Bit mask of ORC field. */
+
+/* Register: SPIM_POWER */
+/* Description: Peripheral power control. */
+
+/* Bit 0 : Peripheral power control. */
+#define SPIM_POWER_POWER_Pos (0UL) /*!< Position of POWER field. */
+#define SPIM_POWER_POWER_Msk (0x1UL << SPIM_POWER_POWER_Pos) /*!< Bit mask of POWER field. */
+#define SPIM_POWER_POWER_Disabled (0UL) /*!< Module power disabled. */
+#define SPIM_POWER_POWER_Enabled (1UL) /*!< Module power enabled. */
+
 
 /* Peripheral: SPIS */
 /* Description: SPI slave 1. */
@@ -6671,6 +6617,13 @@
 #define TWI_ERRORSRC_ANACK_Present (1UL) /*!< Error present. */
 #define TWI_ERRORSRC_ANACK_Clear (1UL) /*!< Clear error on write. */
 
+/* Bit 0 : Byte received in RXD register before read of the last received byte (data loss). */
+#define TWI_ERRORSRC_OVERRUN_Pos (0UL) /*!< Position of OVERRUN field. */
+#define TWI_ERRORSRC_OVERRUN_Msk (0x1UL << TWI_ERRORSRC_OVERRUN_Pos) /*!< Bit mask of OVERRUN field. */
+#define TWI_ERRORSRC_OVERRUN_NotPresent (0UL) /*!< Error not present. */
+#define TWI_ERRORSRC_OVERRUN_Present (1UL) /*!< Error present. */
+#define TWI_ERRORSRC_OVERRUN_Clear (1UL) /*!< Clear error on write. */
+
 /* Register: TWI_ENABLE */
 /* Description: Enable two-wire master. */
 
@@ -6724,21 +6677,6 @@
 /* Peripheral: UART */
 /* Description: Universal Asynchronous Receiver/Transmitter. */
 
-/* Register: UART_SHORTS */
-/* Description: Shortcuts for UART. */
-
-/* Bit 4 : Shortcut between NCTS event and the STOPRX task. */
-#define UART_SHORTS_NCTS_STOPRX_Pos (4UL) /*!< Position of NCTS_STOPRX field. */
-#define UART_SHORTS_NCTS_STOPRX_Msk (0x1UL << UART_SHORTS_NCTS_STOPRX_Pos) /*!< Bit mask of NCTS_STOPRX field. */
-#define UART_SHORTS_NCTS_STOPRX_Disabled (0UL) /*!< Shortcut disabled. */
-#define UART_SHORTS_NCTS_STOPRX_Enabled (1UL) /*!< Shortcut enabled. */
-
-/* Bit 3 : Shortcut between CTS event and the STARTRX task. */
-#define UART_SHORTS_CTS_STARTRX_Pos (3UL) /*!< Position of CTS_STARTRX field. */
-#define UART_SHORTS_CTS_STARTRX_Msk (0x1UL << UART_SHORTS_CTS_STARTRX_Pos) /*!< Bit mask of CTS_STARTRX field. */
-#define UART_SHORTS_CTS_STARTRX_Disabled (0UL) /*!< Shortcut disabled. */
-#define UART_SHORTS_CTS_STARTRX_Enabled (1UL) /*!< Shortcut enabled. */
-
 /* Register: UART_INTENSET */
 /* Description: Interrupt enable set register. */
 
@@ -6903,7 +6841,7 @@
 #define UART_BAUDRATE_BAUDRATE_Baud230400 (0x03AFB000UL) /*!< 230400 baud. */
 #define UART_BAUDRATE_BAUDRATE_Baud250000 (0x04000000UL) /*!< 250000 baud. */
 #define UART_BAUDRATE_BAUDRATE_Baud460800 (0x075F7000UL) /*!< 460800 baud. */
-#define UART_BAUDRATE_BAUDRATE_Baud921600 (0x0EBEDFA4UL) /*!< 921600 baud. */
+#define UART_BAUDRATE_BAUDRATE_Baud921600 (0x0EBED000UL) /*!< 921600 baud. */
 #define UART_BAUDRATE_BAUDRATE_Baud1M (0x10000000UL) /*!< 1M baud. */
 
 /* Register: UART_CONFIG */
@@ -6940,14 +6878,14 @@
 /* Bits 15..8 : Readback protect all code in the device. */
 #define UICR_RBPCONF_PALL_Pos (8UL) /*!< Position of PALL field. */
 #define UICR_RBPCONF_PALL_Msk (0xFFUL << UICR_RBPCONF_PALL_Pos) /*!< Bit mask of PALL field. */
+#define UICR_RBPCONF_PALL_Enabled (0x00UL) /*!< Enabled. */
 #define UICR_RBPCONF_PALL_Disabled (0xFFUL) /*!< Disabled. */
-#define UICR_RBPCONF_PALL_Enabled (0x00UL) /*!< Enabled. */
 
 /* Bits 7..0 : Readback protect region 0. Will be ignored if pre-programmed factory code is present on the chip. */
 #define UICR_RBPCONF_PR0_Pos (0UL) /*!< Position of PR0 field. */
 #define UICR_RBPCONF_PR0_Msk (0xFFUL << UICR_RBPCONF_PR0_Pos) /*!< Bit mask of PR0 field. */
+#define UICR_RBPCONF_PR0_Enabled (0x00UL) /*!< Enabled. */
 #define UICR_RBPCONF_PR0_Disabled (0xFFUL) /*!< Disabled. */
-#define UICR_RBPCONF_PR0_Enabled (0x00UL) /*!< Enabled. */
 
 /* Register: UICR_XTALFREQ */
 /* Description: Reset value for CLOCK XTALFREQ register. */
@@ -6955,8 +6893,8 @@
 /* Bits 7..0 : Reset value for CLOCK XTALFREQ register. */
 #define UICR_XTALFREQ_XTALFREQ_Pos (0UL) /*!< Position of XTALFREQ field. */
 #define UICR_XTALFREQ_XTALFREQ_Msk (0xFFUL << UICR_XTALFREQ_XTALFREQ_Pos) /*!< Bit mask of XTALFREQ field. */
+#define UICR_XTALFREQ_XTALFREQ_32MHz (0x00UL) /*!< 32MHz Xtal is used. */
 #define UICR_XTALFREQ_XTALFREQ_16MHz (0xFFUL) /*!< 16MHz Xtal is used. */
-#define UICR_XTALFREQ_XTALFREQ_32MHz (0x00UL) /*!< 32MHz Xtal is used. */
 
 /* Register: UICR_FWID */
 /* Description: Firmware ID. */
--- a/source/nordic-sdk/components/drivers_nrf/hal/nrf51_deprecated.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nordic-sdk/components/drivers_nrf/hal/nrf51_deprecated.h	Wed Apr 06 22:39:17 2016 +0100
@@ -29,6 +29,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
+
 #ifndef NRF51_DEPRECATED_H
 #define NRF51_DEPRECATED_H
 
@@ -41,13 +42,13 @@
 
 /* NVMC */
 /* The register ERASEPROTECTEDPAGE is called ERASEPCR0 in the documentation. */
-#define ERASEPCR0   ERASEPROTECTEDPAGE
-/* The register ERASEPAGE is also called ERASEPCR1 in the documentation. */
-#define ERASEPCR1   ERASEPAGE
+#define ERASEPROTECTEDPAGE   ERASEPCR0
+
  
 /* LPCOMP */
 /* The interrupt ISR was renamed. Adding old name to the macros. */
 #define LPCOMP_COMP_IRQHandler      LPCOMP_IRQHandler
+#define LPCOMP_COMP_IRQn            LPCOMP_IRQn
  
  
 /* MPU */
--- a/source/nordic-sdk/components/drivers_nrf/hal/nrf_delay.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
- 
-#include <stdio.h> 
-
-#include "nrf.h"
-#include "nrf_delay.h"
-
-/*lint --e{438} "Variable not used" */
-void nrf_delay_ms(uint32_t volatile number_of_ms)
-{
-    while(number_of_ms != 0)
-    {
-        number_of_ms--;
-        nrf_delay_us(999);
-    }
-}
\ No newline at end of file
--- a/source/nordic-sdk/components/drivers_nrf/hal/nrf_ecb.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,92 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/** 
- * @file
- * @brief Implementation of AES ECB driver
- */
-
-
-//lint -e438
-
-#include <stdlib.h>
-#include <stdbool.h>
-#include <string.h>
-#include "nrf.h" 
-#include "nrf_ecb.h"
-
-static uint8_t  ecb_data[48];   ///< ECB data structure for RNG peripheral to access.
-static uint8_t* ecb_key;        ///< Key:        Starts at ecb_data 
-static uint8_t* ecb_cleartext;  ///< Cleartext:  Starts at ecb_data + 16 bytes.
-static uint8_t* ecb_ciphertext; ///< Ciphertext: Starts at ecb_data + 32 bytes.
-
-bool nrf_ecb_init(void)
-{
-  ecb_key = ecb_data;
-  ecb_cleartext  = ecb_data + 16;
-  ecb_ciphertext = ecb_data + 32;
-
-  NRF_ECB->ECBDATAPTR = (uint32_t)ecb_data;
-  return true;
-}
-
-
-bool nrf_ecb_crypt(uint8_t * dest_buf, const uint8_t * src_buf)
-{
-   uint32_t counter = 0x1000000;
-   if(src_buf != ecb_cleartext)
-   {
-     memcpy(ecb_cleartext,src_buf,16);
-   }
-   NRF_ECB->EVENTS_ENDECB = 0;
-   NRF_ECB->TASKS_STARTECB = 1;
-   while(NRF_ECB->EVENTS_ENDECB == 0)
-   {
-    counter--;
-    if(counter == 0)
-    {
-      return false;
-    }
-   }
-   NRF_ECB->EVENTS_ENDECB = 0;
-   if(dest_buf != ecb_ciphertext)
-   {
-     memcpy(dest_buf,ecb_ciphertext,16);
-   }
-   return true;
-}
-
-void nrf_ecb_set_key(const uint8_t * key)
-{
-  memcpy(ecb_key,key,16);
-}
-
--- a/source/nordic-sdk/components/drivers_nrf/hal/nrf_ecb.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/**
- * @file
- * @brief ECB driver API.
- */
-
-#ifndef NRF_ECB_H__
-#define NRF_ECB_H__
-
-/**
- * @defgroup nrf_ecb AES ECB encryption
- * @{
- * @ingroup nrf_drivers
- * @brief Driver for the nRF51 AES Electronic Code Book (ECB) peripheral.
- *
- * In order to encrypt and decrypt data the peripheral must be powered on
- * using nrf_ecb_init() and then the key set using nrf_ecb_set_key.
- */
-
-#include <stdint.h>
-
-/**
- * Initialize and power on the ECB peripheral.
- *
- * Allocates memory for the ECBDATAPTR.
- * @retval true Initialization was successful.
- * @retval false Powering up failed.
- */
-bool nrf_ecb_init(void);
-
-/**
- * Encrypt/decrypt 16-byte data using current key.
- *
- * The function avoids unnecessary copying of data if the point to the 
- * correct locations in the ECB data structure.
- *
- * @param dst Result of encryption/decryption. 16 bytes will be written. 
- * @param src Source with 16-byte data to be encrypted/decrypted.
- *
- * @retval true  If the encryption operation completed.
- * @retval false If the encryption operation did not complete.
- */
-bool nrf_ecb_crypt(uint8_t * dst, const uint8_t * src);
-
-/**
- * Set the key to be used for encryption/decryption.
- *
- * @param key Pointer to key. 16 bytes will be read.
- */
-void nrf_ecb_set_key(const uint8_t * key);
-
-#endif  // NRF_ECB_H__
-
-/** @} */
\ No newline at end of file
--- a/source/nordic-sdk/components/drivers_nrf/hal/nrf_gpio.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,454 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#ifndef NRF_GPIO_H__
-#define NRF_GPIO_H__
-
-#include "nrf51.h"
-#include "nrf51_bitfields.h"
-
-/**
- * @defgroup nrf_gpio GPIO abstraction
- * @{
- * @ingroup nrf_drivers
- * @brief GPIO pin abstraction and port abstraction for reading and writing byte-wise to GPIO ports.
- *
- * Here, the GPIO ports are defined as follows:
- * - Port 0 -> pin 0-7
- * - Port 1 -> pin 8-15
- * - Port 2 -> pin 16-23
- * - Port 3 -> pin 24-31
- */
-
-/**
- * @enum nrf_gpio_port_dir_t
- * @brief Enumerator used for setting the direction of a GPIO port.
- */
-typedef enum
-{
-    NRF_GPIO_PORT_DIR_OUTPUT,       ///<  Output
-    NRF_GPIO_PORT_DIR_INPUT         ///<  Input
-} nrf_gpio_port_dir_t;
-
-/**
- * @enum nrf_gpio_pin_dir_t
- * Pin direction definitions.
- */
-typedef enum
-{
-    NRF_GPIO_PIN_DIR_INPUT,   ///< Input
-    NRF_GPIO_PIN_DIR_OUTPUT   ///< Output
-} nrf_gpio_pin_dir_t;
-
-/**
- * @enum nrf_gpio_port_select_t
- * @brief Enumerator used for selecting between port 0 - 3.
- */
-typedef enum
-{
-    NRF_GPIO_PORT_SELECT_PORT0 = 0,           ///<  Port 0 (GPIO pin 0-7)
-    NRF_GPIO_PORT_SELECT_PORT1,               ///<  Port 1 (GPIO pin 8-15)
-    NRF_GPIO_PORT_SELECT_PORT2,               ///<  Port 2 (GPIO pin 16-23)
-    NRF_GPIO_PORT_SELECT_PORT3,               ///<  Port 3 (GPIO pin 24-31)
-} nrf_gpio_port_select_t;
-
-/**
- * @enum nrf_gpio_pin_pull_t
- * @brief Enumerator used for selecting the pin to be pulled down or up at the time of pin configuration
- */
-typedef enum
-{
-    NRF_GPIO_PIN_NOPULL   = GPIO_PIN_CNF_PULL_Disabled,                 ///<  Pin pullup resistor disabled
-    NRF_GPIO_PIN_PULLDOWN = GPIO_PIN_CNF_PULL_Pulldown,                 ///<  Pin pulldown resistor enabled
-    NRF_GPIO_PIN_PULLUP   = GPIO_PIN_CNF_PULL_Pullup,                   ///<  Pin pullup resistor enabled
-} nrf_gpio_pin_pull_t;
-
-/**
- * @enum nrf_gpio_pin_sense_t
- * @brief Enumerator used for selecting the pin to sense high or low level on the pin input.
- */
-typedef enum
-{
-    NRF_GPIO_PIN_NOSENSE    = GPIO_PIN_CNF_SENSE_Disabled,              ///<  Pin sense level disabled.
-    NRF_GPIO_PIN_SENSE_LOW  = GPIO_PIN_CNF_SENSE_Low,                   ///<  Pin sense low level.
-    NRF_GPIO_PIN_SENSE_HIGH = GPIO_PIN_CNF_SENSE_High,                  ///<  Pin sense high level.
-} nrf_gpio_pin_sense_t;
-
-/**
- * @brief Function for configuring the GPIO pin range as outputs with normal drive strength.
- *        This function can be used to configure pin range as simple output with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
- *
- * @param pin_range_start specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30)
- *
- * @param pin_range_end specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30)
- *
- * @note For configuring only one pin as output use @ref nrf_gpio_cfg_output
- *       Sense capability on the pin is disabled, and input is disconnected from the buffer as the pins are configured as output.
- */
-static __INLINE void nrf_gpio_range_cfg_output(uint32_t pin_range_start, uint32_t pin_range_end)
-{
-    /*lint -e{845} // A zero has been given as right argument to operator '|'" */
-    for (; pin_range_start <= pin_range_end; pin_range_start++)
-    {
-        NRF_GPIO->PIN_CNF[pin_range_start] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
-                                        | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
-                                        | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
-                                        | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
-                                        | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
-    }
-}
-
-/**
- * @brief Function for configuring the GPIO pin range as inputs with given initial value set, hiding inner details.
- *        This function can be used to configure pin range as simple input.
- *
- * @param pin_range_start specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30)
- *
- * @param pin_range_end specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30)
- *
- * @param pull_config State of the pin range pull resistor (no pull, pulled down or pulled high)
- *
- * @note  For configuring only one pin as input use @ref nrf_gpio_cfg_input
- *        Sense capability on the pin is disabled, and input is connected to buffer so that the GPIO->IN register is readable
- */
-static __INLINE void nrf_gpio_range_cfg_input(uint32_t pin_range_start, uint32_t pin_range_end, nrf_gpio_pin_pull_t pull_config)
-{
-    /*lint -e{845} // A zero has been given as right argument to operator '|'" */
-    for (; pin_range_start <= pin_range_end; pin_range_start++)
-    {
-        NRF_GPIO->PIN_CNF[pin_range_start] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
-                                        | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
-                                        | (pull_config << GPIO_PIN_CNF_PULL_Pos)
-                                        | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
-                                        | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
-    }
-}
-
-/**
- * @brief Function for configuring the given GPIO pin number as output with given initial value set, hiding inner details.
- *        This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
- *
- * @param pin_number specifies the pin number of gpio pin numbers to be configured (allowed values 0-30)
- *
- * @note  Sense capability on the pin is disabled, and input is disconnected from the buffer as the pins are configured as output.
- */
-static __INLINE void nrf_gpio_cfg_output(uint32_t pin_number)
-{
-    /*lint -e{845} // A zero has been given as right argument to operator '|'" */
-    NRF_GPIO->PIN_CNF[pin_number] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
-                                            | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
-                                            | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
-                                            | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
-                                            | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
-}
-
-/**
- * @brief Function for configuring the given GPIO pin number as input with given initial value set, hiding inner details.
- *        This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
- *
- * @param pin_number specifies the pin number of gpio pin numbers to be configured (allowed values 0-30)
- *
- * @param pull_config State of the pin range pull resistor (no pull, pulled down or pulled high)
- *
- * @note  Sense capability on the pin is disabled, and input is connected to buffer so that the GPIO->IN register is readable
- */
-static __INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config)
-{
-    /*lint -e{845} // A zero has been given as right argument to operator '|'" */
-    NRF_GPIO->PIN_CNF[pin_number] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
-                                        | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
-                                        | (pull_config << GPIO_PIN_CNF_PULL_Pos)
-                                        | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
-                                        | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
-}
-
-/**
- * @brief Function for configuring the given GPIO pin number as input with given initial value set, hiding inner details.
- *        This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
- *        Sense capability on the pin is configurable, and input is connected to buffer so that the GPIO->IN register is readable.
- *
- * @param pin_number specifies the pin number of gpio pin numbers to be configured (allowed values 0-30).
- *
- * @param pull_config state of the pin pull resistor (no pull, pulled down or pulled high).
- *
- * @param sense_config sense level of the pin (no sense, sense low or sense high).
- */
-static __INLINE void nrf_gpio_cfg_sense_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config, nrf_gpio_pin_sense_t sense_config)
-{
-    /*lint -e{845} // A zero has been given as right argument to operator '|'" */
-    NRF_GPIO->PIN_CNF[pin_number] = (sense_config << GPIO_PIN_CNF_SENSE_Pos)
-                                        | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
-                                        | (pull_config << GPIO_PIN_CNF_PULL_Pos)
-                                        | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
-                                        | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
-}
-
-/**
- * @brief Function for setting the direction for a GPIO pin.
- *
- * @param pin_number specifies the pin number [0:31] for which to
- * set the direction.
- *
- * @param direction specifies the direction
- */
-static __INLINE void nrf_gpio_pin_dir_set(uint32_t pin_number, nrf_gpio_pin_dir_t direction)
-{
-    if(direction == NRF_GPIO_PIN_DIR_INPUT)
-    {
-        NRF_GPIO->PIN_CNF[pin_number] =
-          (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
-        | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
-        | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
-        | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
-        | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
-    }
-    else
-    {
-        NRF_GPIO->DIRSET = (1UL << pin_number);
-    }
-}
-
-/**
- * @brief Function for setting a GPIO pin.
- *
- * Note that the pin must be configured as an output for this
- * function to have any effect.
- *
- * @param pin_number specifies the pin number [0:31] to
- * set.
- */
-static __INLINE void nrf_gpio_pin_set(uint32_t pin_number)
-{
-    NRF_GPIO->OUTSET = (1UL << pin_number);
-}
-
-/**
- * @brief Function for clearing a GPIO pin.
- *
- * Note that the pin must be configured as an output for this
- * function to have any effect.
- *
- * @param pin_number specifies the pin number [0:31] to
- * clear.
- */
-static __INLINE void nrf_gpio_pin_clear(uint32_t pin_number)
-{
-    NRF_GPIO->OUTCLR = (1UL << pin_number);
-}
-
-/**
- * @brief Function for toggling a GPIO pin.
- *
- * Note that the pin must be configured as an output for this
- * function to have any effect.
- *
- * @param pin_number specifies the pin number [0:31] to
- * toggle.
- */
-static __INLINE void nrf_gpio_pin_toggle(uint32_t pin_number)
-{
-    const uint32_t pin_bit   = 1UL << pin_number;
-    const uint32_t pin_state = ((NRF_GPIO->OUT >> pin_number) & 1UL);
-    
-    if (pin_state == 0)
-    {
-        // Current state low, set high.
-        NRF_GPIO->OUTSET = pin_bit;        
-    }
-    else
-    {
-        // Current state high, set low.    
-        NRF_GPIO->OUTCLR = pin_bit;       
-    }
-}
-
-/**
- * @brief Function for writing a value to a GPIO pin.
- *
- * Note that the pin must be configured as an output for this
- * function to have any effect.
- *
- * @param pin_number specifies the pin number [0:31] to
- * write.
- *
- * @param value specifies the value to be written to the pin.
- * @arg 0 clears the pin
- * @arg >=1 sets the pin.
- */
-static __INLINE void nrf_gpio_pin_write(uint32_t pin_number, uint32_t value)
-{
-    if (value == 0)
-    {
-        nrf_gpio_pin_clear(pin_number);
-    }
-    else
-    {
-        nrf_gpio_pin_set(pin_number);
-    }
-}
-
-/**
- * @brief Function for reading the input level of a GPIO pin.
- *
- * Note that the pin must have input connected for the value
- * returned from this function to be valid.
- *
- * @param pin_number specifies the pin number [0:31] to
- * read.
- *
- * @return
- * @retval 0 if the pin input level is low.
- * @retval 1 if the pin input level is high.
- * @retval > 1 should never occur.
- */
-static __INLINE uint32_t nrf_gpio_pin_read(uint32_t pin_number)
-{
-    return  ((NRF_GPIO->IN >> pin_number) & 1UL);
-}
-
-/**
- * @brief Generic function for writing a single byte of a 32 bit word at a given
- * address.
- *
- * This function should not be called from outside the nrf_gpio
- * abstraction layer.
- *
- * @param word_address is the address of the word to be written.
- *
- * @param byte_no is the the word byte number (0-3) to be written.
- *
- * @param value is the value to be written to byte "byte_no" of word
- * at address "word_address"
- */
-static __INLINE void nrf_gpio_word_byte_write(volatile uint32_t * word_address, uint8_t byte_no, uint8_t value)
-{
-    *((volatile uint8_t*)(word_address) + byte_no) = value;
-}
-
-/**
- * @brief Generic function for reading a single byte of a 32 bit word at a given
- * address.
- *
- * This function should not be called from outside the nrf_gpio
- * abstraction layer.
- *
- * @param word_address is the address of the word to be read.
- *
- * @param byte_no is the the byte number (0-3) of the word to be read.
- *
- * @return byte "byte_no" of word at address "word_address".
- */
-static __INLINE uint8_t nrf_gpio_word_byte_read(const volatile uint32_t* word_address, uint8_t byte_no)
-{
-    return (*((const volatile uint8_t*)(word_address) + byte_no));
-}
-
-/**
- * @brief Function for setting the direction of a port.
- *
- * @param port is the port for which to set the direction.
- *
- * @param dir direction to be set for this port.
- */
-static __INLINE void nrf_gpio_port_dir_set(nrf_gpio_port_select_t port, nrf_gpio_port_dir_t dir)
-{
-    if (dir == NRF_GPIO_PORT_DIR_OUTPUT)
-    {
-        nrf_gpio_word_byte_write(&NRF_GPIO->DIRSET, port, 0xFF);
-    }
-    else
-    {
-        nrf_gpio_range_cfg_input(port*8, (port+1)*8-1, NRF_GPIO_PIN_NOPULL);
-    }
-}
-
-/**
- * @brief Function for reading a GPIO port.
- *
- * @param port is the port to read.
- *
- * @return the input value on this port.
- */
-static __INLINE uint8_t nrf_gpio_port_read(nrf_gpio_port_select_t port)
-{
-    return nrf_gpio_word_byte_read(&NRF_GPIO->IN, port);
-}
-
-/**
- * @brief Function for writing to a GPIO port.
- *
- * @param port is the port to write.
- *
- * @param value is the value to write to this port.
- *
- * @sa nrf_gpio_port_dir_set()
- */
-static __INLINE void nrf_gpio_port_write(nrf_gpio_port_select_t port, uint8_t value)
-{
-    nrf_gpio_word_byte_write(&NRF_GPIO->OUT, port, value);
-}
-
-/**
- * @brief Function for setting individual pins on GPIO port.
- *
- * @param port is the port for which to set the pins.
- *
- * @param set_mask is a mask specifying which pins to set. A bit
- * set to 1 indicates that the corresponding port pin shall be
- * set.
- *
- * @sa nrf_gpio_port_dir_set()
- */
-static __INLINE void nrf_gpio_port_set(nrf_gpio_port_select_t port, uint8_t set_mask)
-{
-    nrf_gpio_word_byte_write(&NRF_GPIO->OUTSET, port, set_mask);
-}
-
-/**
- * @brief Function for clearing individual pins on GPIO port.
- *
- * @param port is the port for which to clear the pins.
- *
- * @param clr_mask is a mask specifying which pins to clear. A bit
- * set to 1 indicates that the corresponding port pin shall be
- * cleared.
- *
- * @sa nrf_gpio_port_dir_set()
- */
-static __INLINE void nrf_gpio_port_clear(nrf_gpio_port_select_t port, uint8_t clr_mask)
-{
-    nrf_gpio_word_byte_write(&NRF_GPIO->OUTCLR, port, clr_mask);
-}
-
-/** @} */
-
-#endif
\ No newline at end of file
--- a/source/nordic-sdk/components/drivers_nrf/hal/nrf_gpiote.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,173 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-#ifndef NRF_GPIOTE_H__
-#define NRF_GPIOTE_H__
-
-#include "nrf.h"
-
-/**
-* @defgroup nrf_gpiote GPIOTE abstraction
-* @{
-* @ingroup nrf_drivers
-* @brief GPIOTE abstraction for configuration of channels.
-*/
-
-
- /**
- * @enum nrf_gpiote_polarity_t
- * @brief Polarity for GPIOTE channel enumerator.
- */
-typedef enum
-{
-  NRF_GPIOTE_POLARITY_LOTOHI = GPIOTE_CONFIG_POLARITY_LoToHi,       ///<  Low to high
-  NRF_GPIOTE_POLARITY_HITOLO = GPIOTE_CONFIG_POLARITY_HiToLo,       ///<  High to low
-  NRF_GPIOTE_POLARITY_TOGGLE = GPIOTE_CONFIG_POLARITY_Toggle        ///<  Toggle
-} nrf_gpiote_polarity_t;
-
-
- /**
- * @enum nrf_gpiote_outinit_t
- * @brief Initial output value for GPIOTE channel enumerator.
- */
-typedef enum
-{
-  NRF_GPIOTE_INITIAL_VALUE_LOW  = GPIOTE_CONFIG_OUTINIT_Low,       ///<  Low to high
-  NRF_GPIOTE_INITIAL_VALUE_HIGH = GPIOTE_CONFIG_OUTINIT_High       ///<  High to low
-} nrf_gpiote_outinit_t;
-
-
-/**
- * @brief Function for configuring GPIOTE channel as output, setting the properly desired output level.
- *
- *
- * @param channel_number specifies the GPIOTE channel [0:3] to configure as an output channel.
- * @param pin_number specifies the pin number [0:30] to use in the GPIOTE channel.
- * @param polarity specifies the desired polarity in the output GPIOTE channel.
- * @param initial_value specifies the initial value of the GPIOTE channel input after the channel configuration.
- */
-static __INLINE void nrf_gpiote_task_config(uint32_t channel_number, uint32_t pin_number, nrf_gpiote_polarity_t polarity, nrf_gpiote_outinit_t initial_value)
-{
-    /* Check if the output desired is high or low */
-    if (initial_value == NRF_GPIOTE_INITIAL_VALUE_LOW)
-    {
-        /* Workaround for the OUTINIT PAN. When nrf_gpiote_task_config() is called a glitch happens
-        on the GPIO if the GPIO in question is already assigned to GPIOTE and the pin is in the 
-        correct state in GPIOTE but not in the OUT register. */
-        NRF_GPIO->OUTCLR = (1 << pin_number);
-        
-        /* Configure channel to Pin31, not connected to the pin, and configure as a tasks that will set it to proper level */
-        NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Task       << GPIOTE_CONFIG_MODE_Pos)     |
-                                             (31UL                          << GPIOTE_CONFIG_PSEL_Pos)     |
-                                             (GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos);                                    
-    } 
-    else 
-    {
-        /* Workaround for the OUTINIT PAN. When nrf_gpiote_task_config() is called a glitch happens
-        on the GPIO if the GPIO in question is already assigned to GPIOTE and the pin is in the 
-        correct state in GPIOTE but not in the OUT register. */
-        NRF_GPIO->OUTSET = (1 << pin_number);
-        
-        /* Configure channel to Pin31, not connected to the pin, and configure as a tasks that will set it to proper level */
-        NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Task       << GPIOTE_CONFIG_MODE_Pos)     |
-                                             (31UL                          << GPIOTE_CONFIG_PSEL_Pos)     |
-                                             (GPIOTE_CONFIG_POLARITY_LoToHi << GPIOTE_CONFIG_POLARITY_Pos);
-    }
-
-    /* Three NOPs are required to make sure configuration is written before setting tasks or getting events */
-    __NOP();
-    __NOP();
-    __NOP(); 
-
-    /* Launch the task to take the GPIOTE channel output to the desired level */
-    NRF_GPIOTE->TASKS_OUT[channel_number] = 1;
-    
-
-    /* Finally configure the channel as the caller expects. If OUTINIT works, the channel is configured properly. 
-       If it does not, the channel output inheritance sets the proper level. */
-    NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos)     |
-                                         ((uint32_t)pin_number    << GPIOTE_CONFIG_PSEL_Pos)     |
-                                         ((uint32_t)polarity      << GPIOTE_CONFIG_POLARITY_Pos) |
-                                         ((uint32_t)initial_value << GPIOTE_CONFIG_OUTINIT_Pos);
-
-    /* Three NOPs are required to make sure configuration is written before setting tasks or getting events */
-    __NOP();
-    __NOP();
-    __NOP(); 
-}
-
-/**
- * @brief Function for configuring GPIOTE channel as input, automatically clearing an event that appears in some cases under configuration.
- *
- * Note that when configuring the channel as input an event might be triggered. Care of disabling interrupts
- * for that channel is left to the user.
- *
- * @param channel_number specifies the GPIOTE channel [0:3] to configure as an input channel.
- * @param pin_number specifies the pin number [0:30] to use in the GPIOTE channel.
- * @param polarity specifies the desired polarity in the output GPIOTE channel.
- */
-static __INLINE void nrf_gpiote_event_config(uint32_t channel_number, uint32_t pin_number, nrf_gpiote_polarity_t polarity)
-{   
-    /* Configure the channel as the caller expects */
-    NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos)     |
-                                         ((uint32_t)pin_number     << GPIOTE_CONFIG_PSEL_Pos)     |
-                                         ((uint32_t)polarity       << GPIOTE_CONFIG_POLARITY_Pos);
-
-    /* Three NOPs are required to make sure configuration is written before setting tasks or getting events */
-    __NOP();
-    __NOP();
-    __NOP();
-    
-    /* Clear the event that appears in some cases */
-    NRF_GPIOTE->EVENTS_IN[channel_number] = 0; 
-}
-
-
-/**
- * @brief Function for unconfiguring GPIOTE channel.
- *
- *
- * Note that when unconfiguring the channel, the pin is configured as GPIO PIN_CNF configuration.
- *
- * @param channel_number specifies the GPIOTE channel [0:3] to unconfigure.
- */
-static __INLINE void nrf_gpiote_unconfig(uint32_t channel_number)
-{   
-    /* Unonfigure the channel as the caller expects */
-    NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Disabled   << GPIOTE_CONFIG_MODE_Pos) |
-                                         (31UL                          << GPIOTE_CONFIG_PSEL_Pos) |
-                                         (GPIOTE_CONFIG_POLARITY_Toggle << GPIOTE_CONFIG_POLARITY_Pos);
-}
-
-
-/** @} */
-
-#endif
\ No newline at end of file
--- a/source/nordic-sdk/components/drivers_nrf/hal/nrf_nvmc.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,135 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/** 
- *@file
- *@brief NMVC driver implementation 
- */
-
-#include "stdbool.h"
-#include "nrf.h"
-#include "nrf_nvmc.h"
-
-
-void nrf_nvmc_page_erase(uint32_t address)
-{ 
-  // Enable erase.
-  NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Een;
-  while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
-  {
-  }
-
-  // Erase the page
-  NRF_NVMC->ERASEPAGE = address;
-  while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
-  {
-  }
-  
-  NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
-  while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
-  {
-  }
-}
-
-
-void nrf_nvmc_write_byte(uint32_t address, uint8_t value)
-{
-  uint32_t byte_shift = address & (uint32_t)0x03;
-  uint32_t address32 = address & ~byte_shift; // Address to the word this byte is in.
-  uint32_t value32 = (*(uint32_t*)address32 & ~((uint32_t)0xFF << (byte_shift << (uint32_t)3)));
-  value32 = value32 + ((uint32_t)value << (byte_shift << 3));
-
-  // Enable write.
-  NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos);
-  while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
-  {
-  }
-
-  *(uint32_t*)address32 = value32;
-  while(NRF_NVMC->READY == NVMC_READY_READY_Busy)
-  {
-  }
-
-  NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
-  {
-  }
-}
-
-void nrf_nvmc_write_word(uint32_t address, uint32_t value)
-{
-  // Enable write.
-  NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
-  while (NRF_NVMC->READY == NVMC_READY_READY_Busy){
-  }
-
-  *(uint32_t*)address = value;
-  while (NRF_NVMC->READY == NVMC_READY_READY_Busy){
-  }
-
-  NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
-  while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
-  {
-  }
-}
-
-void nrf_nvmc_write_bytes(uint32_t address, const uint8_t * src, uint32_t num_bytes)
-{
-  uint32_t i;
-  for(i=0;i<num_bytes;i++)
-  {
-     nrf_nvmc_write_byte(address+i,src[i]);
-  }
-}
-
-void nrf_nvmc_write_words(uint32_t address, const uint32_t * src, uint32_t num_words)
-{
-  uint32_t i;
-
-  // Enable write.
-  NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
-  while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
-  {
-  }
-
-  for(i=0;i<num_words;i++)
-  {
-    ((uint32_t*)address)[i] = src[i];
-    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
-    {
-    }
-  }
-
-  NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
-  while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
-  {
-  }
-}
--- a/source/nordic-sdk/components/drivers_nrf/hal/nrf_nvmc.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,108 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/**
- * @file
- * @brief NMVC driver API.
- */
-
-#ifndef NRF_NVMC_H__
-#define NRF_NVMC_H__
-
-#include <stdint.h>
-
-
-/**
- * @defgroup nrf_nvmc Non-volatile memory controller
- * @{
- * @ingroup nrf_drivers
- * @brief Driver for the nRF51 NVMC peripheral.
- *
- * This driver allows writing to the non-volatile memory (NVM) regions
- * of the nRF51. In order to write to NVM the controller must be powered
- * on and the relevant page must be erased.
- *
- */
-
-
-/**
- * @brief Erase a page in flash. This is required before writing to any
- * address in the page.
- *
- * @param address Start address of the page. 
- */
-void nrf_nvmc_page_erase(uint32_t address);
-
-
-/**
- * @brief Write a single byte to flash.
- *
- * The function reads the word containing the byte, and then
- * rewrites the entire word.
- *
- * @param address Address to write to.
- * @param value   Value to write.
- */
-void nrf_nvmc_write_byte(uint32_t address , uint8_t value);
-
-
-/**
- * @brief Write a 32-bit word to flash. 
- * @param address Address to write to.
- * @param value   Value to write.
- */
-void nrf_nvmc_write_word(uint32_t address, uint32_t value);
-
-
-/**
- * @brief Write consecutive bytes to flash.
- *
- * @param address   Address to write to.
- * @param src       Pointer to data to copy from.
- * @param num_bytes Number of bytes in src to write.
- */
-void nrf_nvmc_write_bytes(uint32_t  address, const uint8_t * src, uint32_t num_bytes);
-
-
-/**
- * @brief Write consecutive words to flash.
- * 
- * @param address   Address to write to.
- * @param src       Pointer to data to copy from.
- * @param num_words Number of bytes in src to write.
- */
-void nrf_nvmc_write_words(uint32_t address, const uint32_t * src, uint32_t num_words);
-
-
-#endif // NRF_NVMC_H__
-/** @} */
-
--- a/source/nordic-sdk/components/drivers_nrf/hal/nrf_temp.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,81 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#ifndef NRF_TEMP_H__
-#define NRF_TEMP_H__
-
-#include "nrf51.h"
-
-/**
-* @defgroup nrf_temperature TEMP (temperature) abstraction
-* @{
-* @ingroup nrf_drivers temperature_example
-* @brief Temperature module init and read functions.
-*
-*/
-
-
-
-/**
- * @brief Function for preparing the temp module for temperature measurement.
- *
- * This function initializes the TEMP module and writes to the hidden configuration register.
- * 
- * @param none
- */
-static __INLINE void nrf_temp_init(void)
-{
-    /**@note Workaround for PAN_028 rev2.0A anomaly 31 - TEMP: Temperature offset value has to be manually loaded to the TEMP module */
-    *(uint32_t *) 0x4000C504 = 0;
-}
-
-
-
-#define MASK_SIGN           (0x00000200UL)
-#define MASK_SIGN_EXTENSION (0xFFFFFC00UL)
-
-/**
- * @brief Function for reading temperature measurement.
- *
- * The function reads the 10 bit 2's complement value and transforms it to a 32 bit 2's complement value.
- * 
- * @param none
- */
-static __INLINE int32_t nrf_temp_read(void)
-{    
-    /**@note Workaround for PAN_028 rev2.0A anomaly 28 - TEMP: Negative measured values are not represented correctly */
-    return ((NRF_TEMP->TEMP & MASK_SIGN) != 0) ? (NRF_TEMP->TEMP | MASK_SIGN_EXTENSION) : (NRF_TEMP->TEMP);    
-}
-
-/** @} */
-
-#endif
\ No newline at end of file
--- a/source/nordic-sdk/components/drivers_nrf/pstorage/config/pstorage_platform.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
- /** @cond To make doxygen skip this file */
-
-/** @file
- *  This header contains defines with respect persistent storage that are specific to
- *  persistent storage implementation and application use case.
- */
-#ifndef PSTORAGE_PL_H__
-#define PSTORAGE_PL_H__
-
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif // #ifdef __cplusplus
-
-#define PSTORAGE_FLASH_PAGE_SIZE    ((uint16_t)NRF_FICR->CODEPAGESIZE)   /**< Size of one flash page. */
-#define PSTORAGE_FLASH_EMPTY_MASK    0xFFFFFFFF                          /**< Bit mask that defines an empty address in flash. */
-
-#define PSTORAGE_FLASH_PAGE_END                                     \
-        ((NRF_UICR->BOOTLOADERADDR != PSTORAGE_FLASH_EMPTY_MASK)    \
-        ? (NRF_UICR->BOOTLOADERADDR / PSTORAGE_FLASH_PAGE_SIZE)     \
-        : NRF_FICR->CODESIZE)
-
-
-#define PSTORAGE_MAX_APPLICATIONS   1                                                           /**< Maximum number of applications that can be registered with the module, configurable based on system requirements. */
-#define PSTORAGE_MIN_BLOCK_SIZE     0x0010                                                      /**< Minimum size of block that can be registered with the module. Should be configured based on system requirements, recommendation is not have this value to be at least size of word. */
-
-#define PSTORAGE_DATA_START_ADDR    ((PSTORAGE_FLASH_PAGE_END - PSTORAGE_MAX_APPLICATIONS - 1) \
-                                    * PSTORAGE_FLASH_PAGE_SIZE)                                 /**< Start address for persistent data, configurable according to system requirements. */
-#define PSTORAGE_DATA_END_ADDR      ((PSTORAGE_FLASH_PAGE_END - 1) * PSTORAGE_FLASH_PAGE_SIZE)  /**< End address for persistent data, configurable according to system requirements. */
-#define PSTORAGE_SWAP_ADDR          PSTORAGE_DATA_END_ADDR                                      /**< Top-most page is used as swap area for clear and update. */
-
-#define PSTORAGE_MAX_BLOCK_SIZE     PSTORAGE_FLASH_PAGE_SIZE                                    /**< Maximum size of block that can be registered with the module. Should be configured based on system requirements. And should be greater than or equal to the minimum size. */
-#define PSTORAGE_CMD_QUEUE_SIZE     2                                                           /**< Maximum number of flash access commands that can be maintained by the module for all applications. Configurable. */
-
-
-/** Abstracts persistently memory block identifier. */
-typedef uint32_t pstorage_block_t;
-
-typedef struct
-{
-    uint32_t            module_id;      /**< Module ID.*/
-    pstorage_block_t    block_id;       /**< Block ID.*/
-} pstorage_handle_t;
-
-typedef uint16_t pstorage_size_t;      /** Size of length and offset fields. */
-
-/**@brief Handles Flash Access Result Events. To be called in the system event dispatcher of the application. */
-void pstorage_sys_event_handler (uint32_t sys_evt);
-
-#ifdef __cplusplus
-}
-#endif // #ifdef __cplusplus
-
-#endif // PSTORAGE_PL_H__
-
-/** @} */
-/** @endcond */
\ No newline at end of file
--- a/source/nordic-sdk/components/drivers_nrf/pstorage/pstorage.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1141 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "pstorage.h"
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include "nordic_common.h"
-#include "nrf_error.h"
-#include "nrf_assert.h"
-// #include "nrf.h"
-#include "nrf_soc.h"
-#include "app_util.h"
-
-#define INVALID_OPCODE     0x00                            /**< Invalid op code identifier. */
-#define SOC_MAX_WRITE_SIZE 1024                            /**< Maximum write size allowed for a single call to \ref sd_flash_write as specified in the SoC API. */
-#define RAW_MODE_APP_ID    (PSTORAGE_MAX_APPLICATIONS + 1) /**< Application id for raw mode. */
-
-/**
- * @defgroup api_param_check API Parameters check macros.
- *
- * @details Macros that verify parameters passed to the module in the APIs. These macros
- *          could be mapped to nothing in final versions of code to save execution and size.
- *
- * @{
- */
-
-/**
- * @brief Check if the input pointer is NULL, if it is returns NRF_ERROR_NULL.
- */
-#define NULL_PARAM_CHECK(PARAM)                                                                   \
-        if ((PARAM) == NULL)                                                                      \
-        {                                                                                         \
-            return NRF_ERROR_NULL;                                                                \
-        }
-
-/**
- * @brief Verifies the module identifier supplied by the application is within permissible
- *        range.
- */
-#define MODULE_ID_RANGE_CHECK(ID)                                                                 \
-        if ((((ID)->module_id) >= PSTORAGE_MAX_APPLICATIONS) ||                                   \
-            (m_app_table[(ID)->module_id].cb == NULL))                                            \
-        {                                                                                         \
-            return NRF_ERROR_INVALID_PARAM;                                                       \
-        }
-
-/**
- * @brief Verifies the block identifier supplied by the application is within the permissible
- *        range.
- */
-#define BLOCK_ID_RANGE_CHECK(ID)                                                                  \
-        if (((ID)->block_id) >= (m_app_table[(ID)->module_id].base_id +                           \
-            (m_app_table[(ID)->module_id].block_count * MODULE_BLOCK_SIZE(ID))))                  \
-        {                                                                                         \
-            return NRF_ERROR_INVALID_PARAM;                                                       \
-        }
-
-/**
- * @brief Verifies the block size requested by the application can be supported by the module.
- */
-#define BLOCK_SIZE_CHECK(X)                                                                       \
-        if (((X) > PSTORAGE_MAX_BLOCK_SIZE) || ((X) < PSTORAGE_MIN_BLOCK_SIZE))                   \
-        {                                                                                         \
-            return NRF_ERROR_INVALID_PARAM;                                                       \
-        }
-
-/**
- * @brief Verifies block size requested by Application in registration API.
- */
-#define BLOCK_COUNT_CHECK(COUNT, SIZE)                                                            \
-        if (((COUNT) == 0) ||                                                                     \
-            ((m_next_page_addr + ((COUNT) *(SIZE)) > PSTORAGE_SWAP_ADDR)) ||                      \
-            ((((COUNT) * (SIZE)) > PSTORAGE_FLASH_PAGE_SIZE) && (PSTORAGE_FLASH_PAGE_SIZE % (SIZE))))  \
-        {                                                                                         \
-            return NRF_ERROR_INVALID_PARAM;                                                       \
-        }
-
-/**
- * @brief Verifies size parameter provided by application in API.
- */
-#define SIZE_CHECK(ID, SIZE)                                                                      \
-        if(((SIZE) == 0) || ((SIZE) > MODULE_BLOCK_SIZE(ID)))                                     \
-        {                                                                                         \
-            return NRF_ERROR_INVALID_PARAM;                                                       \
-        }
-
-/**
- * @brief Verifies offset parameter provided by application in API.
- */
-#define OFFSET_CHECK(ID, OFFSET, SIZE)                                                            \
-        if(((SIZE) + (OFFSET)) > MODULE_BLOCK_SIZE(ID))                                           \
-        {                                                                                         \
-            return NRF_ERROR_INVALID_PARAM;                                                       \
-        }
-
-#ifdef PSTORAGE_RAW_MODE_ENABLE
-
-/**
- * @brief Verifies the module identifier supplied by the application is registered for raw mode.
- */
-#define MODULE_RAW_ID_RANGE_CHECK(ID)                                                             \
-        if ((PSTORAGE_MAX_APPLICATIONS+1 != ((ID)->module_id)) ||                                 \
-            (m_raw_app_table.cb == NULL))                                                         \
-        {                                                                                         \
-            return NRF_ERROR_INVALID_PARAM;                                                       \
-        }
-
-#endif // PSTORAGE_RAW_MODE_ENABLE
-
-/**@} */
-
-
-/**@brief    Verify module's initialization status.
- *
- * @details   Verify module's initialization status. Returns NRF_ERROR_INVALID_STATE in case a
- *            module API is called without initializing the module.
- */
-#define VERIFY_MODULE_INITIALIZED()                                                               \
-        do                                                                                        \
-        {                                                                                         \
-            if (!m_module_initialized)                                                            \
-            {                                                                                     \
-                 return NRF_ERROR_INVALID_STATE;                                                  \
-            }                                                                                     \
-        } while(0)
-
-/**@brief Macro to fetch the block size registered for the module. */
-#define MODULE_BLOCK_SIZE(ID) (m_app_table[(ID)->module_id].block_size)
-
-
-/** @brief States for the Update/Clear swap backup state machine. */
-typedef enum
-{
-    STATE_INIT,                /**< State for indicating that swap can be used when using update/clear API. */
-    STATE_DATA_TO_SWAP_WRITE,  /**< State for doing backup of data page into the swap page when using update/clear API. */
-    STATE_DATA_ERASE,          /**< State for erasing data page when using update/clear API. */
-    STATE_HEAD_RESTORE,        /**< State for restoring head (beginning) of backed up data from swap to data page when using update/clear API. */
-    STATE_TAIL_RESTORE,        /**< State for restoring tail (end) of backed up data from swap to data page when using update/clear API. */
-    STATE_NEW_BODY_WRITE,      /**< State for writing body (middle) data to the data page when using update/clear API. */
-    STATE_SWAP_ERASE,          /**< State for erasing the swap page when using the update/clear API. */
-    STATE_COMPLETE,            /**< State for indicating that update/clear sequence is completed internal in the module when using the update/clear API. */
-    STATE_SWAP_DIRTY           /**< State for initializing the swap region on module initialization. */
-} swap_backup_state_t;
-
-
-/**
- * @brief Application registration information.
- *
- * @details Define application specific information that application needs to maintain to be able
- *          to process requests from each one of them.
- */
-typedef struct
-{
-    pstorage_ntf_cb_t    cb;             /**< Callback registered with the module to be notified of result of flash access.  */
-    pstorage_block_t     base_id;        /**< Base block id assigned to the module. */
-    pstorage_size_t      block_size;     /**< Size of block for the module. */
-    pstorage_size_t      block_count;    /**< Number of block requested by application. */
-    pstorage_size_t      num_of_pages;   /**< Variable to remember how many pages have been allocated for this module. This information is used for clearing of block, so that application does not need to have knowledge of number of pages its using. */
-} pstorage_module_table_t;
-
-
-#ifdef PSTORAGE_RAW_MODE_ENABLE
-/**
- * @brief Application registration information.
- *
- * @details Define application specific information that application registered for raw mode.
- */
-typedef struct
-{
-    pstorage_ntf_cb_t      cb;             /**< Callback registered with the module to be notified of result of flash access.  */
-    uint16_t               num_of_pages;   /**< Variable to remember how many pages have been allocated for this module. This information is used for clearing of block, so that application does not need to have knowledge of number of pages its using. */
-} pstorage_raw_module_table_t;
-#endif // PSTORAGE_RAW_MODE_ENABLE
-
-
-/**
- * @brief Defines command queue element.
- *
- * @details Defines command queue element. Each element encapsulates needed information to process
- *          a flash access command.
- */
-typedef struct
-{
-    uint8_t              op_code;       /**< Identifies flash access operation being queued. Element is free if op-code is INVALID_OPCODE. */
-    pstorage_size_t      size;          /**< Identifies size in bytes requested for the operation. */
-    pstorage_size_t      offset;        /**< Offset requested by the application for access operation. */
-    pstorage_handle_t    storage_addr;  /**< Address/Identifier for persistent memory. */
-    uint8_t *            p_data_addr;   /**< Address/Identifier for data memory. This is assumed to be resident memory. */
-} cmd_queue_element_t;
-
-
-/**
- * @brief Defines command queue, an element is free if op_code field is not invalid.
- *
- * @details Defines commands enqueued for flash access. At any point of time, this queue has one or
- *          more flash access operation pending if the count field is not zero. When the queue is
- *          not empty, the rp (read pointer) field points to the flash access command in progress
- *          or to requested next. The queue implements a simple first in first out algorithm.
- *          Data addresses are assumed to be resident.
- */
-typedef struct
-{
-    uint8_t              rp;                           /**< Read pointer, pointing to flash access that is ongoing or to be requested next. */
-    uint8_t              count;                        /**< Number of elements in the queue.  */
-    bool                 flash_access;                 /**< Flag to ensure an flash event received is for an request issued by the module. */
-    cmd_queue_element_t  cmd[PSTORAGE_CMD_QUEUE_SIZE]; /**< Array to maintain flash access operation details. */
-} cmd_queue_t;
-
-
-static cmd_queue_t         m_cmd_queue;                  /**< Flash operation request queue. */
-static pstorage_size_t     m_next_app_instance;          /**< Points to the application module instance that can be allocated next. */
-static uint32_t            m_next_page_addr;             /**< Points to the flash address that can be allocated to a module next, this is needed as blocks of a module can span across flash pages. */
-static pstorage_size_t     m_round_val;                  /**< Round value for multiple round operations. For erase operations, the round value will contain current round counter which is identical to number of pages erased. For store operations, the round value contains current round of operation * SOC_MAX_WRITE_SIZE to ensure each store to the SoC Flash API is within the SoC limit. */
-static bool                m_module_initialized = false; /**< Flag for checking if module has been initialized. */
-static swap_backup_state_t m_swap_state;                 /**< Swap page state. */
-
-
-static pstorage_module_table_t m_app_table[PSTORAGE_MAX_APPLICATIONS]; /**< Registered application information table. */
-
-#ifdef PSTORAGE_RAW_MODE_ENABLE
-static pstorage_raw_module_table_t m_raw_app_table;                    /**< Registered application information table for raw mode. */
-#endif // PSTORAGE_RAW_MODE_ENABLE
-
-
-/**
- * @brief Routine called to actually issue the flash access request to the SoftDevice.
- *
- * @retval    NRF_SUCCESS    on success, else an error code indicating reason for failure.
- */
-static uint32_t cmd_process(void);
-
-
-/**
- * @brief Routine to notify application of any errors.
- *
- * @param[in] result Result of event being notified.
- */
-static void app_notify(uint32_t result);
-
-
-/**
- * @defgroup utility_functions Utility internal functions.
- * @{
- * @details Utility functions needed for interfacing with flash through SoC APIs.
- * SoC APIs are non blocking and provide the result of flash access through an event.
- *
- * @note Only one flash access operation is permitted at a time by SoC. Hence a queue is
- * maintained by this module.
- */
-
-
-/**
- * @brief Initializes command queue element.
- *
- * @param[in] index Element index being initialized.
- */
-static void cmd_queue_element_init(uint32_t index)
-{
-    // Internal function and checks on range of index can be avoided.
-    m_cmd_queue.cmd[index].op_code                = INVALID_OPCODE;
-    m_cmd_queue.cmd[index].size                   = 0;
-    m_cmd_queue.cmd[index].storage_addr.module_id = PSTORAGE_MAX_APPLICATIONS;
-    m_cmd_queue.cmd[index].storage_addr.block_id  = 0;
-    m_cmd_queue.cmd[index].p_data_addr            = NULL;
-    m_cmd_queue.cmd[index].offset                 = 0;
-}
-
-
-/**
- * @brief Initializes command queue.
- */
-static void cmd_queue_init(void)
-{
-    uint32_t cmd_index;
-
-    m_round_val              = 0;
-    m_swap_state             = STATE_INIT;
-    m_cmd_queue.rp           = 0;
-    m_cmd_queue.count        = 0;
-    m_cmd_queue.flash_access = false;
-
-    for (cmd_index = 0; cmd_index < PSTORAGE_CMD_QUEUE_SIZE; cmd_index++)
-    {
-        cmd_queue_element_init(cmd_index);
-    }
-}
-
-
-/**
- * @brief Routine to enqueue a flash access operation.
- *
- * @param[in] opcode         Identifies operation requested to be enqueued.
- * @param[in] p_storage_addr Identiifes module and flash address on which operation is requested.
- * @param[in] p_data_addr    Identifies data address for flash access.
- * @param[in] size           Size in bytes of data requested for the access operation.
- * @param[in] offset         Offset within the flash memory block at which operation is requested.
- *
- * @retval    NRF_SUCCESS    on success, else an error code indicating reason for failure.
- *
- * @note All paramater check should be performed before requesting in an enqueue.
- */
-static uint32_t cmd_queue_enqueue(uint8_t             opcode,
-                                  pstorage_handle_t * p_storage_addr,
-                                  uint8_t           * p_data_addr,
-                                  pstorage_size_t     size,
-                                  pstorage_size_t     offset)
-{
-    uint32_t retval;
-    uint8_t  write_index = 0;
-
-    if (m_cmd_queue.count != PSTORAGE_CMD_QUEUE_SIZE)
-    {
-        // Enqueue the command if it is queue is not full.
-        write_index = m_cmd_queue.rp + m_cmd_queue.count;
-
-        if (write_index >= PSTORAGE_CMD_QUEUE_SIZE)
-        {
-            write_index -= PSTORAGE_CMD_QUEUE_SIZE;
-        }
-
-        m_cmd_queue.cmd[write_index].op_code      = opcode;
-        m_cmd_queue.cmd[write_index].p_data_addr  = p_data_addr;
-        m_cmd_queue.cmd[write_index].storage_addr = (*p_storage_addr);
-        m_cmd_queue.cmd[write_index].size         = size;
-        m_cmd_queue.cmd[write_index].offset       = offset;
-        retval                                    = NRF_SUCCESS;
-        if (m_cmd_queue.flash_access == false)
-        {
-            retval = cmd_process();
-            if (retval == NRF_ERROR_BUSY)
-            {
-                // In case of busy error code, it is possible to attempt to access flash.
-                retval = NRF_SUCCESS;
-            }
-        }
-        m_cmd_queue.count++;
-    }
-    else
-    {
-        retval = NRF_ERROR_NO_MEM;
-    }
-
-    return retval;
-}
-
-
-/**
- * @brief Dequeues a command element.
- *
- * @retval    NRF_SUCCESS    on success, else an error code indicating reason for failure.
- */
-static uint32_t cmd_queue_dequeue(void)
-{
-    uint32_t retval;
-    retval = NRF_SUCCESS;
-
-    // If any flash operation is enqueued, schedule.
-    if (m_cmd_queue.count > 0)
-    {
-        retval = cmd_process();
-        if (retval != NRF_SUCCESS)
-        {
-            // Flash could be accessed by modules other than Bond Manager, hence a busy error is
-            // acceptable, but any other error needs to be indicated to the bond manager.
-            if (retval == NRF_ERROR_BUSY)
-            {
-                // In case of busy error code, it is possible to attempt to access flash.
-                retval = NRF_SUCCESS;
-            }
-        }
-    }
-    else
-    {
-        // No flash access request pending.
-    }
-
-    return retval;
-}
-
-
-/**
- * @brief Routine to notify application of any errors.
- *
- * @param[in] result Result of event being notified.
- */
-static void app_notify(uint32_t result)
-{
-    pstorage_ntf_cb_t ntf_cb;
-    uint8_t           op_code = m_cmd_queue.cmd[m_cmd_queue.rp].op_code;
-
-#ifdef PSTORAGE_RAW_MODE_ENABLE
-    if (m_cmd_queue.cmd[m_cmd_queue.rp].storage_addr.module_id == RAW_MODE_APP_ID)
-    {
-        ntf_cb = m_raw_app_table.cb;
-    }
-    else
-#endif // PSTORAGE_RAW_MODE_ENABLE
-    {
-        ntf_cb = m_app_table[m_cmd_queue.cmd[m_cmd_queue.rp].storage_addr.module_id].cb;
-    }
-
-    // Indicate result to client.
-    // For PSTORAGE_CLEAR_OP_CODE no size is returned as the size field is used only internally
-    // for clients registering multiple pages.
-    ntf_cb(&m_cmd_queue.cmd[m_cmd_queue.rp].storage_addr,
-           op_code,
-           result,
-           m_cmd_queue.cmd[m_cmd_queue.rp].p_data_addr,
-           m_cmd_queue.cmd[m_cmd_queue.rp].size);
-}
-
-
-/**
- * @brief Handles Flash Access Result Events declared in pstorage_platform.h.
- *
- * @param[in] sys_evt System event to be handled.
- */
-void pstorage_sys_event_handler(uint32_t sys_evt)
-{
-    uint32_t retval = NRF_SUCCESS;
-
-    // Its possible the flash access was not initiated by bond manager, hence
-    // event is processed only if the event triggered was for an operation requested by the
-    // bond manager.
-    if (m_cmd_queue.flash_access == true)
-    {
-        cmd_queue_element_t * p_cmd;
-
-        m_cmd_queue.flash_access = false;
-
-        if (m_swap_state == STATE_SWAP_DIRTY)
-        {
-            if (sys_evt == NRF_EVT_FLASH_OPERATION_SUCCESS)
-            {
-                m_swap_state = STATE_INIT;
-            }
-            else
-            {
-                // If clearing the swap fails, set the application back to un-initialized, to give
-                // the application a chance for a retry.
-                m_module_initialized = false;
-            }
-
-            // Schedule any queued flash access operations.
-            retval = cmd_queue_dequeue();
-            if (retval != NRF_SUCCESS)
-            {
-                app_notify(retval);
-            }
-            return;
-        }
-
-        switch (sys_evt)
-        {
-            case NRF_EVT_FLASH_OPERATION_SUCCESS:
-            {
-                p_cmd = &m_cmd_queue.cmd[m_cmd_queue.rp];
-                m_round_val++;
-
-                const bool store_finished =
-                    ((p_cmd->op_code == PSTORAGE_STORE_OP_CODE) &&
-                     ((m_round_val * SOC_MAX_WRITE_SIZE) >= p_cmd->size));
-
-                const bool update_finished =
-                    ((p_cmd->op_code == PSTORAGE_UPDATE_OP_CODE) &&
-                     (m_swap_state == STATE_COMPLETE));
-
-                const bool clear_block_finished =
-                    ((p_cmd->op_code == PSTORAGE_CLEAR_OP_CODE) &&
-                     (m_swap_state == STATE_COMPLETE));
-
-                const bool clear_all_finished =
-                    ((p_cmd->op_code == PSTORAGE_CLEAR_OP_CODE) &&
-                     ((m_round_val * SOC_MAX_WRITE_SIZE) >= p_cmd->size) &&
-                     (m_swap_state == STATE_INIT));
-
-                if (update_finished ||
-                    clear_block_finished ||
-                    clear_all_finished ||
-                    store_finished)
-                {
-                    m_swap_state = STATE_INIT;
-
-                    app_notify(retval);
-
-                    // Initialize/free the element as it is now processed.
-                    cmd_queue_element_init(m_cmd_queue.rp);
-                    m_round_val = 0;
-                    m_cmd_queue.count--;
-                    m_cmd_queue.rp++;
-
-                    if (m_cmd_queue.rp >= PSTORAGE_CMD_QUEUE_SIZE)
-                    {
-                        m_cmd_queue.rp -= PSTORAGE_CMD_QUEUE_SIZE;
-                    }
-                }
-                // Schedule any queued flash access operations.
-                retval = cmd_queue_dequeue();
-
-                if (retval != NRF_SUCCESS)
-                {
-                    app_notify(retval);
-                }
-            }
-            break;
-
-            case NRF_EVT_FLASH_OPERATION_ERROR:
-                app_notify(NRF_ERROR_TIMEOUT);
-                break;
-
-            default:
-                // No implementation needed.
-                break;
-
-        }
-    }
-}
-
-
-/** @brief Function for handling flash accesses when using swap.
- *
- * __________________________________________________________
- * |                       Page                             |
- * |________________________________________________________|
- * | head | affected body (to be updated or cleared) | tail |
- * |______|__________________________________________|______|
- *
- * @param[in] p_cmd          Queue element being processed.
- * @param[in] page_number    The affected page number.
- * @param[in] head_word_size Size of the head in number of words.
- * @param[in] tail_word_size Size of the tail in number of words.
- *
- * @retval    NRF_SUCCESS    on success, else an error code indicating reason for failure.
- */
-static uint32_t swap_state_process(cmd_queue_element_t * p_cmd,
-                                   uint32_t              page_number,
-                                   uint32_t              head_word_size,
-                                   uint32_t              tail_word_size)
-{
-    uint32_t retval = NRF_ERROR_INTERNAL;
-
-    // Adjust entry point to state machine if needed. When we update has no head or tail its
-    // no need for using the swap.
-    if (m_swap_state == STATE_INIT)
-    {
-        if ((head_word_size == 0) && (tail_word_size == 0))
-        {
-            // Only skip swap usage if the new data fills a whole flash page.
-            m_swap_state = STATE_DATA_ERASE;
-        }
-        else
-        {
-            // Else start backing up application data to swap.
-            m_swap_state = STATE_DATA_TO_SWAP_WRITE;
-        }
-    }
-
-    switch (m_swap_state)
-    {
-        case STATE_DATA_TO_SWAP_WRITE:
-            // Backup previous content into swap page.
-            retval = sd_flash_write((uint32_t *)(PSTORAGE_SWAP_ADDR),
-                                    (uint32_t *)(page_number * PSTORAGE_FLASH_PAGE_SIZE),
-                                    PSTORAGE_FLASH_PAGE_SIZE / sizeof(uint32_t));
-            if (retval == NRF_SUCCESS)
-            {
-                m_swap_state = STATE_DATA_ERASE;
-            }
-            break;
-
-        case STATE_DATA_ERASE:
-            // Clear the application data page.
-            retval = sd_flash_page_erase(page_number);
-            if (retval == NRF_SUCCESS)
-            {
-                if (head_word_size == 0)
-                {
-                    if (tail_word_size == 0)
-                    {
-                        if (p_cmd->op_code == PSTORAGE_CLEAR_OP_CODE)
-                        {
-                            m_swap_state = STATE_COMPLETE;
-                        }
-                        else
-                        {
-                            m_swap_state = STATE_NEW_BODY_WRITE;
-                        }
-                    }
-                    else
-                    {
-                        m_swap_state = STATE_TAIL_RESTORE;
-                    }
-                }
-                else
-                {
-                    m_swap_state = STATE_HEAD_RESTORE;
-                }
-            }
-            break;
-
-        case STATE_HEAD_RESTORE:
-            // Restore head from swap to application data page.
-            retval = sd_flash_write((uint32_t *)(page_number * PSTORAGE_FLASH_PAGE_SIZE),
-                                    (uint32_t *)PSTORAGE_SWAP_ADDR,
-                                    head_word_size);
-            if (retval == NRF_SUCCESS)
-            {
-                if (tail_word_size == 0)
-                {
-                    if (p_cmd->op_code == PSTORAGE_CLEAR_OP_CODE)
-                    {
-                        m_swap_state = STATE_SWAP_ERASE;
-                    }
-                    else
-                    {
-                        m_swap_state = STATE_NEW_BODY_WRITE;
-                    }
-                }
-                else
-                {
-                    m_swap_state = STATE_TAIL_RESTORE;
-                }
-            }
-            break;
-
-        case STATE_TAIL_RESTORE:
-            // Restore tail from swap to application data page.
-            retval = sd_flash_write((uint32_t *)((page_number * PSTORAGE_FLASH_PAGE_SIZE) +
-                                                 (head_word_size * sizeof(uint32_t)) +
-                                                 p_cmd->size),
-                                    (uint32_t *)(PSTORAGE_SWAP_ADDR +
-                                                 (head_word_size * sizeof(uint32_t)) +
-                                                 p_cmd->size),
-                                    tail_word_size);
-            if (retval == NRF_SUCCESS)
-            {
-                if (p_cmd->op_code == PSTORAGE_CLEAR_OP_CODE)
-                {
-                    m_swap_state = STATE_SWAP_ERASE;
-                }
-                else
-                {
-                    m_swap_state = STATE_NEW_BODY_WRITE;
-                }
-            }
-            break;
-
-        case STATE_NEW_BODY_WRITE:
-            // Write new data (body) to application data page.
-            retval = sd_flash_write((uint32_t *)((page_number * PSTORAGE_FLASH_PAGE_SIZE) +
-                                                 (head_word_size * sizeof(uint32_t))),
-                                    (uint32_t *)p_cmd->p_data_addr,
-                                    p_cmd->size / sizeof(uint32_t));
-            if (retval == NRF_SUCCESS)
-            {
-                if ((head_word_size == 0) && (tail_word_size == 0))
-                {
-                    m_swap_state = STATE_COMPLETE;
-                }
-                else
-                {
-                    m_swap_state = STATE_SWAP_ERASE;
-                }
-            }
-            break;
-
-        case STATE_SWAP_ERASE:
-            // Clear the swap page for subsequent use.
-            retval = sd_flash_page_erase(PSTORAGE_SWAP_ADDR / PSTORAGE_FLASH_PAGE_SIZE);
-            if (retval == NRF_SUCCESS)
-            {
-                m_swap_state = STATE_COMPLETE;
-            }
-            break;
-
-        default:
-            break;
-    }
-
-    return retval;
-}
-
-
-/**
- * @brief Routine called to actually issue the flash access request to the SoftDevice.
- *
- * @retval    NRF_SUCCESS    on success, else an error code indicating reason for failure.
- */
-static uint32_t cmd_process(void)
-{
-    uint32_t              retval;
-    uint32_t              storage_addr;
-    cmd_queue_element_t * p_cmd;
-
-    retval = NRF_ERROR_FORBIDDEN;
-
-    p_cmd = &m_cmd_queue.cmd[m_cmd_queue.rp];
-
-    storage_addr = p_cmd->storage_addr.block_id;
-
-    switch (p_cmd->op_code)
-    {
-        case PSTORAGE_STORE_OP_CODE:
-        {
-            uint32_t  size;
-            uint32_t  offset;
-            uint8_t * p_data_addr = p_cmd->p_data_addr;
-
-            offset        = (m_round_val * SOC_MAX_WRITE_SIZE);
-            size          = p_cmd->size - offset;
-            p_data_addr  += offset;
-            storage_addr += (p_cmd->offset + offset);
-
-            if (size < SOC_MAX_WRITE_SIZE)
-            {
-                retval = sd_flash_write(((uint32_t *)storage_addr),
-                                        (uint32_t *)p_data_addr,
-                                        size / sizeof(uint32_t));
-            }
-            else
-            {
-                retval = sd_flash_write(((uint32_t *)storage_addr),
-                                        (uint32_t *)p_data_addr,
-                                        SOC_MAX_WRITE_SIZE / sizeof(uint32_t));
-            }
-        }
-        break;
-
-        case PSTORAGE_CLEAR_OP_CODE:
-        {
-            // Calculate page number before clearing.
-            uint32_t page_number;
-
-            pstorage_size_t block_size =
-                m_app_table[p_cmd->storage_addr.module_id].block_size;
-
-            pstorage_size_t block_count =
-                m_app_table[p_cmd->storage_addr.module_id].block_count;
-
-            pstorage_block_t base_address =
-                m_app_table[p_cmd->storage_addr.module_id].base_id;
-
-            // If the whole module should be cleared.
-            if (((base_address == storage_addr) && (block_size * block_count == p_cmd->size)) ||
-                (p_cmd->storage_addr.module_id == RAW_MODE_APP_ID))
-            {
-                page_number = ((storage_addr / PSTORAGE_FLASH_PAGE_SIZE) + m_round_val);
-
-                retval = sd_flash_page_erase(page_number);
-            }
-            // If one block is to be erased.
-            else
-            {
-                page_number = (storage_addr / PSTORAGE_FLASH_PAGE_SIZE);
-
-                uint32_t head_word_size = (
-                    storage_addr -
-                    (page_number * PSTORAGE_FLASH_PAGE_SIZE)
-                    ) / sizeof(uint32_t);
-
-                uint32_t tail_word_size = (
-                    ((page_number + 1) * PSTORAGE_FLASH_PAGE_SIZE) -
-                    (storage_addr + p_cmd->size)
-                    ) / sizeof(uint32_t);
-
-                retval = swap_state_process(p_cmd,
-                                            page_number,
-                                            head_word_size,
-                                            tail_word_size);
-            }
-        }
-        break;
-
-        case PSTORAGE_UPDATE_OP_CODE:
-        {
-            uint32_t page_number = (storage_addr / PSTORAGE_FLASH_PAGE_SIZE);
-
-            uint32_t head_word_size = (
-                storage_addr + p_cmd->offset -
-                (page_number * PSTORAGE_FLASH_PAGE_SIZE)
-                ) / sizeof(uint32_t);
-
-            uint32_t tail_word_size = (
-                ((page_number + 1) * PSTORAGE_FLASH_PAGE_SIZE) -
-                (storage_addr + p_cmd->offset + p_cmd->size)
-                ) / sizeof(uint32_t);
-
-            retval = swap_state_process(p_cmd, page_number, head_word_size, tail_word_size);
-        }
-        break;
-
-        default:
-            // Should never reach here.
-            break;
-    }
-
-    if (retval == NRF_SUCCESS)
-    {
-        m_cmd_queue.flash_access = true;
-    }
-
-    return retval;
-}
-/** @} */
-
-
-uint32_t pstorage_init(void)
-{
-    uint32_t retval;
-
-    cmd_queue_init();
-
-    m_next_app_instance = 0;
-    m_next_page_addr    = PSTORAGE_DATA_START_ADDR;
-    m_round_val         = 0;
-
-    for (uint32_t index = 0; index < PSTORAGE_MAX_APPLICATIONS; index++)
-    {
-        m_app_table[index].cb           = NULL;
-        m_app_table[index].block_size   = 0;
-        m_app_table[index].num_of_pages = 0;
-        m_app_table[index].block_count  = 0;
-    }
-
-#ifdef PSTORAGE_RAW_MODE_ENABLE
-    m_raw_app_table.cb           = NULL;
-    m_raw_app_table.num_of_pages = 0;
-    m_module_initialized         = true;
-    m_swap_state                 = STATE_INIT;
-
-    retval = NRF_SUCCESS;
-#else
-    m_swap_state = STATE_SWAP_DIRTY;
-
-    // Erase swap region in case it is dirty.
-    retval = sd_flash_page_erase(PSTORAGE_SWAP_ADDR / PSTORAGE_FLASH_PAGE_SIZE);
-    if (retval == NRF_SUCCESS)
-    {
-        m_cmd_queue.flash_access = true;
-        m_module_initialized     = true;
-    }
-#endif //PSTORAGE_RAW_MODE_ENABLE
-
-    return retval;
-}
-
-
-uint32_t pstorage_register(pstorage_module_param_t * p_module_param,
-                           pstorage_handle_t       * p_block_id)
-{
-    uint16_t page_count;
-    uint32_t total_size;
-
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_module_param);
-    NULL_PARAM_CHECK(p_block_id);
-    NULL_PARAM_CHECK(p_module_param->cb);
-    BLOCK_SIZE_CHECK(p_module_param->block_size);
-    BLOCK_COUNT_CHECK(p_module_param->block_count, p_module_param->block_size);
-
-    // Block size should be a multiple of word size.
-    if (!((p_module_param->block_size % sizeof(uint32_t)) == 0))
-    {
-        return NRF_ERROR_INVALID_PARAM;
-    }
-
-    if (m_next_app_instance == PSTORAGE_MAX_APPLICATIONS)
-    {
-        return NRF_ERROR_NO_MEM;
-    }
-
-    p_block_id->module_id = m_next_app_instance;
-    p_block_id->block_id  = m_next_page_addr;
-
-    m_app_table[m_next_app_instance].base_id     = p_block_id->block_id;
-    m_app_table[m_next_app_instance].cb          = p_module_param->cb;
-    m_app_table[m_next_app_instance].block_size  = p_module_param->block_size;
-    m_app_table[m_next_app_instance].block_count = p_module_param->block_count;
-
-    // Calculate number of flash pages allocated for the device.
-    page_count = 0;
-    total_size = p_module_param->block_size * p_module_param->block_count;
-    do
-    {
-        page_count++;
-        if (total_size > PSTORAGE_FLASH_PAGE_SIZE)
-        {
-            total_size -= PSTORAGE_FLASH_PAGE_SIZE;
-        }
-        else
-        {
-            total_size = 0;
-        }
-        m_next_page_addr += PSTORAGE_FLASH_PAGE_SIZE;
-    }
-    while (total_size >= PSTORAGE_FLASH_PAGE_SIZE);
-
-    m_app_table[m_next_app_instance].num_of_pages = page_count;
-    m_next_app_instance++;
-
-    return NRF_SUCCESS;
-}
-
-
-uint32_t pstorage_block_identifier_get(pstorage_handle_t * p_base_id,
-                                       pstorage_size_t     block_num,
-                                       pstorage_handle_t * p_block_id)
-{
-    pstorage_handle_t temp_id;
-
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_base_id);
-    NULL_PARAM_CHECK(p_block_id);
-    MODULE_ID_RANGE_CHECK(p_base_id);
-
-    temp_id           = (*p_base_id);
-    temp_id.block_id += (block_num * MODULE_BLOCK_SIZE(p_base_id));
-
-    BLOCK_ID_RANGE_CHECK(&temp_id);
-
-    (*p_block_id) = temp_id;
-
-    return NRF_SUCCESS;
-}
-
-
-uint32_t pstorage_store(pstorage_handle_t * p_dest,
-                        uint8_t           * p_src,
-                        pstorage_size_t     size,
-                        pstorage_size_t     offset)
-{
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_src);
-    NULL_PARAM_CHECK(p_dest);
-    MODULE_ID_RANGE_CHECK(p_dest);
-    BLOCK_ID_RANGE_CHECK(p_dest);
-    SIZE_CHECK(p_dest, size);
-    OFFSET_CHECK(p_dest, offset,size);
-
-    // Verify word alignment.
-    if ((!is_word_aligned(p_src)) || (!is_word_aligned((void *)(uint32_t)offset)))
-    {
-        return NRF_ERROR_INVALID_ADDR;
-    }
-
-    if ((!is_word_aligned((uint32_t *)p_dest->block_id)))
-    {
-        return NRF_ERROR_INVALID_ADDR;
-    }
-
-    return cmd_queue_enqueue(PSTORAGE_STORE_OP_CODE, p_dest, p_src, size, offset);
-}
-
-
-uint32_t pstorage_update(pstorage_handle_t * p_dest,
-                         uint8_t           * p_src,
-                         pstorage_size_t     size,
-                         pstorage_size_t     offset)
-{
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_src);
-    NULL_PARAM_CHECK(p_dest);
-    MODULE_ID_RANGE_CHECK(p_dest);
-    BLOCK_ID_RANGE_CHECK(p_dest);
-    SIZE_CHECK(p_dest, size);
-    OFFSET_CHECK(p_dest, offset, size);
-
-    // Verify word alignment.
-    if ((!is_word_aligned(p_src)) || (!is_word_aligned((void *)(uint32_t)offset)))
-    {
-        return NRF_ERROR_INVALID_ADDR;
-    }
-
-    if ((!is_word_aligned((uint32_t *)p_dest->block_id)))
-    {
-        return NRF_ERROR_INVALID_ADDR;
-    }
-
-    return cmd_queue_enqueue(PSTORAGE_UPDATE_OP_CODE, p_dest, p_src, size, offset);
-}
-
-
-uint32_t pstorage_load(uint8_t           * p_dest,
-                       pstorage_handle_t * p_src,
-                       pstorage_size_t     size,
-                       pstorage_size_t     offset)
-{
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_src);
-    NULL_PARAM_CHECK(p_dest);
-    MODULE_ID_RANGE_CHECK(p_src);
-    BLOCK_ID_RANGE_CHECK(p_src);
-    SIZE_CHECK(p_src, size);
-    OFFSET_CHECK(p_src, offset, size);
-
-    // Verify word alignment.
-    if ((!is_word_aligned(p_dest)) || (!is_word_aligned((void *)(uint32_t)offset)))
-    {
-        return NRF_ERROR_INVALID_ADDR;
-    }
-
-    if ((!is_word_aligned((uint32_t *)p_src->block_id)))
-    {
-        return NRF_ERROR_INVALID_ADDR;
-    }
-
-    memcpy(p_dest, (((uint8_t *)p_src->block_id) + offset), size);
-
-    m_app_table[p_src->module_id].cb(p_src, PSTORAGE_LOAD_OP_CODE, NRF_SUCCESS, p_dest, size);
-
-    return NRF_SUCCESS;
-}
-
-
-uint32_t pstorage_clear(pstorage_handle_t * p_dest, pstorage_size_t size)
-{
-    uint32_t retval;
-
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_dest);
-    MODULE_ID_RANGE_CHECK(p_dest);
-    BLOCK_ID_RANGE_CHECK(p_dest);
-
-    if ((!is_word_aligned((uint32_t *)p_dest->block_id)))
-    {
-        return NRF_ERROR_INVALID_ADDR;
-    }
-
-    if (
-        !(
-            ((p_dest->block_id - m_app_table[p_dest->module_id].base_id) %
-             m_app_table[p_dest->module_id].block_size) == 0
-            )
-        )
-    {
-        return NRF_ERROR_INVALID_PARAM;
-    }
-
-    retval = cmd_queue_enqueue(PSTORAGE_CLEAR_OP_CODE, p_dest, NULL, size, 0);
-
-    return retval;
-}
-
-
-uint32_t pstorage_access_status_get(uint32_t * p_count)
-{
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_count);
-
-    (*p_count) = m_cmd_queue.count;
-
-    return NRF_SUCCESS;
-}
-
-#ifdef PSTORAGE_RAW_MODE_ENABLE
-
-
-uint32_t pstorage_raw_register(pstorage_module_param_t * p_module_param,
-                               pstorage_handle_t       * p_block_id)
-{
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_module_param);
-    NULL_PARAM_CHECK(p_block_id);
-    NULL_PARAM_CHECK(p_module_param->cb);
-
-    if (m_raw_app_table.cb != NULL)
-    {
-        return NRF_ERROR_NO_MEM;
-    }
-
-    p_block_id->module_id = RAW_MODE_APP_ID;
-    m_raw_app_table.cb    = p_module_param->cb;
-
-    return NRF_SUCCESS;
-}
-
-
-uint32_t pstorage_raw_store(pstorage_handle_t * p_dest,
-                            uint8_t           * p_src,
-                            pstorage_size_t     size,
-                            pstorage_size_t     offset)
-{
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_src);
-    NULL_PARAM_CHECK(p_dest);
-    MODULE_RAW_ID_RANGE_CHECK(p_dest);
-
-    // Verify word alignment.
-    if ((!is_word_aligned(p_src)) || (!is_word_aligned((void *)(uint32_t)offset)))
-    {
-        return NRF_ERROR_INVALID_ADDR;
-    }
-
-    return cmd_queue_enqueue(PSTORAGE_STORE_OP_CODE, p_dest, p_src, size, offset);
-}
-
-
-uint32_t pstorage_raw_clear(pstorage_handle_t * p_dest, pstorage_size_t size)
-{
-    uint32_t retval;
-
-    VERIFY_MODULE_INITIALIZED();
-    NULL_PARAM_CHECK(p_dest);
-    MODULE_RAW_ID_RANGE_CHECK(p_dest);
-
-    retval = cmd_queue_enqueue(PSTORAGE_CLEAR_OP_CODE, p_dest, NULL, size, 0);
-
-    return retval;
-}
-
-#endif // PSTORAGE_RAW_MODE_ENABLE
\ No newline at end of file
--- a/source/nordic-sdk/components/drivers_nrf/pstorage/pstorage.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,403 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/**@file
- *
- * @defgroup persistent_storage Persistent Storage Interface
- * @{
- * @ingroup app_common
- * @brief Abstracted flash interface.
- *
- * @details In order to ensure that the SDK and application be moved to alternate persistent storage
- *          options other than the default provided with NRF solution, an abstracted interface is provided
- *          by the module to ensure SDK modules and application can be ported to alternate option with ease.
- */
-
-#ifndef PSTORAGE_H__
-#define PSTORAGE_H__
-
-#include "pstorage_platform.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* #ifdef __cplusplus */
-
-
-/**@defgroup ps_opcode Persistent Storage Access Operation Codes
- * @{
- * @brief    Persistent Storage Access Operation Codes. These are used to report any error during
- *           a persistent storage access operation or any general error that may occur in the
- *           interface.
- *
- * @details  Persistent Storage Access Operation Codes used in error notification callback
- *           registered with the interface to report any error during an persistent storage access
- *           operation or any general error that may occur in the interface.
- */
-#define PSTORAGE_ERROR_OP_CODE    0x01  /**< General Error Code */
-#define PSTORAGE_STORE_OP_CODE    0x02  /**< Error when Store Operation was requested */
-#define PSTORAGE_LOAD_OP_CODE     0x03  /**< Error when Load Operation was requested */
-#define PSTORAGE_CLEAR_OP_CODE    0x04  /**< Error when Clear Operation was requested */
-#define PSTORAGE_UPDATE_OP_CODE   0x05  /**< Update an already touched storage block */
-
-/**@} */
-
-/**@defgroup pstorage_data_types Persistent Memory Interface Data Types
- * @{
- * @brief Data Types needed for interfacing with persistent memory.
- *
- * @details Data Types needed for interfacing with persistent memory.
- */
-
-/**@brief Persistent Storage Error Reporting Callback
- *
- * @details Persistent Storage Error Reporting Callback that is used by the interface to report
- *          success or failure of a flash operation. Therefore, for any operations, application 
- *          can know when the procedure was complete. For store operation, since no data copy 
- *          is made, receiving a success or failure notification, indicated by the reason 
- *          parameter of callback is an indication that the resident memory could now be reused 
- *          or freed, as the case may be.
- * 
- * @param[in] handle   Identifies module and block for which callback is received.
- * @param[in] op_code  Identifies the operation for which the event is notified.
- * @param[in] result   Identifies the result of flash access operation.
- *                     NRF_SUCCESS implies, operation succeeded.
- * @param[in] p_data   Identifies the application data pointer. In case of store operation, this 
- *                     points to the resident source of application memory that application can now 
- *                     free or reuse. In case of clear, this is NULL as no application pointer is 
- *                     needed for this operation.
- * @param[in] data_len Length data application had provided for the operation.
- * 
- */
-typedef void (*pstorage_ntf_cb_t)(pstorage_handle_t *  p_handle,
-                                  uint8_t              op_code,
-                                  uint32_t             result,
-                                  uint8_t *            p_data,
-                                  uint32_t             data_len);
-
-
-typedef struct
-{
-    pstorage_ntf_cb_t cb;             /**< Callback registered with the module to be notified of any error occurring in persistent memory management */
-    pstorage_size_t   block_size;     /**< Desired block size for persistent memory storage, for example, if a module has a table with 10 entries, each entry is size 64 bytes,
-                                       *   it can request 10 blocks with block size 64 bytes. On the other hand, the module can also request one block of size 640 based on
-                                       *   how it would like to access or alter memory in persistent memory.
-                                       *   First option is preferred when single entries that need to be updated often when having no impact on the other entries.
-                                       *   While second option is preferred when entries of table are not changed on individually but have common point of loading and storing
-                                       *   data. */
-    pstorage_size_t   block_count;    /** Number of blocks requested by the module, minimum values is 1. */
-} pstorage_module_param_t;
-
-/**@} */
-
-/**@defgroup pstorage_routines Persistent Storage Access Routines
- * @{
- * @brief Functions/Interface SDK modules use to persistently store data.
- *
- * @details Interface for Application & SDK module to load/store information persistently.
- *          Note: that while implementation of each of the persistent storage access function
- *          depends on the system and can specific to system/solution, the signature of the
- *          interface routines should not be altered.
- */
-
-/**@brief Module Initialization Routine.
- *
- * @details Initializes module. To be called once before any other APIs of the module are used.
- *
- * @retval     NRF_SUCCESS             on success, else an error code indicating reason for failure.
- */
-uint32_t pstorage_init(void);
-
-
-/**@brief Register with persistent storage interface.
- *
- * @param[in]  p_module_param Module registration param.
- * @param[out] p_block_id     Block identifier to identify persistent memory blocks in case 
- *                            registration succeeds. Application is expected to use the block ids 
- *                            for subsequent operations on requested persistent memory. Maximum 
- *                            registrations permitted is determined by configuration parameter 
- *                            PSTORAGE_MAX_APPLICATIONS. 
- *             In case more than one memory blocks are requested, the identifier provided here is
- *             the base identifier for the first block and to identify subsequent block,
- *             application shall use \@ref pstorage_block_identifier_get with this base identifier
- *             and block number. Therefore if 10 blocks of size 64 are requested and application
- *             wishes to store memory in 6th block, it shall use
- *             \@ref pstorage_block_identifier_get with based id and provide a block number of 5.
- *             This way application is only expected to remember the base block identifier.
- *
- * @note       To register an area with a total size (block count * block size) larger than the
- *             page size (usually 1024 bytes), the block size must be a divisor of the page size 
- *             (page size % block size == 0).
- *
- * @retval     NRF_SUCCESS             on success, else an error code indicating reason for failure.
- * @retval     NRF_ERROR_INVALID_STATE is returned is API is called without module initialization.
- * @retval     NRF_ERROR_NULL          if NULL parameter has been passed.
- * @retval     NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API.
- * @retval     NRF_ERROR_NO_MEM        in case no more registrations can be supported.
- */
-uint32_t pstorage_register(pstorage_module_param_t * p_module_param,
-                           pstorage_handle_t *       p_block_id);
-
-
-/**
- * @brief Function to get block id with reference to base block identifier provided at time of
- *        registration.
- *
- * @details Function to get block id with reference to base block identifier provided at time of
- *          registration.
- *          In case more than one memory blocks were requested when registering, the identifier
- *          provided here is the base identifier for the first block and to identify subsequent
- *          block, application shall use this routine to get block identifier providing input as
- *          base identifier and block number. Therefore if 10 blocks of size 64 are requested and
- *          application wishes to store memory in 6th block, it shall use
- *          \@ref pstorage_block_identifier_get with based id and provide a block number of 5.
- *          This way application is only expected to remember the base block identifier.
- *
- * @param[in]  p_base_id  Base block id received at the time of registration.
- * @param[in]  block_num  Block Number, with first block numbered zero.
- * @param[out] p_block_id Block identifier for the block number requested in case the API succeeds.
- *
- * @retval     NRF_SUCCESS             on success, else an error code indicating reason for failure.
- * @retval     NRF_ERROR_INVALID_STATE is returned is API is called without module initialization.
- * @retval     NRF_ERROR_NULL          if NULL parameter has been passed.
- * @retval     NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API.
- */
-uint32_t pstorage_block_identifier_get(pstorage_handle_t * p_base_id,
-                                       pstorage_size_t     block_num,
-                                       pstorage_handle_t * p_block_id);
-
-
-/**@brief Routine to persistently store data of length 'size' contained in 'p_src' address
- *        in storage module at 'p_dest' address; Equivalent to Storage Write.
- *
- * @param[in]  p_dest Destination address where data is to be stored persistently.
- * @param[in]  p_src  Source address containing data to be stored. API assumes this to be resident
- *                    memory and no intermediate copy of data is made by the API.
- * @param[in]  size   Size of data to be stored expressed in bytes. Should be word aligned.
- * @param[in]  offset Offset in bytes to be applied when writing to the block.
- *                    For example, if within a block of 100 bytes, application wishes to
- *                    write 20 bytes at offset of 12, then this field should be set to 12.
- *                    Should be word aligned.
- *
- * @retval     NRF_SUCCESS             on success, else an error code indicating reason for failure.
- * @retval     NRF_ERROR_INVALID_STATE is returned is API is called without module initialization.
- * @retval     NRF_ERROR_NULL          if NULL parameter has been passed.
- * @retval     NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API.
- * @retval     NRF_ERROR_INVALID_ADDR  in case data address 'p_src' is not aligned.
- * @retval     NRF_ERROR_NO_MEM        in case request cannot be processed.
- *
- * @warning    No copy of the data is made, and hence memory provided for data source to be written
- *             to flash cannot be freed or reused by the application until this procedure
- *             is complete. End of this procedure is notified to the application using the
- *             notification callback registered by the application.
- */
-uint32_t pstorage_store(pstorage_handle_t * p_dest,
-                        uint8_t *           p_src,
-                        pstorage_size_t     size,
-                        pstorage_size_t     offset);
-
-/**@brief Routine to update persistently stored data of length 'size' contained in 'p_src' address
- *        in storage module at 'p_dest' address.
- *
- * @param[in]  p_dest Destination address where data is to be updated.
- * @param[in]  p_src  Source address containing data to be stored. API assumes this to be resident
- *                    memory and no intermediate copy of data is made by the API.
- * @param[in]  size   Size of data to be stored expressed in bytes. Should be word aligned.
- * @param[in]  offset Offset in bytes to be applied when writing to the block.
- *                    For example, if within a block of 100 bytes, application wishes to
- *                    write 20 bytes at offset of 12, then this field should be set to 12.
- *                    Should be word aligned.
- *
- * @retval     NRF_SUCCESS             on success, else an error code indicating reason for failure.
- * @retval     NRF_ERROR_INVALID_STATE is returned is API is called without module initialization.
- * @retval     NRF_ERROR_NULL          if NULL parameter has been passed.
- * @retval     NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API.
- * @retval     NRF_ERROR_INVALID_ADDR  in case data address 'p_src' is not aligned.
- * @retval     NRF_ERROR_NO_MEM        in case request cannot be processed.
- *
- * @warning    No copy of the data is made, and hence memory provided for data source to be written
- *             to flash cannot be freed or reused by the application until this procedure
- *             is complete. End of this procedure is notified to the application using the
- *             notification callback registered by the application.
- */
-uint32_t pstorage_update(pstorage_handle_t * p_dest,
-                         uint8_t *           p_src,
-                         pstorage_size_t     size,
-                         pstorage_size_t     offset);
-
-/**@brief Routine to load persistently stored data of length 'size' from 'p_src' address
- *        to 'p_dest' address; Equivalent to Storage Read.
- *
- * @param[in]  p_dest Destination address where persistently stored data is to be loaded.
- * @param[in]  p_src  Source from where data is to be loaded from persistent memory.
- * @param[in]  size   Size of data to be loaded from persistent memory expressed in bytes.
- *                    Should be word aligned.
- * @param[in]  offset Offset in bytes to be applied when loading from the block.
- *                    For example, if within a block of 100 bytes, application wishes to
- *                    load 20 bytes from offset of 12, then this field should be set to 12.
- *                    Should be word aligned.
- *
- * @retval     NRF_SUCCESS             on success, else an error code indicating reason for failure.
- * @retval     NRF_ERROR_INVALID_STATE is returned is API is called without module initialization.
- * @retval     NRF_ERROR_NULL          if NULL parameter has been passed.
- * @retval     NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API.
- * @retval     NRF_ERROR_INVALID_ADDR  in case data address 'p_dst' is not aligned.
- * @retval     NRF_ERROR_NO_MEM        in case request cannot be processed.
- */
-uint32_t pstorage_load(uint8_t *           p_dest,
-                       pstorage_handle_t * p_src,
-                       pstorage_size_t     size,
-                       pstorage_size_t     offset);
-
-/**@brief Routine to clear data in persistent memory.
- *
- * @param[in]  p_base_id Base block identifier in persistent memory that needs to cleared;
- *                       Equivalent to an Erase Operation.
- *
- * @param[in]  size      Size of data to be cleared from persistent memory expressed in bytes.
- *                       This parameter is to provision for clearing of certain blocks
- *                       of memory, or all memory blocks in a registered module. If the total size 
- *                       of the application module is used (blocks * block size) in combination with
- *                       the identifier for the first block in the module, all blocks in the 
- *                       module will be erased.
- *
- * @retval     NRF_SUCCESS             on success, else an error code indicating reason for failure.
- * @retval     NRF_ERROR_INVALID_STATE is returned is API is called without module initialization.
- * @retval     NRF_ERROR_NULL          if NULL parameter has been passed.
- * @retval     NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API.
- * @retval     NRF_ERROR_INVALID_ADDR  in case data address 'p_dst' is not aligned.
- * @retval     NRF_ERROR_NO_MEM        in case request cannot be processed.
- *
- * @note       Clear operations may take time. This API however, does not block until the clear
- *             procedure is complete. Application is notified of procedure completion using
- *             notification callback registered by the application. 'result' parameter of the
- *             callback suggests if the procedure was successful or not.
- */
-uint32_t pstorage_clear(pstorage_handle_t * p_base_id, pstorage_size_t size);
-
-/**
- * @brief API to get status of number of pending operations with the module.
- *
- * @param[out] p_count Number of storage operations pending with the module, if 0,
- *                     there are no outstanding requests.
- *
- * @retval     NRF_SUCCESS             on success, else an error code indicating reason for failure.
- * @retval     NRF_ERROR_INVALID_STATE is returned is API is called without module initialization.
- * @retval     NRF_ERROR_NULL          if NULL parameter has been passed.
- */
-uint32_t pstorage_access_status_get(uint32_t * p_count);
-
-#ifdef PSTORAGE_RAW_MODE_ENABLE
-
-/**@brief      Function for registering with persistent storage interface.
- *
- * @param[in]  p_module_param Module registration param.
- * @param[out] p_block_id     Block identifier to identify persistent memory blocks in case 
- *                            registration succeeds. Application is expected to use the block ids 
- *                            for subsequent operations on requested persistent memory.
- *             In case more than one memory blocks are requested, the identifier provided here is
- *             the base identifier for the first block and to identify subsequent block,
- *             application shall use \@ref pstorage_block_identifier_get with this base identifier
- *             and block number. Therefore if 10 blocks of size 64 are requested and application
- *             wishes to store memory in 6th block, it shall use
- *             \@ref pstorage_block_identifier_get with based id and provide a block number of 5.
- *             This way application is only expected to remember the base block identifier.
- *
- * @retval     NRF_SUCCESS             on success, else an error code indicating reason for failure.
- * @retval     NRF_ERROR_INVALID_STATE is returned is API is called without module initialization.
- * @retval     NRF_ERROR_NULL          if NULL parameter has been passed.
- * @retval     NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API.
- * @retval     NRF_ERROR_NO_MEM        in case no more registrations can be supported.
- */
-uint32_t pstorage_raw_register(pstorage_module_param_t * p_module_param,
-                               pstorage_handle_t *       p_block_id);
-
-/**@brief     Raw mode function for persistently storing data of length 'size' contained in 'p_src'
- *            address in storage module at 'p_dest' address; Equivalent to Storage Write.
- *
- * @param[in]  p_dest Destination address where data is to be stored persistently.
- * @param[in]  p_src  Source address containing data to be stored. API assumes this to be resident
- *                    memory and no intermediate copy of data is made by the API.
- * @param[in]  size   Size of data to be stored expressed in bytes. Should be word aligned.
- * @param[in]  offset Offset in bytes to be applied when writing to the block.
- *                    For example, if within a block of 100 bytes, application wishes to
- *                    write 20 bytes at offset of 12, then this field should be set to 12.
- *                    Should be word aligned.
- *
- * @retval     NRF_SUCCESS             on success, else an error code indicating reason for failure.
- * @retval     NRF_ERROR_INVALID_STATE is returned is API is called without module initialization.
- * @retval     NRF_ERROR_NULL          if NULL parameter has been passed.
- * @retval     NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API.
- * @retval     NRF_ERROR_INVALID_ADDR  in case data address 'p_src' is not aligned.
- * @retval     NRF_ERROR_NO_MEM        in case request cannot be processed.
- *
- * @warning    No copy of the data is made, and hence memory provided for data source to be written
- *             to flash cannot be freed or reused by the application until this procedure
- *             is complete. End of this procedure is notified to the application using the
- *             notification callback registered by the application.
- */
-uint32_t pstorage_raw_store(pstorage_handle_t * p_dest,
-                            uint8_t *           p_src,
-                            pstorage_size_t     size,
-                            pstorage_size_t     offset);
-
-/**@brief      Function for clearing data in persistent memory in raw mode.
- *
- * @param[in]  p_dest Base block identifier in persistent memory that needs to cleared;
- *                    Equivalent to an Erase Operation.
- * @param[in]  size   Size of data to be cleared from persistent memory expressed in bytes.
- *                    This is currently unused. And a clear would mean clearing all blocks,
- *                    however, this parameter is to provision for clearing of certain blocks
- *                    of memory only and not all if need be.
- *
- * @retval     NRF_SUCCESS             on success, else an error code indicating reason for failure.
- * @retval     NRF_ERROR_INVALID_STATE is returned is API is called without module initialization.
- * @retval     NRF_ERROR_NULL          if NULL parameter has been passed.
- * @retval     NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API.
- * @retval     NRF_ERROR_NO_MEM        in case request cannot be processed.
- *
- * @note       Clear operations may take time. This API however, does not block until the clear
- *             procedure is complete. Application is notified of procedure completion using
- *             notification callback registered by the application. 'result' parameter of the
- *             callback suggests if the procedure was successful or not.
- */
-uint32_t pstorage_raw_clear(pstorage_handle_t * p_dest, pstorage_size_t size);
-
-#endif // PSTORAGE_RAW_MODE_ENABLE
-
-/**@} */
-/**@} */
-
-#ifdef __cplusplus
-}
-#endif /* #ifdef __cplusplus */
-
-#endif // PSTORAGE_H__
--- a/source/nordic-sdk/components/libraries/bootloader_dfu/bootloader.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,117 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
- 
-/**@file
- *
- * @defgroup nrf_bootloader Bootloader API.
- * @{     
- *
- * @brief Bootloader module interface.
- */
-
-#ifndef BOOTLOADER_H__
-#define BOOTLOADER_H__
-
-#include <stdbool.h>
-#include <stdint.h>
-#include "bootloader_types.h"
-#include "dfu_types.h"
-
-/**@brief Function for initializing the Bootloader.
- * 
- * @retval     NRF_SUCCESS If bootloader was succesfully initialized. 
- */
-uint32_t bootloader_init(void);
-
-/**@brief Function for validating application region in flash.
- * 
- * @param[in]  app_addr      Address to the region in flash where the application is stored.
- * 
- * @retval     true          If Application region is valid.
- * @retval     false         If Application region is not valid.
- */
-bool bootloader_app_is_valid(uint32_t app_addr);
-
-/**@brief Function for starting the Device Firmware Update.
- * 
- * @retval     NRF_SUCCESS If new application image was successfully transferred.
- */
-uint32_t bootloader_dfu_start(void);
-
-/**@brief Function for exiting bootloader and booting into application.
- *
- * @details This function will disable SoftDevice and all interrupts before jumping to application.
- *          The SoftDevice vector table base for interrupt forwarding will be set the application
- *          address.
- *
- * @param[in]  app_addr      Address to the region where the application is stored.
- */
-void bootloader_app_start(uint32_t app_addr);
-
-/**@brief Function for retrieving the bootloader settings.
- *
- * @param[out] p_settings    A copy of the current bootloader settings is returned in the structure
- *                           provided.
- */
-void bootloader_settings_get(bootloader_settings_t * const p_settings);
-
-/**@brief Function for processing DFU status update.
- *
- * @param[in]  update_status DFU update status.
- */
-void bootloader_dfu_update_process(dfu_update_status_t update_status);
-
-/**@brief Function getting state of SoftDevice update in progress.
- *        After a successfull SoftDevice transfer the system restarts in orderto disable SoftDevice
- *        and complete the update.
- *
- * @retval     true          A SoftDevice update is in progress. This indicates that second stage 
- *                           of a SoftDevice update procedure can be initiated.
- * @retval     false         No SoftDevice update is in progress.
- */
-bool bootloader_dfu_sd_in_progress(void);
-
-/**@brief Function for continuing the Device Firmware Update of a SoftDevice.
- * 
- * @retval     NRF_SUCCESS If the final stage of SoftDevice update was successful. 
- */
-uint32_t bootloader_dfu_sd_update_continue(void);
-
-/**@brief Function for finalizing the Device Firmware Update of a SoftDevice.
- * 
- * @retval     NRF_SUCCESS If the final stage of SoftDevice update was successful. 
- */
-uint32_t bootloader_dfu_sd_update_finalize(void);
-
-#endif // BOOTLOADER_H__
-
-/**@} */
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/bootloader_dfu/bootloader_types.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,79 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
- 
-/**@file
- *
- * @defgroup nrf_bootloader_types Types and definitions.
- * @{     
- *  
- * @ingroup nrf_bootloader
- * 
- * @brief Bootloader module type and definitions.
- */
- 
-#ifndef BOOTLOADER_TYPES_H__
-#define BOOTLOADER_TYPES_H__
-
-#include <stdint.h>
-
-#define BOOTLOADER_DFU_START 0xB1
-
-#define BOOTLOADER_SVC_APP_DATA_PTR_GET 0x02
-
-/**@brief DFU Bank state code, which indicates wether the bank contains: A valid image, invalid image, or an erased flash.
-  */
-typedef enum
-{
-    BANK_VALID_APP   = 0x01,
-    BANK_VALID_SD    = 0xA5,
-    BANK_VALID_BOOT  = 0xAA,
-    BANK_ERASED      = 0xFE,
-    BANK_INVALID_APP = 0xFF,
-} bootloader_bank_code_t;
-
-/**@brief Structure holding bootloader settings for application and bank data.
- */
-typedef struct
-{
-    bootloader_bank_code_t bank_0;          /**< Variable to store if bank 0 contains a valid application. */
-    uint16_t               bank_0_crc;      /**< If bank is valid, this field will contain a valid CRC of the total image. */
-    bootloader_bank_code_t bank_1;          /**< Variable to store if bank 1 has been erased/prepared for new image. Bank 1 is only used in Banked Update scenario. */
-    uint32_t               bank_0_size;     /**< Size of active image in bank0 if present, otherwise 0. */
-    uint32_t               sd_image_size;   /**< Size of SoftDevice image in bank0 if bank_0 code is BANK_VALID_SD. */
-    uint32_t               bl_image_size;   /**< Size of Bootloader image in bank0 if bank_0 code is BANK_VALID_SD. */
-    uint32_t               app_image_size;  /**< Size of Application image in bank0 if bank_0 code is BANK_VALID_SD. */
-    uint32_t               sd_image_start;  /**< Location in flash where SoftDevice image is stored for SoftDevice update. */
-} bootloader_settings_t;
-
-#endif // BOOTLOADER_TYPES_H__ 
-
-/**@} */
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/bootloader_dfu/bootloader_util.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
- /**@file
- *
- * @defgroup nrf_bootloader_util Bootloader util API.
- * @{     
- *  
- * @brief Bootloader util module interface.
- */
- 
-#ifndef BOOTLOADER_UTIL_H__
-#define BOOTLOADER_UTIL_H__
-
-#include <stdint.h>
-#include "bootloader_types.h"
-
-/**@brief Function for starting the application (or bootloader) at the provided address.
- * 
- * @param[in]  start_addr             Start address.
- *
- * @note This function will never retrun. Instead it will reset into the application of the 
- *       provided address.
- */
-void bootloader_util_app_start(uint32_t start_addr);
-
-#endif // BOOTLOADER_UTIL_H__
-
-/**@} */
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/bootloader_dfu/bootloader_util_arm.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,135 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-#include "compiler_abstraction.h"
-#include "bootloader_util.h"
-#include <stdint.h>
-#include <string.h>
-
-/**
- * @brief Function for aborting current application/bootloader jump to to other app/bootloader.
- *
- * @details This functions will use the address provide to swap the stack pointer and then load
- *          the address of the reset handler to be executed. It will check current system mode
- *          (thread/handler) and if in thread mode it will reset into other application.
- *          If in handler mode \ref isr_abort will be executed to ensure correct exit of handler
- *          mode and jump into reset handler of other application.
- *
- * @param[in]  start_addr  Start address of other application. This address must point to the
-               initial stack pointer of the application.
- *
- * @note This function will never return but issue a reset into provided application.
- */
-#ifdef TOOLCHAIN_ARM
-__asm static void bootloader_util_reset(uint32_t start_addr)
-{
-MASK_ONES       EQU 0xFFFFFFFF  ; Ones, to be loaded into register as default value before reset.
-MASK_ZEROS      EQU 0x00000000  ; Zeros, to be loaded into register as default value before reset.
-xPSR_RESET      EQU 0x21000000  ; Default value of xPSR after System Reset.
-EXC_RETURN_CMD  EQU 0xFFFFFFF9  ; EXC_RETURN for ARM Cortex. When loaded to PC the current interrupt service routine (handler mode) willl exit and the stack will be popped. Execution will continue in thread mode.
-    LDR   R5, [R0]              ; Get App initial MSP for bootloader.
-    MSR   MSP, R5               ; Set the main stack pointer to the applications MSP.
-    LDR   R6, [R0, #0x04]       ; Load Reset handler into register 6.
-
-    LDR   R2, =MASK_ZEROS       ; Load zeros to R2
-    MRS   R3, IPSR              ; Load IPSR to R3 to check for handler or thread mode
-    CMP   R2, R3                ; Compare, if 0 then we are in thread mode and can continue to reset handler of bootloader
-    MOV   R0, R6
-    BNE   isr_abort             ; If not zero we need to exit current ISR and jump to reset handler of bootloader
-
-    LDR   R4, =MASK_ONES        ; Load ones to R4 to be placed in Link Register.
-    MOV   LR, R4                ; Clear the link register and set to ones to ensure no return.
-    BX    R6                    ; Branch to reset handler of bootloader
-isr_abort
-    LDR   R4,=MASK_ONES         ; Fill with ones before jumping to reset handling. We be popped as R12 when exiting ISR (Cleaning up the registers).
-    LDR   R5,=MASK_ONES         ; Fill with ones before jumping to reset handling. We be popped as LR when exiting ISR. Ensures no return to application.
-    MOV   R6, R0                ; Move address of reset handler to R6. Will be popped as PC when exiting ISR. Ensures the reset handler will be executed when exist ISR.
-    LDR   R7,=xPSR_RESET        ; Move reset value of xPSR to R7. Will be popped as xPSR when exiting ISR.
-    PUSH  {r4-r7}               ; Push everything to new stack to allow interrupt handler to fetch it on exiting the ISR.
-
-    LDR   R4,=MASK_ZEROS        ; Fill with zeros before jumping to reset handling. We be popped as R0 when exiting ISR (Cleaning up of the registers).
-    LDR   R5,=MASK_ZEROS        ; Fill with zeros before jumping to reset handling. We be popped as R1 when exiting ISR (Cleaning up of the registers).
-    LDR   R6,=MASK_ZEROS        ; Fill with zeros before jumping to reset handling. We be popped as R2 when exiting ISR (Cleaning up of the registers).
-    LDR   R7,=MASK_ZEROS        ; Fill with zeros before jumping to reset handling. We be popped as R3 when exiting ISR (Cleaning up of the registers).
-    PUSH  {r4-r7}               ; Push zeros (R4-R7) to stack to prepare for exiting the interrupt routine.
-
-    LDR   R0,=EXC_RETURN_CMD    ; Load the execution return command into register.
-    BX    R0                    ; No return - Handler mode will be exited. Stack will be popped and execution will continue in reset handler initializing other application.
-    ALIGN
-}
-#elif defined(TOOLCHAIN_GCC)
-static void bootloader_util_reset(uint32_t start_addr)
-{
-    __ASM(
-        ".equ MASK_ONES,  0xFFFFFFFF\n\t" /* Ones, to be loaded into register as default value before reset.  */
-        ".equ MASK_ZEROS, 0x00000000\n\t" /* Zeros, to be loaded into register as default value before reset. */
-        ".equ xPSR_RESET, 0x21000000\n\t" /* Default value of xPSR after System Reset. */
-        ".equ EXC_RETURN_CMD, 0xFFFFFFF9\n\t" /* EXC_RETURN for ARM Cortex. When loaded to PC the current interrupt service routine (handler mode) willl exit and the stack will be popped. Execution will continue in thread mode. */
-
-        "LDR   r5, [r0]       \n\t"       /* Get App initial MSP for bootloader.                              */
-        "MSR   MSP, r5        \n\t"       /* Set the main stack pointer to the applications MSP.              */
-        "LDR   r6,[r0, #0x04] \n\t"       /* Load Reset handler into register 0.                              */
-
-        "LDR   r2, =MASK_ZEROS\n\t"       /* Load zeros to R2                                                 */
-        "MRS   r3, IPSR       \n\t"       /* Load IPSR to R3 to check for handler or thread mode              */
-        "CMP   r2, r3         \n\t"       /* Compare, if 0 then we are in thread mode and can continue to reset handler of bootloader */
-        "MOV   R0, R6         \n\t"
-        "BNE   isr_abort      \n\t"       /* If not zero we need to exit current ISR and jump to reset handler of bootloader */
-
-        "LDR   r4, =MASK_ONES \n\t"       /* Load ones to R4 to be placed in Link Register.                   */
-        "MOV   LR, r4         \n\t"       /* Clear the link register and set to ones to ensure no return.     */
-        "BX    r6             \n\t"       /* Branch to reset handler of bootloader                            */
-        "isr_abort:           \n\t"
-        "LDR   R4,=MASK_ONES \n\t" /* Fill with ones before jumping to reset handling. We be popped as R12 when exiting ISR (Cleaning up the registers). */
-        "LDR   R5,=MASK_ONES \n\t" /* Fill with ones before jumping to reset handling. We be popped as LR when exiting ISR. Ensures no return to application. */
-        "MOV   R6, R0        \n\t" /* Move address of reset handler to R6. Will be popped as PC when exiting ISR. Ensures the reset handler will be executed when exist ISR. */
-        "LDR   R7,=xPSR_RESET\n\t" /* Move reset value of xPSR to R7. Will be popped as xPSR when exiting ISR. */
-        "PUSH  {r4-r7}       \n\t" /* Push everything to new stack to allow interrupt handler to fetch it on exiting the ISR. */
-
-        "LDR   R4,=MASK_ZEROS\n\t" /* Fill with zeros before jumping to reset handling. We be popped as R0 when exiting ISR (Cleaning up of the registers). */
-        "LDR   R5,=MASK_ZEROS\n\t" /* Fill with zeros before jumping to reset handling. We be popped as R1 when exiting ISR (Cleaning up of the registers). */
-        "LDR   R6,=MASK_ZEROS\n\t" /* Fill with zeros before jumping to reset handling. We be popped as R2 when exiting ISR (Cleaning up of the registers). */
-        "LDR   R7,=MASK_ZEROS\n\t" /* Fill with zeros before jumping to reset handling. We be popped as R3 when exiting ISR (Cleaning up of the registers). */
-        "PUSH  {r4-r7}       \n\t" /* Push zeros (R4-R7) to stack to prepare for exiting the interrupt routine. */
-
-        "LDR   R0,=EXC_RETURN_CMD\n\t" /* Load the execution return command into register. */
-        "BX    R0                \n\t" /* No return - Handler mode will be exited. Stack will be popped and execution will continue in reset handler initializing other application. */
-        : /* output operands */
-        : /* input operands */
-        : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7" /* clobber list */
-        );
-}
-#endif /* TOOLCHAIN_ARM */
-
-void bootloader_util_app_start(uint32_t start_addr)
-{
-    bootloader_util_reset(start_addr);
-}
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/bootloader_dfu/dfu.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,154 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
- 
-/**@file
- *
- * @defgroup nrf_dfu Device Firmware Update API.
- * @{     
- *
- * @brief Device Firmware Update module interface.
- */
-
-#ifndef DFU_H__
-#define DFU_H__
-
-#include "dfu_types.h"
-#include <stdbool.h>
-#include <stdint.h>
-
-
-/**@brief DFU event callback for asynchronous calls.
- *
- * @param[in] packet  Packet type for which this callback is related. START_PACKET, DATA_PACKET.
- * @param[in] result  Operation result code. NRF_SUCCESS when a queued operation was successful.
- * @param[in] p_data  Pointer to the data to which the operation is related.
- */
-typedef void (*dfu_callback_t)(uint32_t packet, uint32_t  result, uint8_t * p_data);
-
-/**@brief Function for initializing the Device Firmware Update module.
- * 
- * @return    NRF_SUCCESS on success, an error_code otherwise.
- */
-uint32_t dfu_init(void);
-
-/**@brief Function for registering a callback listener for \ref dfu_data_pkt_handle callbacks.
- *
- * @param[in] callback_handler  Callback handler for receiving DFU events on completed operations
- *                              of DFU packets.
- */
-void dfu_register_callback(dfu_callback_t callback_handler);
-
-/**@brief Function for setting the DFU image size. 
- *
- * @details Function sets the DFU image size. This function must be called when an update is started 
- *          in order to notify the DFU of the new image size. If multiple images are to be 
- *          transferred within the same update context then this function must be called with size 
- *          information for each image being transfered.
- *          If an image type is not being transfered, e.g. SoftDevice but no Application , then the
- *          image size for application must be zero.
- * 
- * @param[in] p_packet   Pointer to the DFU packet containing information on DFU update process to
- *                       be started.
- *
- * @return    NRF_SUCCESS on success, an error_code otherwise.
- */
-uint32_t dfu_start_pkt_handle(dfu_update_packet_t * p_packet);
-
-/**@brief Function for handling DFU data packets.
- *
- * @param[in] p_packet   Pointer to the DFU packet.
- *
- * @return    NRF_SUCCESS on success, an error_code otherwise.
- */
-uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet);
-
-/**@brief Function for handling DFU init packets.
- *
- * @return    NRF_SUCCESS on success, an error_code otherwise.
- */
-uint32_t dfu_init_pkt_handle(dfu_update_packet_t * p_packet);
-
-/**@brief Function for validating a transferred image after the transfer has completed.
- * 
- * @return    NRF_SUCCESS on success, an error_code otherwise.
- */
-uint32_t dfu_image_validate(void);
-
-/**@brief Function for activating the transfered image after validation has successfully completed.
- *
- * @return    NRF_SUCCESS on success, an error_code otherwise.
- */
-uint32_t dfu_image_activate(void);
-
-/**@brief Function for reseting the current update procedure and return to initial state.
- *        
- * @details This function call will result in a system reset to ensure correct system behavior.
- *          The reset will might be scheduled to execute at a later point in time to ensure pending 
- *          flash operations has completed.
- */
-void dfu_reset(void);
-
-/**@brief Function for validating that new bootloader has been correctly installed.
- *        
- * @return NRF_SUCCESS if install was successful. NRF_ERROR_NULL if the images differs.
- */
-uint32_t dfu_bl_image_validate(void);
-
-/**@brief Function for validating that new SoftDevicehas been correctly installed.
- *        
- * @return NRF_SUCCESS if install was successful. NRF_ERROR_NULL if the images differs.
- */
-uint32_t dfu_sd_image_validate(void);
-
-/**@brief Function for swapping existing bootloader with newly received.
- *        
- * @return NRF_SUCCESS on succesfull swapping. For error code please refer to 
- *         \ref sd_mbr_command_copy_bl_t.
- */
-uint32_t dfu_bl_image_swap(void);
-
-/**@brief Function for swapping existing SoftDevice with newly received.
- *        
- * @return NRF_SUCCESS on succesfull swapping. For error code please refer to 
- *         \ref sd_mbr_command_copy_sd_t.
- */
-uint32_t dfu_sd_image_swap(void);
-
-/**@brief Function for handling DFU init packet complete.
- *
- * @return    NRF_SUCCESS on success, an error_code otherwise.
- */
-uint32_t dfu_init_pkt_complete(void);
-
-#endif // DFU_H__
-
-/** @} */
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/bootloader_dfu/dfu_bank_internal.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,107 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
- 
-/**@file
- *
- * @defgroup dfu_bank_internal Device Firmware Update internal header for bank handling in DFU.
- * @{     
- *
- * @brief Device Firmware Update Bank handling module interface.
- *
- * @details This header is intended for shared definition and functions between single and dual bank 
- *         implementations used for DFU support. It is not supposed to be used for external access 
- *         to the DFU module.
- *  
- */
-#ifndef DFU_BANK_INTERNAL_H__
-#define DFU_BANK_INTERNAL_H__
-
-#include "dfu_types.h"
-
-/**@brief States of the DFU state machine. */
-typedef enum
-{
-    DFU_STATE_INIT_ERROR,                                                           /**< State for: dfu_init(...) error. */
-    DFU_STATE_IDLE,                                                                 /**< State for: idle. */
-    DFU_STATE_PREPARING,                                                            /**< State for: preparing, indicates that the flash is being erased and no data packets can be processed. */
-    DFU_STATE_RDY,                                                                  /**< State for: ready. */
-    DFU_STATE_RX_INIT_PKT,                                                          /**< State for: receiving initialization packet. */
-    DFU_STATE_RX_DATA_PKT,                                                          /**< State for: receiving data packet. */
-    DFU_STATE_VALIDATE,                                                             /**< State for: validate. */
-    DFU_STATE_WAIT_4_ACTIVATE                                                       /**< State for: waiting for dfu_image_activate(). */
-} dfu_state_t;
-
-#define APP_TIMER_PRESCALER         0                                               /**< Value of the RTC1 PRESCALER register. */
-#define DFU_TIMEOUT_INTERVAL        APP_TIMER_TICKS(120000, APP_TIMER_PRESCALER)    /**< DFU timeout interval in units of timer ticks. */     
-
-#define IS_UPDATING_SD(START_PKT)   ((START_PKT).dfu_update_mode & DFU_UPDATE_SD)   /**< Macro for determining if a SoftDevice update is ongoing. */
-#define IS_UPDATING_BL(START_PKT)   ((START_PKT).dfu_update_mode & DFU_UPDATE_BL)   /**< Macro for determining if a Bootloader update is ongoing. */
-#define IS_UPDATING_APP(START_PKT)  ((START_PKT).dfu_update_mode & DFU_UPDATE_APP)  /**< Macro for determining if a Application update is ongoing. */
-#define IMAGE_WRITE_IN_PROGRESS()   (m_data_received > 0)                           /**< Macro for determining if an image write is in progress. */
-#define IS_WORD_SIZED(SIZE)         ((SIZE & (sizeof(uint32_t) - 1)) == 0)          /**< Macro for checking that the provided is word sized. */
-
-/**@cond NO_DOXYGEN */
-static uint32_t                     m_data_received;                                /**< Amount of received data. */
-/**@endcond */
-
-/**@brief     Type definition of function used for preparing of the bank before receiving of a
- *            software image.
- *
- * @param[in] image_size  Size of software image being received.
- */
-typedef void (*dfu_bank_prepare_t)(uint32_t image_size);
-
-/**@brief     Type definition of function used for handling clear complete of the bank before 
- *            receiving of a software image.
- */
-typedef void (*dfu_bank_cleared_t)(void);
-
-/**@brief    Type definition of function used for activating of the software image received.
- *
- * @return  NRF_SUCCESS If the image has been successfully activated any other NRF_ERROR code in
- *          case of a failure.
- */
-typedef uint32_t (*dfu_bank_activate_t)(void);
-
-/**@brief Structure for holding of function pointers for needed prepare and activate procedure for
- *        the requested update procedure. 
- */
-typedef struct
-{
-    dfu_bank_prepare_t  prepare;                                                    /**< Function pointer to the prepare function called on start of update procedure. */
-    dfu_bank_cleared_t  cleared;                                                    /**< Function pointer to the cleared function called after prepare function completes. */
-    dfu_bank_activate_t activate;                                                   /**< Function pointer to the activate function called on finalizing the update procedure. */
-} dfu_bank_func_t;
-
-#endif // DFU_BANK_INTERNAL_H__
-
-/** @} */
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/bootloader_dfu/dfu_ble_svc.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,100 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-  
-/** @file
- *
- * @defgroup nrf_dfu_ble_svc DFU BLE SVC 
- * @{
- *
- * @brief DFU BLE SVC in bootloader. The DFU BLE SuperVisor Calls allow an application to execute
- *        functions in the installed bootloader. 
- *
- * @details This module implements handling of SuperVisor Calls in the bootloader. 
- *          SuperVisor Calls allow for an application to execute calls into the bootloader.
- *          Currently, it is possible to exchange bonding information (like keys) from the 
- *          application to a bootloader supporting DFU OTA using BLE, so the update process can be 
- *          done through an already existing bond.
- *
- * @note The application must make sure that all SuperVisor Calls (SVC) are forwarded to the 
- *       bootloader to ensure correct behavior. Forwarding of SVCs to the bootloader is 
- *       done using the SoftDevice SVC @ref sd_softdevice_vector_table_base_set with the value 
- *       present in @c NRF_UICR->BOOTLOADERADDR.
- */
- 
-#ifndef DFU_BLE_SVC_H__
-#define DFU_BLE_SVC_H__
-
-#include "nrf_svc.h"
-#include <stdint.h>
-#include "ble_gap.h"
-#include "nrf51.h"
-#include "nrf_soc.h"
-#include "nrf_error_sdm.h"
-
-#define BOOTLOADER_SVC_BASE     0x0     /**< The number of the lowest SVC number reserved for the bootloader. */
-#define SYSTEM_SERVICE_ATT_SIZE 8       /**< Size of the system service attribute length including CRC-16 at the end. */  
-
-/**@brief The SVC numbers used by the SVC functions in the SoC library. */
-enum BOOTLOADER_SVCS
-{
-    DFU_BLE_SVC_SET_PEER_DATA = BOOTLOADER_SVC_BASE,    /**< SVC number for the setting of peer data call. */
-    BOOTLOADER_SVC_LAST
-};
-
-/**@brief   DFU Peer data structure.
- *
- * @details This structure contains peer data needed for connection to a bonded device during DFU.
- *          The peer data must be provided by the application to the bootloader during buttonless
- *          update. See @ref dfu_ble_svc_set_peer_data. It contains bond information about the
- *          desired DFU peer.
- */
-typedef struct
-{
-    ble_gap_addr_t      addr;                                   /**< BLE GAP address of the device that initiated the DFU process. */
-    ble_gap_irk_t       irk;                                    /**< IRK of the device that initiated the DFU process if this device uses Private Resolvable Addresses. */
-    ble_gap_enc_key_t   enc_key;                                /**< Encryption key structure containing encrypted diversifier and LTK for re-establishing the bond. */
-    uint8_t             sys_serv_attr[SYSTEM_SERVICE_ATT_SIZE]; /**< System service attributes for restoring of Service Changed Indication setting in DFU mode. */
-} dfu_ble_peer_data_t;
-
-/**@brief   SVC Function for setting peer data containing address, IRK, and LTK to establish bonded
- *          connection in DFU mode.
- *
- * @param[in] p_peer_data  Pointer to the peer data containing keys for the connection.
- *
- * @retval NRF_ERROR_NULL If a NULL pointer was provided as argument.
- * @retval NRF_SUCCESS    If the function completed successfully.
- */
-SVCALL(DFU_BLE_SVC_SET_PEER_DATA, uint32_t, dfu_ble_svc_set_peer_data(dfu_ble_peer_data_t * p_peer_data));
-
-#endif // DFU_BLE_SVC_H__
-
-/** @} */
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/bootloader_dfu/dfu_ble_svc_internal.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-  
-/** @file
- *
- * @defgroup nrf_dfu_ble_svc_internal DFU BLE SVC internal
- * @{
- *
- * @brief DFU BLE SVC internal functions in bootloader. The DFU BLE SuperVisor Calls allow an 
- *        application to execute functions in the installed bootloader. This interface provides 
- *        internal Bootloader DFU functions for retrieving data exchanged through SuperVisor Calls.
- *
- */
-
-#ifndef DFU_BLE_SVC_INTERNAL_H__
-#define DFU_BLE_SVC_INTERNAL_H__
-
-#include <stdint.h>
-#include "dfu_ble_svc.h"
-#include "ble_gap.h"
-
-/**@brief Internal bootloader/DFU function for retrieving peer data provided from application.
- *
- * @param[out] p_peer_data Peer data set by application to be used for DFU connection.
- *
- * @retval NRF_SUCCES             If peer data is valid and can be used for connection.
- * @retval NRF_ERROR_INVALID_DATA If peer data is not available or invalid.
- */
-uint32_t dfu_ble_get_peer_data(dfu_ble_peer_data_t * p_peer_data);
-
-#endif // DFU_BLE_SVC_INTERNAL_H__
-
-/** @} */
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/bootloader_dfu/dfu_init.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,154 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/**@file
- *
- * @defgroup nrf_dfu_init Init packet handling in DFU.
- * @{
- *
- * @brief Device Firmware Update module type and function declaration for init packet handling.
- *
- * @details This header contains basic functionality for performing safety checks on software 
- *          updates for nRF51 based devices. It provides a skeleton for pre-checking an init packet
- *          to ensure the following image is compatible with this device. A safety check should 
- *          always be performed to prevent accidental flashing of unsupported applications or a
- *          wrong combination of application and SoftDevice.
- *          The device information contains information such as:
- *          - Device type (2 bytes), for example Heart Rate. The device type is a number defined by
- *            the customer. It can be located in UICR or FICR.
- *          - Device revision (2 bytes), for example major revision 1, minor revision 0. The device
- *            revision is a number defined by the customer. It can be located in UICR or FICR.
- *          - List of SoftDevices supported by this application, for example 
- *              0x0049 = S110v6_0_0 
- *              0xFFFE = S110 development (any SoftDevice accepted),
- *          - CRC or hash of firmware image
- *
- * @note This module does not support security features such as image signing, but the corresponding
- *       implementation allows for such extensions.
- *       If the init packet is signed by a trusted source, it must be decrypted before it can be 
- *       processed.
- */
-
-#ifndef DFU_INIT_H__
-#define DFU_INIT_H__
-
-#include <stdint.h>
-#include "nrf51.h"
-
-/**@brief Structure contained in an init packet. Contains information on device type, revision, and 
- *        supported SoftDevices.
- */
-typedef struct
-{
-    uint16_t device_type;                                                                   /**< Device type (2 bytes), for example Heart Rate. This number must be defined by the customer before production. It can be located in UICR or FICR. */
-    uint16_t device_rev;                                                                    /**< Device revision (2 bytes), for example major revision 1, minor revision 0. This number must be defined by the customer before production. It can be located in UICR or FICR. */
-    uint32_t app_version;                                                                   /**< Application version for the image software. This field allows for additional checking, for example ensuring that a downgrade is not allowed. */
-    uint16_t softdevice_len;                                                                /**< Number of different SoftDevice revisions compatible with this application. The list of SoftDevice firmware IDs is defined in @ref softdevice. */
-    uint16_t softdevice[1];                                                                 /**< Variable length array of SoftDevices compatible with this application. The length of the array is specified in the length field. SoftDevice firmware id 0xFFFE indicates any SoftDevice. */
-} dfu_init_packet_t;
-
-/**@brief Structure holding basic device information settings.
- */
-typedef struct
-{
-    uint16_t device_type;                                                                   /**< Device type (2 bytes), for example Heart Rate. This number must be defined by the customer before production. It can be located in UICR or FICR. */
-    uint16_t device_rev;                                                                    /**< Device revision (2 bytes), for example major revision 1, minor revision 0. This number must be defined by the customer before production. It can be located in UICR or FICR. */
-} dfu_device_info_t;
-
-/** The device info offset can be modified to place the device info settings at a different location.
-  * If the customer reserved UICR location is used for other application specific data, the offset
-  * must be updated to avoid collision with that data.
-  */
-/** [DFU UICR DEV offset] */
-#define UICR_CUSTOMER_DEVICE_INFO_OFFSET    0x0                                             /**< Device info offset inside the customer UICR reserved area. Customers may change this value to place the device information in a user-preferred location. */
-/** [DFU UICR DEV offset] */
-
-#define UICR_CUSTOMER_RESERVED_OFFSET       0x80                                            /**< Customer reserved area in the UICR. The area from UICR + 0x80 is reserved for customer usage. */
-#define DFU_DEVICE_INFO_BASE                (NRF_UICR_BASE + \
-                                             UICR_CUSTOMER_RESERVED_OFFSET + \
-                                             UICR_CUSTOMER_DEVICE_INFO_OFFSET)              /**< The device information base address inside of UICR. */
-#define DFU_DEVICE_INFO                     ((dfu_device_info_t *)DFU_DEVICE_INFO_BASE)     /**< The memory mapped structure for device information data. */
-
-#define DFU_DEVICE_TYPE_EMPTY               ((uint16_t)0xFFFF)                              /**< Mask indicating no device type is present in UICR. 0xFFFF is default flash pattern when not written with data. */
-#define DFU_DEVICE_REVISION_EMPTY           ((uint16_t)0xFFFF)                              /**< Mask indicating no device revision is present in UICR. 0xFFFF is default flash pattern when not written with data. */
-#define DFU_SOFTDEVICE_ANY                  ((uint16_t)0xFFFE)                              /**< Mask indicating that any SoftDevice is allowed for updating this application. Allows for easy development. Not to be used in production images. */
-
-
-/**@brief DFU prevalidate call for pre-checking the received init packet.
- *
- * @details  Pre-validation will safety check the firmware image to be transfered in second stage.
- *           The function currently checks the device type, device revision, application firmware 
- *           version, and supported SoftDevices. More checks should be added according to 
- *           customer-specific requirements.
- * 
- * @param[in] p_init_data    Pointer to the init packet. If the init packet is encrypted or signed,
- *                           it must first be decrypted before being checked.
- * @param[in] init_data_len  Length of the init data.
- *
- * @retval NRF_SUCCESS              If the pre-validation succeeded, that means the image is 
- *                                  supported by the device and it is considered to come from a 
- *                                  trusted source (signing).
- * @retval NRF_ERROR_INVALID_DATA   If the pre-validation failed, that means the image is not 
- *                                  supported by the device or comes from an un-trusted source 
- *                                  (signing).
- * @retval NRF_ERROR_INVALID_LENGTH If the size of the init packet is not within the limits of 
- *                                  the init packet handler.
- */
-uint32_t dfu_init_prevalidate(uint8_t * p_init_data, uint32_t init_data_len);
-
-/**@brief DFU postvalidate call for post-checking the received image using the init packet.
- *
- * @details  Post-validation can verify the integrity check the firmware image received before 
- *           activating the image.
- *           Checks performed can be: 
- *           - A simple CRC as shown in the corresponding implementation of this API in the file
- *             dfu_init_template.c
- *           - A hash for better verification of the image.
- *           - A signature to ensure the image originates from a trusted source.
- *           Checks are intended to be expanded for customer-specific requirements.
- * 
- * @param[in] p_image    Pointer to the received image. The init data provided in the call 
- *                       \ref dfu_init_prevalidate will be used for validating the image.
- * @param[in] image_len  Length of the image data.
- *
- * @retval NRF_SUCCESS             If the post-validation succeeded, that meant the integrity of the
- *                                 image has been verified and the image originates from a trusted 
- *                                 source (signing).
- * @retval NRF_ERROR_INVALID_DATA  If the post-validation failed, that meant the post check of the 
- *                                 image failed such as the CRC is not matching the image transfered
- *                                 or the verification of the image fails (signing).
- */
-uint32_t dfu_init_postvalidate(uint8_t * p_image, uint32_t image_len);
-
-#endif // DFU_INIT_H__
-
-/**@} */
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/bootloader_dfu/dfu_init_template.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,176 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/**@file
- *
- * @defgroup nrf_dfu_init_template Template file with an DFU init packet handling example.
- * @{
- *
- * @ingroup nrf_dfu
- *
- * @brief This file contains a template on how to implement DFU init packet handling.
- *
- * @details The template shows how device type and revision can be used for a safety check of the 
- *          received image. It shows how validation can be performed in two stages:
- *          - Stage 1: Pre-check of firmware image before transfer to ensure the firmware matches:
- *                     - Device Type.
- *                     - Device Revision.
- *                     Installed SoftDevice.
- *                     This template can be extended with additional checks according to needs.
- *                     For example, such a check could be the origin of the image (trusted source) 
- *                     based on a signature scheme.
- *          - Stage 2: Post-check of the image after image transfer but before installing firmware.
- *                     For example, such a check could be an integrity check in form of hashing or 
- *                     verification of a signature.
- *                     In this template, a simple CRC check is carried out.
- *                     The CRC check can be replaced with other mechanisms, like signing.
- *
- * @note This module does not support security features such as image signing, but the 
- *       implementation allows for such extension.
- *       If the init packet is signed by a trusted source, it must be decrypted before it can be
- *       processed.
- */
-
-#include "dfu_init.h"
-#include <stdint.h>
-#include <string.h>
-#include "dfu_types.h"
-#include "nrf_error.h"
-#include "crc16.h"
-
-#define DFU_INIT_PACKET_EXT_LENGTH_MIN      2                       //< Minimum length of the extended init packet. The extended init packet may contain a CRC, a HASH, or other data. This value must be changed according to the requirements of the system. The template uses a minimum value of two in order to hold a CRC. */
-#define DFU_INIT_PACKET_EXT_LENGTH_MAX      10                      //< Maximum length of the extended init packet. The extended init packet may contain a CRC, a HASH, or other data. This value must be changed according to the requirements of the system. The template uses a maximum value of 10 in order to hold a CRC and any padded data on transport layer without overflow. */
-
-static uint8_t m_extended_packet[DFU_INIT_PACKET_EXT_LENGTH_MAX];   //< Data array for storage of the extended data received. The extended data follows the normal init data of type \ref dfu_init_packet_t. Extended data can be used for a CRC, hash, signature, or other data. */
-static uint8_t m_extended_packet_length;                            //< Length of the extended data received with init packet. */
-
-
-uint32_t dfu_init_prevalidate(uint8_t * p_init_data, uint32_t init_data_len)
-{
-    uint32_t i = 0;
-    
-    // In order to support signing or encryption then any init packet decryption function / library
-    // should be called from here or implemented at this location.
-
-    // Length check to ensure valid data are parsed.
-    if (init_data_len < sizeof(dfu_init_packet_t))
-    {
-        return NRF_ERROR_INVALID_LENGTH;
-    }
-
-    // Current template uses clear text data so they can be casted for pre-check.
-    dfu_init_packet_t * p_init_packet = (dfu_init_packet_t *)p_init_data;
-
-    m_extended_packet_length = ((uint32_t)p_init_data + init_data_len) -
-                               (uint32_t)&p_init_packet->softdevice[p_init_packet->softdevice_len];
-    if (m_extended_packet_length < DFU_INIT_PACKET_EXT_LENGTH_MIN)
-    {
-        return NRF_ERROR_INVALID_LENGTH;
-    }
-
-    if (((uint32_t)p_init_data + init_data_len) < 
-        (uint32_t)&p_init_packet->softdevice[p_init_packet->softdevice_len])
-    {
-        return NRF_ERROR_INVALID_LENGTH;
-    }
-
-    memcpy(m_extended_packet,
-           &p_init_packet->softdevice[p_init_packet->softdevice_len],
-           m_extended_packet_length);
-
-/** [DFU init application version] */
-    // To support application versioning, this check should be updated.
-    // This template allows for any application to be installed. However, 
-    // customers can place a revision number at the bottom of the application 
-    // to be verified by the bootloader. This can be done at a location 
-    // relative to the application, for example the application start 
-    // address + 0x0100.
-/** [DFU init application version] */
-    
-    // First check to verify the image to be transfered matches the device type.
-    // If no Device type is present in DFU_DEVICE_INFO then any image will be accepted.
-    if ((DFU_DEVICE_INFO->device_type != DFU_DEVICE_TYPE_EMPTY) &&
-        (p_init_packet->device_type != DFU_DEVICE_INFO->device_type))
-    {
-        return NRF_ERROR_INVALID_DATA;
-    }
-    
-    // Second check to verify the image to be transfered matches the device revision.
-    // If no Device revision is present in DFU_DEVICE_INFO then any image will be accepted.
-    if ((DFU_DEVICE_INFO->device_rev != DFU_DEVICE_REVISION_EMPTY) &&
-        (p_init_packet->device_rev != DFU_DEVICE_INFO->device_rev))
-    {
-        return NRF_ERROR_INVALID_DATA;
-    }
-
-    // Third check: Check the array of supported SoftDevices by this application.
-    //              If the installed SoftDevice does not match any SoftDevice in the list then an
-    //              error is returned.
-    while (i < p_init_packet->softdevice_len)
-    {
-        if (p_init_packet->softdevice[i] == DFU_SOFTDEVICE_ANY ||
-            p_init_packet->softdevice[i++] == SOFTDEVICE_INFORMATION->firmware_id)
-        {
-            return NRF_SUCCESS;
-        }
-    }
-    
-    // No matching SoftDevice found - Return NRF_ERROR_INVALID_DATA.
-    return NRF_ERROR_INVALID_DATA;
-}
-
-
-uint32_t dfu_init_postvalidate(uint8_t * p_image, uint32_t image_len)
-{
-#if NEED_CRC_CHECK /* disabled for now */
-    uint16_t image_crc;
-    uint16_t received_crc;
-    
-    // In order to support hashing (and signing) then the (decrypted) hash should be fetched and
-    // the corresponding hash should be calculated over the image at this location.
-    // If hashing (or signing) is added to the system then the CRC validation should be removed.
-
-    // calculate CRC from active block.
-    image_crc = crc16_compute(p_image, image_len, NULL);
-
-    // Decode the received CRC from extended data.    
-    received_crc = uint16_decode((uint8_t *)&m_extended_packet[0]);
-
-    // Compare the received and calculated CRC.
-    if (image_crc != received_crc)
-    {
-        return NRF_ERROR_INVALID_DATA;
-    }
-#endif /* NEED_CRC_CHECK */
-
-    return NRF_SUCCESS;
-}
--- a/source/nordic-sdk/components/libraries/bootloader_dfu/dfu_transport.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/**@file
- *
- * @defgroup nrf_dfu_transport DFU transport API.
- * @{     
- *  
- * @brief DFU transport module interface.
- */
- 
-#ifndef DFU_TRANSPORT_H__
-#define DFU_TRANSPORT_H__
-
-#include <stdint.h>
-
-/**@brief Function for starting the update of Device Firmware.
- *
- * @retval NRF_SUCCESS Operation success.   
- */
-uint32_t dfu_transport_update_start(void);
-
-/**@brief Function for closing the transport layer.
- *
- * @retval NRF_SUCCESS Operation success.    
- */
-uint32_t dfu_transport_close(void);
-
-#endif // DFU_TRANSPORT_H__
-
-/**@} */
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/bootloader_dfu/dfu_types.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,168 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/**@file
- *
- * @defgroup nrf_dfu_types Types and definitions.
- * @{
- *
- * @ingroup nrf_dfu
- *
- * @brief Device Firmware Update module type and definitions.
- */
-
-#ifndef DFU_TYPES_H__
-#define DFU_TYPES_H__
-
-#include <stdint.h>
-#include "nrf51.h"
-#include "app_util.h"
-
-/**@brief Structure holding SoftDevice information to be used by the Bootloader/DFU. 
- *        Only size field is used.
- */
-typedef struct
-{
-    uint8_t  info_size;                                                                                 /**< Not used. */
-    uint8_t  reserved1[3];                                                                              /**< Not used. */
-    uint32_t magic_number;                                                                              /**< Not used. */
-    uint32_t softdevice_size;                                                                           /**< Size field containing the size of installed SoftDevice. */
-    uint16_t firmware_id;                                                                               /**< Firmware id. */
-    uint8_t  reserved2[2];                                                                                 /**< Not used. */
-} SOFTDEVICE_INFORMATION_Type;
-
-#define SOFTDEVICE_INFORMATION_BASE     0x0003000                                                       /**< Location in the SoftDevice image which holds the SoftDevice informations. */
-#define SOFTDEVICE_INFORMATION          ((SOFTDEVICE_INFORMATION_Type *) SOFTDEVICE_INFORMATION_BASE)   /**< Make SoftDevice information accessible through the structure. */
-
-#define NRF_UICR_BOOT_START_ADDRESS     (NRF_UICR_BASE + 0x14)                                          /**< Register where the bootloader start address is stored in the UICR register. */
-
-#define CODE_REGION_1_START             SOFTDEVICE_INFORMATION->softdevice_size                         /**< This field should correspond to the size of Code Region 0, (which is identical to Start of Code Region 1), found in UICR.CLEN0 register. This value is used for compile safety, as the linker will fail if application expands into bootloader. Runtime, the bootloader will use the value found in UICR.CLEN0. */
-
-#define SOFTDEVICE_REGION_START         0x00001000                                                      /**< This field should correspond to start address of the bootloader, found in UICR.RESERVED, 0x10001014, register. This value is used for sanity check, so the bootloader will fail immediately if this value differs from runtime value. The value is used to determine max application size for updating. */
-#define BOOTLOADER_REGION_START         0x0003C000                                                      /**< This field should correspond to start address of the bootloader, found in UICR.RESERVED, 0x10001014, register. This value is used for sanity check, so the bootloader will fail immediately if this value differs from runtime value. The value is used to determine max application size for updating. */
-#define BOOTLOADER_SETTINGS_ADDRESS     0x0003FC00                                                      /**< The field specifies the page location of the bootloader settings address. */
-
-#define DFU_REGION_TOTAL_SIZE           (BOOTLOADER_REGION_START - CODE_REGION_1_START)                 /**< Total size of the region between SD and Bootloader. */
-
-#define DFU_APP_DATA_RESERVED           0x0000                                                          /**< Size of Application Data that must be preserved between application updates. This value must be a multiple of page size. Page size is 0x400 (1024d) bytes, thus this value must be 0x0000, 0x0400, 0x0800, 0x0C00, 0x1000, etc. */
-#define DFU_BANK_PADDING                (DFU_APP_DATA_RESERVED % (2 * CODE_PAGE_SIZE))                  /**< Padding to ensure that image size banked is always page sized. */
-#define DFU_IMAGE_MAX_SIZE_FULL         (DFU_REGION_TOTAL_SIZE - DFU_APP_DATA_RESERVED)                 /**< Maximum size of an application, excluding save data from the application. */
-#define DFU_IMAGE_MAX_SIZE_BANKED       ((DFU_REGION_TOTAL_SIZE - \
-                                          DFU_APP_DATA_RESERVED - \
-                                          DFU_BANK_PADDING) / 2)                                        /**< Maximum size of an application, excluding save data from the application. */
-
-#define DFU_BL_IMAGE_MAX_SIZE           (BOOTLOADER_SETTINGS_ADDRESS - BOOTLOADER_REGION_START)         /**< Maximum size of a bootloader, excluding save data from the current bootloader. */
-
-#define DFU_BANK_0_REGION_START         CODE_REGION_1_START                                             /**< Bank 0 region start. */
-#define DFU_BANK_1_REGION_START         (DFU_BANK_0_REGION_START + DFU_IMAGE_MAX_SIZE_BANKED)           /**< Bank 1 region start. */
-
-#define CODE_PAGE_SIZE                  0x0400                                                          /**< Size of a flash codepage. Used for size of the reserved flash space in the bootloader region. Will be runtime checked against NRF_UICR->CODEPAGESIZE to ensure the region is correct. */
-#define EMPTY_FLASH_MASK                0xFFFFFFFF                                                      /**< Bit mask that defines an empty address in flash. */
-
-#define INVALID_PACKET                  0x00                                                            /**< Invalid packet identifies. */
-#define INIT_PACKET                     0x01                                                            /**< Packet identifies for initialization packet. */
-#define STOP_INIT_PACKET                0x02                                                            /**< Packet identifies for stop initialization packet. Used when complete init packet has been received so that the init packet can be used for pre validaiton. */
-#define START_PACKET                    0x03                                                            /**< Packet identifies for the Data Start Packet. */
-#define DATA_PACKET                     0x04                                                            /**< Packet identifies for a Data Packet. */
-#define STOP_DATA_PACKET                0x05                                                            /**< Packet identifies for the Data Stop Packet. */
-
-#define DFU_UPDATE_SD                   0x01                                                            /**< Bit field indicating update of SoftDevice is ongoing. */
-#define DFU_UPDATE_BL                   0x02                                                            /**< Bit field indicating update of bootloader is ongoing. */
-#define DFU_UPDATE_APP                  0x04                                                            /**< Bit field indicating update of application is ongoing. */
-
-#define DFU_INIT_RX                     0x00                                                            /**< Op Code identifies for receiving init packet. */
-#define DFU_INIT_COMPLETE               0x01                                                            /**< Op Code identifies for transmission complete of init packet. */
-
-// Safe guard to ensure during compile time that the DFU_APP_DATA_RESERVED is a multiple of page size.
-STATIC_ASSERT((((DFU_APP_DATA_RESERVED) & (CODE_PAGE_SIZE - 1)) == 0x00));
-
-/**@brief Structure holding a start packet containing update mode and image sizes.
- */
-typedef struct
-{
-    uint8_t  dfu_update_mode;                                                                           /**< Packet type, used to identify the content of the received packet referenced by data packet. */
-    uint32_t sd_image_size;                                                                             /**< Size of the SoftDevice image to be transferred. Zero if no SoftDevice image will be transfered. */
-    uint32_t bl_image_size;                                                                             /**< Size of the Bootloader image to be transferred. Zero if no Bootloader image will be transfered. */
-    uint32_t app_image_size;                                                                            /**< Size of the application image to be transmitted. Zero if no Bootloader image will be transfered. */
-} dfu_start_packet_t;
-
-/**@brief Structure holding a bootloader init/data packet received.
- */
-typedef struct
-{
-    uint32_t   packet_length;                                                                           /**< Packet length of the data packet. Each data is word size, meaning length of 4 is 4 words, not bytes. */
-    uint32_t * p_data_packet;                                                                           /**< Data Packet received. Each data is a word size entry. */
-} dfu_data_packet_t;
-
-/**@brief Structure for holding dfu update packet. Packet type indicate the type of packet.
- */
-typedef struct
-{
-    uint32_t   packet_type;                                                                             /**< Packet type, used to identify the content of the received packet referenced by data packet. */
-    union
-    {
-        dfu_data_packet_t    data_packet;                                                               /**< Used when packet type is INIT_PACKET or DATA_PACKET. Packet contains data received for init or data. */
-        dfu_start_packet_t * start_packet;                                                              /**< Used when packet type is START_DATA_PACKET. Will contain information on software to be updtaed, i.e. SoftDevice, Bootloader and/or Application along with image sizes. */
-    } params;
-} dfu_update_packet_t;
-
-/**@brief DFU status error codes.
-*/
-typedef enum
-{
-    DFU_UPDATE_APP_COMPLETE,                                                                            /**< Status update of application complete.*/
-    DFU_UPDATE_SD_COMPLETE,                                                                             /**< Status update of SoftDevice update complete. Note that this solely indicates that a new SoftDevice has been received and stored in bank 0 and 1. */
-    DFU_UPDATE_SD_SWAPPED,                                                                              /**< Status update of SoftDevice update complete. Note that this solely indicates that a new SoftDevice has been received and stored in bank 0 and 1. */
-    DFU_UPDATE_BOOT_COMPLETE,                                                                           /**< Status update complete.*/
-    DFU_BANK_0_ERASED,                                                                                  /**< Status bank 0 erased.*/
-    DFU_TIMEOUT,                                                                                        /**< Status timeout.*/
-    DFU_RESET                                                                                           /**< Status Reset to indicate current update procedure has been aborted and system should reset. */
-} dfu_update_status_code_t;
-
-/**@brief Structure holding DFU complete event.
-*/
-typedef struct
-{
-    dfu_update_status_code_t status_code;                                                               /**< Device Firmware Update status. */
-    uint16_t                 app_crc;                                                                   /**< CRC of the recieved application. */
-    uint32_t                 sd_size;                                                                   /**< Size of the recieved SoftDevice. */
-    uint32_t                 bl_size;                                                                   /**< Size of the recieved BootLoader. */
-    uint32_t                 app_size;                                                                  /**< Size of the recieved Application. */
-    uint32_t                 sd_image_start;                                                            /**< Location in flash where the received SoftDevice image is stored. */
-} dfu_update_status_t;
-
-/**@brief Update complete handler type. */
-typedef void (*dfu_complete_handler_t)(dfu_update_status_t dfu_update_status);
-
-#endif // DFU_TYPES_H__
-
-/**@} */
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/bootloader_dfu/experimental/dfu_app_handler.c	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nordic-sdk/components/libraries/bootloader_dfu/experimental/dfu_app_handler.c	Wed Apr 06 22:39:17 2016 +0100
@@ -30,29 +30,28 @@
  *
  */
 
+#include "dfu_app_handler.h"
 #include <string.h>
-#include "dfu_app_handler.h"
 #include "bootloader_util.h"
 #include "nrf.h"
 #include "nrf_sdm.h"
+#include "ble_gatt.h"
 #include "ble_gatts.h"
 #include "app_error.h"
 #include "dfu_ble_svc.h"
 #include "device_manager.h"
+#include "nrf_delay.h"
 
-#define IRQ_ENABLED            0x01                                            /**< Field identifying if an interrupt is enabled. */
-#define MAX_NUMBER_INTERRUPTS  32                                              /**< Maximum number of interrupts available. */
+#define IRQ_ENABLED            0x01                                     /**< Field that identifies if an interrupt is enabled. */
+#define MAX_NUMBER_INTERRUPTS  32                                       /**< Maximum number of interrupts available. */
 
-static void                    dfu_app_reset_prepare(void);                    /**< Forward declare of default reset handler. */
-static dfu_app_reset_prepare_t m_reset_prepare = dfu_app_reset_prepare;        /**< Callback function to application to prepare for system reset. Allows application to cleanup of service and memory prior to reset. */
-#if NEEDED
-static dfu_ble_peer_data_t     m_peer_data;                                    /**< Peer data to be used for data exchange when reseting into DFU mode. */
-static dm_handle_t             m_dm_handle;                                    /**< Device Manager handle with instance id's of current BLE connection. */
-static bool                    m_dm_handle_valid = false;                      /**< Variable indicating if the Device Manager handle is valid. */
-#endif /* NEEDED */
+static void                    dfu_app_reset_prepare(void);             /**< Forward declaration of default reset handler. */
+static dfu_app_reset_prepare_t m_reset_prepare = dfu_app_reset_prepare; /**< Callback function to application to prepare for system reset. Allows application to clean up service and memory before reset. */
+static dfu_ble_peer_data_t     m_peer_data;                             /**< Peer data to be used for data exchange when resetting into DFU mode. */
+static dm_handle_t             m_dm_handle;                             /**< Device Manager handle with instance IDs of current BLE connection. */
 
 
-/**@brief Default reset prepare handler if application hasn't registered a handler.
+/**@brief Function for reset_prepare handler if the application has not registered a handler.
  */
 static void dfu_app_reset_prepare(void)
 {
@@ -67,52 +66,98 @@
 static void interrupts_disable(void)
 {
     uint32_t interrupt_setting_mask;
-    uint32_t irq = 0; // We start from first interrupt, i.e. interrupt 0.
+    uint32_t irq;
 
     // Fetch the current interrupt settings.
     interrupt_setting_mask = NVIC->ISER[0];
 
-    for (; irq < MAX_NUMBER_INTERRUPTS; irq++)
+    // Loop from interrupt 0 for disabling of all interrupts.
+    for (irq = 0; irq < MAX_NUMBER_INTERRUPTS; irq++)
     {
         if (interrupt_setting_mask & (IRQ_ENABLED << irq))
         {
-            // The interrupt was enabled, and hence disable it.
+            // The interrupt was enabled, hence disable it.
             NVIC_DisableIRQ((IRQn_Type)irq);
         }
     }
 }
 
-#if NEEDED
-/**@brief Function for providing peer information to DFU for re-establishing bonded connection in
+
+/**@brief Function for providing peer information to DFU for re-establishing a bonded connection in
  *        DFU mode.
+ *
+ * @param[in] conn_handle   Connection handle for the connection requesting DFU mode.
  */
-static void dfu_app_set_peer_data(void)
+static void dfu_app_peer_data_set(uint16_t conn_handle)
 {
-    uint32_t        err_code;
-    dm_sec_keyset_t key_set;
+    uint32_t                 err_code;
+    dm_sec_keyset_t          key_set;
+    uint32_t                 app_context_data = 0;
+    dm_application_context_t app_context;
+
 
 /** [DFU bond sharing] */
-    err_code = dm_distributed_keys_get(&m_dm_handle, &key_set);
-    APP_ERROR_CHECK(err_code);
+    err_code = dm_handle_get(conn_handle, &m_dm_handle);
+    if (err_code == NRF_SUCCESS)
+    {
+        err_code = dm_distributed_keys_get(&m_dm_handle, &key_set);
+        if (err_code == NRF_SUCCESS)
+        {
+            APP_ERROR_CHECK(err_code);
+
+            m_peer_data.addr              = key_set.keys_central.p_id_key->id_addr_info;
+            m_peer_data.irk               = key_set.keys_central.p_id_key->id_info;
+            m_peer_data.enc_key.enc_info  = key_set.keys_periph.enc_key.p_enc_key->enc_info;
+            m_peer_data.enc_key.master_id = key_set.keys_periph.enc_key.p_enc_key->master_id;
+
+            err_code = dfu_ble_svc_peer_data_set(&m_peer_data);
+            APP_ERROR_CHECK(err_code);
 
-    m_peer_data.addr    = key_set.keys_central.p_id_key->id_addr_info;
-    m_peer_data.enc_key = *((ble_gap_enc_key_t *)(key_set.keys_central.enc_key.p_enc_key));
-    m_peer_data.irk     = key_set.keys_central.p_id_key->id_info;
+            app_context_data   = (DFU_APP_ATT_TABLE_CHANGED << DFU_APP_ATT_TABLE_POS);
+            app_context.len    = sizeof(app_context_data);
+            app_context.p_data = (uint8_t *)&app_context_data;
+            app_context.flags  = 0;
 
-    err_code = dfu_ble_svc_set_peer_data(&m_peer_data);
-    APP_ERROR_CHECK(err_code);
+            err_code = dm_application_context_set(&m_dm_handle, &app_context);
+            APP_ERROR_CHECK(err_code);
+        }
+        else
+        {
+            // Keys were not available, thus we have a non-encrypted connection.
+            err_code = dm_peer_addr_get(&m_dm_handle, &m_peer_data.addr);
+            APP_ERROR_CHECK(err_code);
+
+            err_code = dfu_ble_svc_peer_data_set(&m_peer_data);
+            APP_ERROR_CHECK(err_code);
+        }
+    }
 /** [DFU bond sharing] */
 }
-#endif /* NEEDED */
 
 
-/**@brief Function for preparing the reset, disabling SoftDevice and jump to the bootloader.
+/**@brief Function for preparing the reset, disabling SoftDevice, and jumping to the bootloader.
+ *
+ * @param[in] conn_handle Connection handle for peer requesting to enter DFU mode.
  */
-void bootloader_start(void)
+static void bootloader_start(uint16_t conn_handle)
 {
+    uint32_t err_code;
+    uint16_t sys_serv_attr_len = sizeof(m_peer_data.sys_serv_attr);
+
+    err_code = sd_ble_gatts_sys_attr_get(conn_handle,
+                                         m_peer_data.sys_serv_attr,
+                                         &sys_serv_attr_len,
+                                         BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS);
+    if (err_code != NRF_SUCCESS)
+    {
+        // Any error at this stage means the system service attributes could not be fetched.
+        // This means the service changed indication cannot be sent in DFU mode, but connection
+        // is still possible to establish.
+    }
+
     m_reset_prepare();
 
-    uint32_t err_code = sd_power_gpregret_set(BOOTLOADER_DFU_START);
+    err_code = sd_power_gpregret_set(BOOTLOADER_DFU_START);
     APP_ERROR_CHECK(err_code);
 
     err_code = sd_softdevice_disable();
@@ -121,12 +166,7 @@
     err_code = sd_softdevice_vector_table_base_set(NRF_UICR->BOOTLOADERADDR);
     APP_ERROR_CHECK(err_code);
 
-    // Commenting out the following block because it brings in unwanted dependencies from bonding.
-    // TODO: discuss this with Nordic.
-    // if (m_dm_handle_valid)
-    // {
-    //     dfu_app_set_peer_data();
-    // }
+    dfu_app_peer_data_set(conn_handle);
 
     NVIC_ClearPendingIRQ(SWI2_IRQn);
     interrupts_disable();
@@ -140,21 +180,12 @@
     {
         case BLE_DFU_START:
             // Starting the bootloader - will cause reset.
-            bootloader_start();
+            bootloader_start(p_dfu->conn_handle);
             break;
 
-        case BLE_DFU_VALIDATE:
-        case BLE_DFU_ACTIVATE_N_RESET:
-        case BLE_DFU_SYS_RESET:
-        case BLE_DFU_RECEIVE_INIT_DATA:
-        case BLE_DFU_RECEIVE_APP_DATA:
-        case BLE_DFU_PACKET_WRITE:
-        case BLE_DFU_PKT_RCPT_NOTIF_ENABLED:
-        case BLE_DFU_PKT_RCPT_NOTIF_DISABLED:
-        case BLE_DFU_BYTES_RECEIVED_SEND:
         default:
             {
-                // Unsupported event received from DFU Service.
+                // Unsupported event received from DFU Service. 
                 // Send back BLE_DFU_RESP_VAL_NOT_SUPPORTED message to peer.
                 uint32_t err_code = ble_dfu_response_send(p_dfu,
                                                           BLE_DFU_START_PROCEDURE,
@@ -171,15 +202,11 @@
     m_reset_prepare = reset_prepare_func;
 }
 
-#if NEEDED
-void dfu_app_set_dm_handle(dm_handle_t const * p_dm_handle)
+
+void dfu_app_dm_appl_instance_set(dm_application_instance_t app_instance)
 {
-    m_dm_handle_valid = false;
-
-    if (p_dm_handle != NULL)
-    {
-        m_dm_handle       = *p_dm_handle;
-        m_dm_handle_valid = true;
-    }
-}
-#endif /* NEEDED */
\ No newline at end of file
+    uint32_t err_code;
+    
+    err_code = dm_application_instance_set(&app_instance, &m_dm_handle);
+    APP_ERROR_CHECK(err_code);
+}
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/bootloader_dfu/experimental/dfu_app_handler.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,98 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-  
-/** @file
- *
- * @defgroup nrf_dfu_app_handler DFU BLE packet handling in Application
- * @{
- *
- * @brief DFU BLE packet handling for application.
- *
- * @details This module implements handling of DFU packets transmitted over BLE for switching from 
- *          application mode to Bootloader running full DFU service.
- *          This module only handles the StartDFU packet allowing for any BLE application to expose
- *          support for the DFU service.
- *          Actual DFU service will execute in dedicated environment after a BLE disconnect and 
- *          reset of the nRF51 chip.
- *          The host must then reconnect and can continue the update procedure with access to full
- *          DFU service.
- *
- * @note The application must propagate dfu events to the DFU App handler module by calling
- *       dfu_app_on_dfu_evt() from the @ref ble_dfu_evt_handler_t callback.
- */
- 
-#ifndef DFU_APP_HANDLER_H__
-#define DFU_APP_HANDLER_H__
-
-#include "ble_dfu.h"
-#include "nrf_svc.h"
-#include "bootloader_types.h"
-#include "device_manager.h"
-
-/**@brief DFU Application reset prepare function. This function is a callback which allows the 
- *        application to prepare for an upcoming application reset. 
- */
-typedef void (*dfu_app_reset_prepare_t)(void);
-
-/**@brief   Function for handling of \ref ble_dfu_evt_t from DFU Service. 
- *
- * @details The application must inject this function into the DFU service or propagate DFU events
- *          to dfu_app_handler module by calling this function in application specific DFU event 
- *          handler.
- * 
- * @param[in] p_dfu              Pointer to the DFU Service structure for which the include event 
- *                               relates.
- * @param[in] p_evt  Pointer to the DFU event.
- */
-void dfu_app_on_dfu_evt(ble_dfu_t * p_dfu, ble_dfu_evt_t * p_evt);
-
-/**@brief Function for registering for reset prepare calls. 
- *
- * @details The function provided will be executed before reseting the system into Bootloader/DFU
- *          mode. By setting this function the caller will be notified prior to the reset and can
- *          thus prepare the application for reset. As example the application can gracefully
- *          disconnect any peers on BLE, turning of LEDS, ensure all pending flash operations
- *          has completed, etc.
- *
- * @param[in] reset_prepare_func  Function to be execute prior to a reset.
- */
-void dfu_app_reset_prepare_set(dfu_app_reset_prepare_t reset_prepare_func);
-
-/**@brief Function for setting Device manager handle for current BLE connection.
- *
- * @param[in] p_dm_handle  Pointer to device manager handle of current connection.
- */
-void dfu_app_set_dm_handle(dm_handle_t const * p_dm_handle);
-
-#endif // DFU_APP_HANDLER_H__
-
-/** @} */
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/bootloader_dfu/hci_transport/hci_mem_pool_internal.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/** @file
- *
- * @defgroup memory_pool_internal Memory Pool Internal
- * @{
- * @ingroup memory_pool
- *
- * @brief Memory pool internal definitions
- */
-
-#ifndef MEM_POOL_INTERNAL_H__
-#define MEM_POOL_INTERNAL_H__
-
-#define TX_BUF_SIZE       4u    /**< TX buffer size in bytes. */
-#define RX_BUF_SIZE       32u   /**< RX buffer size in bytes. */
-
-#define RX_BUF_QUEUE_SIZE 8u     /**< RX buffer element size. */
-
-#endif // MEM_POOL_INTERNAL_H__
-
-/** @} */
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/crc16/crc16.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "crc16.h"
-#include <stdio.h>
-
-uint16_t crc16_compute(const uint8_t * p_data, uint32_t size, const uint16_t * p_crc)
-{
-    uint32_t i;
-    uint16_t crc = (p_crc == NULL) ? 0xffff : *p_crc;
-
-    for (i = 0; i < size; i++)
-    {
-        crc  = (unsigned char)(crc >> 8) | (crc << 8);
-        crc ^= p_data[i];
-        crc ^= (unsigned char)(crc & 0xff) >> 4;
-        crc ^= (crc << 8) << 4;
-        crc ^= ((crc & 0xff) << 4) << 1;
-    }
-
-    return crc;
-}
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/hci/hci_mem_pool.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,255 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
- 
-#include "hci_mem_pool.h"
-#include "hci_mem_pool_internal.h"
-#include <stdbool.h>
-#include <stdio.h>
-
-/**@brief RX buffer element instance structure. 
- */
-typedef struct 
-{
-    uint8_t  rx_buffer[RX_BUF_SIZE];                                /**< RX buffer memory array. */  
-    uint32_t length;                                                /**< Length of the RX buffer memory array. */
-} rx_buffer_elem_t;
-
-/**@brief RX buffer queue element instance structure. 
- */
-typedef struct 
-{
-    rx_buffer_elem_t * p_buffer;                                    /**< Pointer to RX buffer element. */
-    uint32_t           free_window_count;                           /**< Free space element count. */
-    uint32_t           free_available_count;                        /**< Free area element count. */
-    uint32_t           read_available_count;                        /**< Read area element count. */
-    uint32_t           write_index;                                 /**< Write position index. */                                      
-    uint32_t           read_index;                                  /**< Read position index. */                                                                            
-    uint32_t           free_index;                                  /**< Free position index. */                                                                                                                  
-} rx_buffer_queue_t;
-
-static bool              m_is_tx_allocated;                         /**< Boolean value to determine if the TX buffer is allocated. */
-static rx_buffer_elem_t  m_rx_buffer_elem_queue[RX_BUF_QUEUE_SIZE]; /**< RX buffer element instances. */
-static rx_buffer_queue_t m_rx_buffer_queue;                         /**< RX buffer queue element instance. */
-
-
-uint32_t hci_mem_pool_open(void)
-{
-    m_is_tx_allocated                      = false;    
-    m_rx_buffer_queue.p_buffer             = m_rx_buffer_elem_queue;
-    m_rx_buffer_queue.free_window_count    = RX_BUF_QUEUE_SIZE;
-    m_rx_buffer_queue.free_available_count = 0;
-    m_rx_buffer_queue.read_available_count = 0;
-    m_rx_buffer_queue.write_index          = 0;    
-    m_rx_buffer_queue.read_index           = 0;        
-    m_rx_buffer_queue.free_index           = 0;            
-    
-    return NRF_SUCCESS;
-}
-
-
-uint32_t hci_mem_pool_close(void)
-{    
-    return NRF_SUCCESS;
-}
-
-
-uint32_t hci_mem_pool_tx_alloc(void ** pp_buffer)
-{
-    static uint8_t tx_buffer[TX_BUF_SIZE];  
-
-    uint32_t err_code;
-    
-    if (pp_buffer == NULL)
-    {
-        return NRF_ERROR_NULL;
-    }
-    
-    if (!m_is_tx_allocated)
-    {        
-            m_is_tx_allocated = true;
-            *pp_buffer        = tx_buffer;
-            err_code          = NRF_SUCCESS;
-    }
-    else
-    {
-        err_code              = NRF_ERROR_NO_MEM;
-    }
-    
-    return err_code;
-}
-
-
-uint32_t hci_mem_pool_tx_free(void)
-{
-    m_is_tx_allocated = false;
-    
-    return NRF_SUCCESS;
-}
-
-
-uint32_t hci_mem_pool_rx_produce(uint32_t length, void ** pp_buffer)
-{
-    uint32_t err_code; 
-
-    if (pp_buffer == NULL)
-    {
-        return NRF_ERROR_NULL;
-    }    
-    *pp_buffer = NULL;
-    
-    if (m_rx_buffer_queue.free_window_count != 0)
-    {    
-        if (length <= RX_BUF_SIZE)
-        {    
-            --(m_rx_buffer_queue.free_window_count);            
-            ++(m_rx_buffer_queue.read_available_count);            
-
-            *pp_buffer                    = 
-                    m_rx_buffer_queue.p_buffer[m_rx_buffer_queue.write_index].rx_buffer;
-
-            m_rx_buffer_queue.free_index |= (1u << m_rx_buffer_queue.write_index);
-
-            // @note: Adjust the write_index making use of the fact that the buffer size is of 
-            // power of two and two's complement arithmetic. For details refer example to book 
-            // "Making embedded systems: Elicia White".
-            m_rx_buffer_queue.write_index = 
-                    (m_rx_buffer_queue.write_index + 1u) & (RX_BUF_QUEUE_SIZE - 1u);
-            
-            err_code                      = NRF_SUCCESS;
-        }
-        else
-        {
-            err_code = NRF_ERROR_DATA_SIZE;    
-        }        
-    }
-    else
-    {
-        err_code = NRF_ERROR_NO_MEM;    
-    }
-    
-    return err_code;
-}
-
-
-uint32_t hci_mem_pool_rx_consume(uint8_t * p_buffer)
-{
-    uint32_t err_code;
-    uint32_t consume_index;
-    uint32_t start_index;
-    
-    if (m_rx_buffer_queue.free_available_count != 0)
-    {
-        // Find the buffer that has been freed -
-        // Start at read_index minus free_available_count and then increment until read index.
-        err_code      = NRF_ERROR_INVALID_ADDR;
-        consume_index = (m_rx_buffer_queue.read_index - m_rx_buffer_queue.free_available_count) & 
-                        (RX_BUF_QUEUE_SIZE - 1u);
-        start_index   = consume_index;
-        
-        do
-        {
-            if (m_rx_buffer_queue.p_buffer[consume_index].rx_buffer == p_buffer)
-            {
-                m_rx_buffer_queue.free_index ^= (1u << consume_index);
-                err_code = NRF_SUCCESS;
-                break;
-            }
-            else
-            {
-                consume_index = (consume_index + 1u) & (RX_BUF_QUEUE_SIZE - 1u);
-            }
-        }
-        while (consume_index != m_rx_buffer_queue.read_index);
-
-        while (!(m_rx_buffer_queue.free_index & (1 << start_index)) && 
-                (m_rx_buffer_queue.free_available_count != 0))
-        {
-            --(m_rx_buffer_queue.free_available_count);
-            ++(m_rx_buffer_queue.free_window_count);            
-            start_index = (consume_index + 1u) & (RX_BUF_QUEUE_SIZE - 1u);
-        }
-    }
-    else
-    {
-        err_code = NRF_ERROR_NO_MEM;
-    }
-        
-    return err_code;    
-}
-
-
-uint32_t hci_mem_pool_rx_data_size_set(uint32_t length)
-{
-    // @note: Adjust the write_index making use of the fact that the buffer size is of power
-    // of two and two's complement arithmetic. For details refer example to book 
-    // "Making embedded systems: Elicia White".
-    const uint32_t index = (m_rx_buffer_queue.write_index - 1u) & (RX_BUF_QUEUE_SIZE - 1u);
-    m_rx_buffer_queue.p_buffer[index].length = length;    
-    
-    return NRF_SUCCESS;
-}
-
-
-uint32_t hci_mem_pool_rx_extract(uint8_t ** pp_buffer, uint32_t * p_length)
-{
-    uint32_t err_code;
-    
-    if ((pp_buffer == NULL) || (p_length == NULL))
-    {
-        return NRF_ERROR_NULL;
-    }
-    
-    if (m_rx_buffer_queue.read_available_count != 0)
-    {
-        --(m_rx_buffer_queue.read_available_count);
-        ++(m_rx_buffer_queue.free_available_count);        
-        
-        *pp_buffer                   = 
-            m_rx_buffer_queue.p_buffer[m_rx_buffer_queue.read_index].rx_buffer;
-        *p_length                    = 
-            m_rx_buffer_queue.p_buffer[m_rx_buffer_queue.read_index].length;
-        
-        // @note: Adjust the write_index making use of the fact that the buffer size is of power
-        // of two and two's complement arithmetic. For details refer example to book 
-        // "Making embedded systems: Elicia White".            
-        m_rx_buffer_queue.read_index = 
-            (m_rx_buffer_queue.read_index + 1u) & (RX_BUF_QUEUE_SIZE - 1u); 
-        
-        err_code                     = NRF_SUCCESS;
-    }
-    else
-    {
-        err_code                     = NRF_ERROR_NO_MEM;        
-    }
-    
-    return err_code;
-}
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/hci/hci_mem_pool.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,152 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
- 
-/** @file
- *
- * @defgroup memory_pool Memory pool
- * @{
- * @ingroup app_common
- *
- * @brief Memory pool implementation
- *
- * Memory pool implementation, based on circular buffer data structure, which supports asynchronous 
- * processing of RX data. The current default implementation supports 1 TX buffer and 4 RX buffers.
- * The memory managed by the pool is allocated from static storage instead of heap. The internal 
- * design of the circular buffer implementing the RX memory layout is illustrated in the picture 
- * below. 
- *
- * @image html memory_pool.png "Circular buffer design"
- *
- * The expected call order for the RX APIs is as follows:
- * - hci_mem_pool_rx_produce
- * - hci_mem_pool_rx_data_size_set
- * - hci_mem_pool_rx_extract
- * - hci_mem_pool_rx_consume
- *
- * @warning If the above mentioned expected call order is violated the end result can be undefined.
- *
- * \par Component specific configuration options
- *
- * The following compile time configuration options are available to suit various implementations:
- * - TX_BUF_SIZE TX buffer size in bytes. 
- * - RX_BUF_SIZE RX buffer size in bytes. 
- * - RX_BUF_QUEUE_SIZE RX buffer element size.
- */
- 
-#ifndef HCI_MEM_POOL_H__
-#define HCI_MEM_POOL_H__
-
-#include <stdint.h>
-#include "nrf_error.h"
-
-/**@brief Function for opening the module.
- *
- * @retval NRF_SUCCESS          Operation success. 
- */
-uint32_t hci_mem_pool_open(void);
-
-/**@brief Function for closing the module.
- *
- * @retval NRF_SUCCESS          Operation success. 
- */
-uint32_t hci_mem_pool_close(void);
-
-/**@brief Function for allocating requested amount of TX memory.
- *
- * @param[out] pp_buffer        Pointer to the allocated memory.
- *
- * @retval NRF_SUCCESS          Operation success. Memory was allocated.
- * @retval NRF_ERROR_NO_MEM     Operation failure. No memory available for allocation.
- * @retval NRF_ERROR_NULL       Operation failure. NULL pointer supplied.  
- */
-uint32_t hci_mem_pool_tx_alloc(void ** pp_buffer);
- 
-/**@brief Function for freeing previously allocated TX memory.
- *
- * @note Memory management follows the FIFO principle meaning that free() order must match the 
- *       alloc(...) order, which is the reason for omitting exact memory block identifier as an 
- *       input parameter.
- *
- * @retval NRF_SUCCESS          Operation success. Memory was freed.
- */
-uint32_t hci_mem_pool_tx_free(void);
- 
-/**@brief Function for producing a free RX memory block for usage.
- *
- * @note Upon produce request amount being 0, NRF_SUCCESS is returned.   
- *
- * @param[in]  length           Amount, in bytes, of free memory to be produced.
- * @param[out] pp_buffer        Pointer to the allocated memory.
- *
- * @retval NRF_SUCCESS          Operation success. Free RX memory block produced.
- * @retval NRF_ERROR_NO_MEM     Operation failure. No suitable memory available for allocation.
- * @retval NRF_ERROR_DATA_SIZE  Operation failure. Request size exceeds limit.  
- * @retval NRF_ERROR_NULL       Operation failure. NULL pointer supplied.   
- */
-uint32_t hci_mem_pool_rx_produce(uint32_t length, void ** pp_buffer);
-
-/**@brief Function for setting the length of the last produced RX memory block.
- *
- * @warning If call to this API is omitted the end result is that the following call to 
- *          mem_pool_rx_extract will return incorrect data in the p_length output parameter.
- *
- * @param[in]  length           Amount, in bytes, of actual memory used.
- *
- * @retval NRF_SUCCESS          Operation success. Length was set.
- */
-uint32_t hci_mem_pool_rx_data_size_set(uint32_t length);
- 
-/**@brief Function for extracting a packet, which has been filled with read data, for further 
- * processing.
- *
- * @param[out] pp_buffer        Pointer to the packet data.
- * @param[out] p_length         Length of packet data in bytes.  
- *
- * @retval NRF_SUCCESS          Operation success. 
- * @retval NRF_ERROR_NO_MEM     Operation failure. No packet available to extract.
- * @retval NRF_ERROR_NULL       Operation failure. NULL pointer supplied.    
- */
-uint32_t hci_mem_pool_rx_extract(uint8_t ** pp_buffer, uint32_t * p_length);
- 
-/**@brief Function for freeing previously extracted packet, which has been filled with read data.
- *
- * @param[in] p_buffer             Pointer to consumed buffer.
- *
- * @retval NRF_SUCCESS             Operation success. 
- * @retval NRF_ERROR_NO_MEM        Operation failure. No packet available to free. 
- * @retval NRF_ERROR_INVALID_ADDR  Operation failure. Not a valid pointer. 
- */
-uint32_t hci_mem_pool_rx_consume(uint8_t * p_buffer);
- 
-#endif // HCI_MEM_POOL_H__
- 
-/** @} */
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/scheduler/app_scheduler.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,212 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "app_scheduler.h"
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include "nrf_soc.h"
-#include "nrf_assert.h"
-#include "app_util.h"
-#include "app_util_platform.h"
-
-/**@brief Structure for holding a scheduled event header. */
-typedef struct
-{
-    app_sched_event_handler_t handler;          /**< Pointer to event handler to receive the event. */
-    uint16_t                  event_data_size;  /**< Size of event data. */
-} event_header_t;
-
-STATIC_ASSERT(sizeof(event_header_t) <= APP_SCHED_EVENT_HEADER_SIZE);
-
-static event_header_t * m_queue_event_headers;  /**< Array for holding the queue event headers. */
-static uint8_t        * m_queue_event_data;     /**< Array for holding the queue event data. */
-static volatile uint8_t m_queue_start_index;    /**< Index of queue entry at the start of the queue. */
-static volatile uint8_t m_queue_end_index;      /**< Index of queue entry at the end of the queue. */
-static uint16_t         m_queue_event_size;     /**< Maximum event size in queue. */
-static uint16_t         m_queue_size;           /**< Number of queue entries. */
-
-/**@brief Function for incrementing a queue index, and handle wrap-around.
- *
- * @param[in]   index   Old index.
- *
- * @return      New (incremented) index.
- */
-static __INLINE uint8_t next_index(uint8_t index)
-{
-    return (index < m_queue_size) ? (index + 1) : 0;
-}
-
-
-static __INLINE uint8_t app_sched_queue_full()
-{
-  uint8_t tmp = m_queue_start_index;
-  return next_index(m_queue_end_index) == tmp;
-}
-
-/**@brief Macro for checking if a queue is full. */
-#define APP_SCHED_QUEUE_FULL() app_sched_queue_full()
-
-
-static __INLINE uint8_t app_sched_queue_empty()
-{
-  uint8_t tmp = m_queue_start_index;
-  return m_queue_end_index == tmp;
-}
-
-/**@brief Macro for checking if a queue is empty. */
-#define APP_SCHED_QUEUE_EMPTY() app_sched_queue_empty()
-
-
-uint32_t app_sched_init(uint16_t event_size, uint16_t queue_size, void * p_event_buffer)
-{
-    uint16_t data_start_index = (queue_size + 1) * sizeof(event_header_t);
-
-    // Check that buffer is correctly aligned
-    if (!is_word_aligned(p_event_buffer))
-    {
-        return NRF_ERROR_INVALID_PARAM;
-    }
-
-    // Initialize event scheduler
-    m_queue_event_headers = p_event_buffer;
-    m_queue_event_data    = &((uint8_t *)p_event_buffer)[data_start_index];
-    m_queue_end_index     = 0;
-    m_queue_start_index   = 0;
-    m_queue_event_size    = event_size;
-    m_queue_size          = queue_size;
-
-    return NRF_SUCCESS;
-}
-
-
-uint32_t app_sched_event_put(void                    * p_event_data,
-                             uint16_t                  event_data_size,
-                             app_sched_event_handler_t handler)
-{
-    uint32_t err_code;
-
-    if (event_data_size <= m_queue_event_size)
-    {
-        uint16_t event_index = 0xFFFF;
-
-        CRITICAL_REGION_ENTER();
-
-        if (!APP_SCHED_QUEUE_FULL())
-        {
-            event_index       = m_queue_end_index;
-            m_queue_end_index = next_index(m_queue_end_index);
-        }
-
-        CRITICAL_REGION_EXIT();
-
-        if (event_index != 0xFFFF)
-        {
-            // NOTE: This can be done outside the critical region since the event consumer will
-            //       always be called from the main loop, and will thus never interrupt this code.
-            m_queue_event_headers[event_index].handler = handler;
-            if ((p_event_data != NULL) && (event_data_size > 0))
-            {
-                memcpy(&m_queue_event_data[event_index * m_queue_event_size],
-                       p_event_data,
-                       event_data_size);
-                m_queue_event_headers[event_index].event_data_size = event_data_size;
-            }
-            else
-            {
-                m_queue_event_headers[event_index].event_data_size = 0;
-            }
-
-            err_code = NRF_SUCCESS;
-        }
-        else
-        {
-            err_code = NRF_ERROR_NO_MEM;
-        }
-    }
-    else
-    {
-        err_code = NRF_ERROR_INVALID_LENGTH;
-    }
-
-    return err_code;
-}
-
-
-/**@brief Function for reading the next event from specified event queue.
- *
- * @param[out]  pp_event_data       Pointer to pointer to event data.
- * @param[out]  p_event_data_size   Pointer to size of event data.
- * @param[out]  p_event_handler     Pointer to event handler function pointer.
- *
- * @return      NRF_SUCCESS if new event, NRF_ERROR_NOT_FOUND if event queue is empty.
- */
-static uint32_t app_sched_event_get(void                     ** pp_event_data,
-                                    uint16_t *                  p_event_data_size,
-                                    app_sched_event_handler_t * p_event_handler)
-{
-    uint32_t err_code = NRF_ERROR_NOT_FOUND;
-
-    if (!APP_SCHED_QUEUE_EMPTY())
-    {
-        uint16_t event_index;
-
-        // NOTE: There is no need for a critical region here, as this function will only be called
-        //       from app_sched_execute() from inside the main loop, so it will never interrupt
-        //       app_sched_event_put(). Also, updating of (i.e. writing to) the start index will be
-        //       an atomic operation.
-        event_index         = m_queue_start_index;
-        m_queue_start_index = next_index(m_queue_start_index);
-
-        *pp_event_data     = &m_queue_event_data[event_index * m_queue_event_size];
-        *p_event_data_size = m_queue_event_headers[event_index].event_data_size;
-        *p_event_handler   = m_queue_event_headers[event_index].handler;
-
-        err_code = NRF_SUCCESS;
-    }
-
-    return err_code;
-}
-
-
-void app_sched_execute(void)
-{
-    void                    * p_event_data;
-    uint16_t                  event_data_size;
-    app_sched_event_handler_t event_handler;
-
-    // Get next event (if any), and execute handler
-    while ((app_sched_event_get(&p_event_data, &event_data_size, &event_handler) == NRF_SUCCESS))
-    {
-        event_handler(p_event_data, event_data_size);
-    }
-}
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/util/app_error.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,100 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/** @file
- *
- * @defgroup app_error Common application error handler
- * @{
- * @ingroup app_common
- *
- * @brief Common application error handler.
- */
-
-#include "nrf.h"
-#include "app_error.h"
-#include "compiler_abstraction.h"
-#include "nordic_common.h"
-#ifdef DEBUG
-
-/* global error variables - in order to prevent removal by optimizers */
-uint32_t m_error_code;
-uint32_t m_line_num;
-const uint8_t * m_p_file_name;
-#endif
-
-/**@brief Function for error handling, which is called when an error has occurred.
- *
- * @warning This handler is an example only and does not fit a final product. You need to analyze
- *          how your product is supposed to react in case of error.
- *
- * @param[in] error_code  Error code supplied to the handler.
- * @param[in] line_num    Line number where the handler is called.
- * @param[in] p_file_name Pointer to the file name.
- *
- * Function is implemented as weak so that it can be overwritten by custom application error handler
- * when needed.
- */
-
-/*lint -save -e14 */
-__WEAK void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name)
-{
-    // On assert, the system can only recover with a reset.
-#ifndef DEBUG
-    NVIC_SystemReset();
-#else
-    
-#ifdef BSP_DEFINES_ONLY 
-    LEDS_ON(LEDS_MASK);
-#else
-    UNUSED_VARIABLE(bsp_indication_set(BSP_INDICATE_FATAL_ERROR));
-    // This call can be used for debug purposes during application development.
-    // @note CAUTION: Activating this code will write the stack to flash on an error.
-    //                This function should NOT be used in a final product.
-    //                It is intended STRICTLY for development/debugging purposes.
-    //                The flash write will happen EVEN if the radio is active, thus interrupting
-    //                any communication.
-    //                Use with care. Uncomment the line below to use.
-    //ble_debug_assert_handler(error_code, line_num, p_file_name);
-#endif // BSP_DEFINES_ONLY
-
-    m_error_code = error_code;
-    m_line_num = line_num;
-    m_p_file_name = p_file_name;
-
-    UNUSED_VARIABLE(m_error_code);
-    UNUSED_VARIABLE(m_line_num);
-    UNUSED_VARIABLE(m_p_file_name);
-    __disable_irq();
-    while(1) ;
-#endif // DEBUG
-}
-/*lint -restore */
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/util/app_util_platform.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "app_util_platform.h"
-
-static uint32_t m_in_critical_region = 0;
-
-void critical_region_enter(void)
-{
-    __disable_irq();    
-    m_in_critical_region++;    
-}
-
-void critical_region_exit(void)
-{
-    m_in_critical_region--;    
-    if (m_in_critical_region == 0)
-    {
-        __enable_irq();
-    }
-}
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/util/app_util_platform.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,149 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/**@file
- *
- * @defgroup app_util_platform Utility Functions and Definitions (Platform)
- * @{
- * @ingroup app_common
- *
- * @brief Various types and definitions available to all applications when using SoftDevice.
- */
-
-#ifndef APP_UTIL_PLATFORM_H__
-#define APP_UTIL_PLATFORM_H__
-
-#include <stdint.h>
-#include "compiler_abstraction.h"
-#include "nrf51.h"
-#ifdef SOFTDEVICE_PRESENT
-#include "nrf_soc.h"
-#include "app_error.h"
-#endif
-/**@brief The interrupt priorities available to the application while the SoftDevice is active. */
-typedef enum
-{
-#ifndef SOFTDEVICE_PRESENT
-    APP_IRQ_PRIORITY_HIGHEST = 0,
-#endif
-    APP_IRQ_PRIORITY_HIGH    = 1,
-#ifndef SOFTDEVICE_PRESENT
-    APP_IRQ_PRIORITY_MID     = 2,
-#endif
-    APP_IRQ_PRIORITY_LOW     = 3
-} app_irq_priority_t;
-
-#define NRF_APP_PRIORITY_THREAD    4                    /**< "Interrupt level" when running in Thread Mode. */
-
-/**@cond NO_DOXYGEN */
-#define EXTERNAL_INT_VECTOR_OFFSET 16
-/**@endcond */
-
-#define PACKED(TYPE) __packed TYPE
-
-void critical_region_enter (void);
-void critical_region_exit (void);
-
-/**@brief Macro for entering a critical region.
- *
- * @note Due to implementation details, there must exist one and only one call to
- *       CRITICAL_REGION_EXIT() for each call to CRITICAL_REGION_ENTER(), and they must be located
- *       in the same scope.
- */
-#ifdef SOFTDEVICE_PRESENT
-#define CRITICAL_REGION_ENTER()                                                             \
-    {                                                                                       \
-        uint8_t IS_NESTED_CRITICAL_REGION = 0;                                              \
-        uint32_t CURRENT_INT_PRI = current_int_priority_get();                              \
-        if (CURRENT_INT_PRI != APP_IRQ_PRIORITY_HIGH)                                       \
-        {                                                                                   \
-            uint32_t ERR_CODE = sd_nvic_critical_region_enter(&IS_NESTED_CRITICAL_REGION);  \
-            if (ERR_CODE == NRF_ERROR_SOFTDEVICE_NOT_ENABLED)                               \
-            {                                                                               \
-                __disable_irq();                                                            \
-            }                                                                               \
-            else                                                                            \
-            {                                                                               \
-                APP_ERROR_CHECK(ERR_CODE);                                                  \
-            }                                                                               \
-        }        
-#else
-#define CRITICAL_REGION_ENTER() critical_region_enter()
-#endif
-
-/**@brief Macro for leaving a critical region.
- *
- * @note Due to implementation details, there must exist one and only one call to
- *       CRITICAL_REGION_EXIT() for each call to CRITICAL_REGION_ENTER(), and they must be located
- *       in the same scope.
- */
-#ifdef SOFTDEVICE_PRESENT
-#define CRITICAL_REGION_EXIT()                                                              \
-        if (CURRENT_INT_PRI != APP_IRQ_PRIORITY_HIGH)                                       \
-        {                                                                                   \
-            uint32_t ERR_CODE;                                                              \
-            __enable_irq();                                                                 \
-            ERR_CODE = sd_nvic_critical_region_exit(IS_NESTED_CRITICAL_REGION);             \
-            if (ERR_CODE != NRF_ERROR_SOFTDEVICE_NOT_ENABLED)                               \
-            {                                                                               \
-                APP_ERROR_CHECK(ERR_CODE);                                                  \
-            }                                                                               \
-        }                                                                                   \
-    }
-#else
-#define CRITICAL_REGION_EXIT() critical_region_exit()
-#endif 
-       
-/**@brief Function for finding the current interrupt level.
- *
- * @return   Current interrupt level.
- * @retval   APP_IRQ_PRIORITY_HIGH    We are running in Application High interrupt level.
- * @retval   APP_IRQ_PRIORITY_LOW     We are running in Application Low interrupt level.
- * @retval   APP_IRQ_PRIORITY_THREAD  We are running in Thread Mode.
- */
-static __INLINE uint8_t current_int_priority_get(void)
-{
-    uint32_t isr_vector_num = (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk);
-    if (isr_vector_num > 0)
-    {
-        int32_t irq_type = ((int32_t)isr_vector_num - EXTERNAL_INT_VECTOR_OFFSET);
-        return (NVIC_GetPriority((IRQn_Type)irq_type) & 0xFF);
-    }
-    else
-    {
-        return NRF_APP_PRIORITY_THREAD;
-    }
-}
-
-#endif // APP_UTIL_PLATFORM_H__
-
-/** @} */
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/util/common.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#ifndef COMMON_H
-#define COMMON_H
-
-/*lint ++flb "Enter library region" */
-
-#include <stdbool.h>
-#include <stdint.h>
-
-/* @file
-* @brief Common header file for generic macros and definitions
- *
- */
-
-/*
- * GPIO glue macros, this can be used to define a pin number in source/header file and use that macro for pin
- * configuration using this expansion.
- * example:
- * #define RESET_PIN    8
- * NRF_GPIO->PINCNF(RESET_PIN) = XXX  ;  // Expanded NRF_GPIO->PIN_CNF[8] = XXX
- */
-#define PINX_GLUE(x, y, z)       x##y##_##z            /*!< first level glue for pin macros */
-#define PINCNF(p)                PINX_GLUE(PIN,p,CNF)  /*!< gpio configure pin number 'p' */
-#define PINOUT(p)                PINX_GLUE(PIN,p,OUT)  /*!< gpio out pin number 'p' */
-
-/*lint --flb "Leave library region" */
-#endif
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/util/nordic_common.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,93 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/** @file
- * @brief Common defines and macros for firmware developed by Nordic Semiconductor.
- */
-
-#ifndef NORDIC_COMMON_H__
-#define NORDIC_COMMON_H__
-
-/** Swaps the upper byte with the lower byte in a 16 bit variable */
-//lint -emacro((572),SWAP) // Suppress warning 572 "Excessive shift value"
-#define SWAP(x) ((((x)&0xFF)<<8)|(((x)>>8)&0xFF))
-
-/** The upper 8 bits of a 16 bit value */
-//lint -emacro(572,MSB) // Suppress warning 572 "Excessive shift value"
-#define MSB(a) (((a) & 0xFF00) >> 8)
-/** The lower 8 bits (of a 16 bit value) */
-#define LSB(a) ((a) & 0xFF)
-
-/** Leaves the minimum of the two arguments */
-/*lint -emacro(506, MIN) */ /* Suppress "Constant value Boolean */ 
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-/** Leaves the maximum of the two arguments */
-/*lint -emacro(506, MAX) */ /* Suppress "Constant value Boolean */ 
-#define MAX(a, b) ((a) < (b) ? (b) : (a))
-
-#define BIT_0 0x01 /**< The value of bit 0 */
-#define BIT_1 0x02 /**< The value of bit 1 */
-#define BIT_2 0x04 /**< The value of bit 2 */
-#define BIT_3 0x08 /**< The value of bit 3 */
-#define BIT_4 0x10 /**< The value of bit 4 */
-#define BIT_5 0x20 /**< The value of bit 5 */
-#define BIT_6 0x40 /**< The value of bit 6 */
-#define BIT_7 0x80 /**< The value of bit 7 */
-#define BIT_8 0x0100 /**< The value of bit 8 */
-#define BIT_9 0x0200 /**< The value of bit 9 */
-#define BIT_10 0x0400 /**< The value of bit 10 */
-#define BIT_11 0x0800 /**< The value of bit 11 */
-#define BIT_12 0x1000 /**< The value of bit 12 */
-#define BIT_13 0x2000 /**< The value of bit 13 */
-#define BIT_14 0x4000 /**< The value of bit 14 */
-#define BIT_15 0x8000 /**< The value of bit 15 */
-#define BIT_16 0x00010000 /**< The value of bit 16 */
-#define BIT_17 0x00020000 /**< The value of bit 17 */
-#define BIT_18 0x00040000 /**< The value of bit 18 */
-#define BIT_19 0x00080000 /**< The value of bit 19 */
-#define BIT_20 0x00100000 /**< The value of bit 20 */
-#define BIT_21 0x00200000 /**< The value of bit 21 */
-#define BIT_22 0x00400000 /**< The value of bit 22 */
-#define BIT_23 0x00800000 /**< The value of bit 23 */
-#define BIT_24 0x01000000 /**< The value of bit 24 */
-#define BIT_25 0x02000000 /**< The value of bit 25 */
-#define BIT_26 0x04000000 /**< The value of bit 26 */
-#define BIT_27 0x08000000 /**< The value of bit 27 */
-#define BIT_28 0x10000000 /**< The value of bit 28 */
-#define BIT_29 0x20000000 /**< The value of bit 29 */
-#define BIT_30 0x40000000 /**< The value of bit 30 */
-#define BIT_31 0x80000000 /**< The value of bit 31 */
-
-#define UNUSED_VARIABLE(X)  ((void)(X))
-#define UNUSED_PARAMETER(X) UNUSED_VARIABLE(X)
-
-#endif // NORDIC_COMMON_H__
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/util/nrf_assert.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-#include "nrf_assert.h"
-
-#if defined(DEBUG_NRF)
-void assert_nrf_callback(uint16_t line_num, const uint8_t * file_name)
-{
-    (void) file_name; /* Unused parameter */
-    (void) line_num;  /* Unused parameter */
- 
-    while (1) ;
-}
-#endif /* DEBUG_NRF */
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/util/nrf_assert.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/** @file
- * @brief Utilities for verifying program logic
- */
-
-#ifndef NRF_ASSERT_H_
-#define NRF_ASSERT_H_
-
-#include <stdint.h>
-#include "compiler_abstraction.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if defined(DEBUG_NRF) || defined(DEBUG_NRF_USER)
-
-/** @brief Function for handling assertions.
- *
- *
- * @note
- * This function is called when an assertion has triggered.
- *
- *
- * @post
- * All hardware is put into an idle non-emitting state (in particular the radio is highly
- * important to switch off since the radio might be in a state that makes it send
- * packets continiously while a typical final infinit ASSERT loop is executing).
- *
- *
- * @param line_num The line number where the assertion is called
- * @param file_name Pointer to the file name
- */
-void assert_nrf_callback(uint16_t line_num, const uint8_t *file_name);
-
-/*lint -emacro(506, ASSERT) */ /* Suppress "Constant value Boolean */ 
-/*lint -emacro(774, ASSERT) */ /* Suppress "Boolean within 'if' always evaluates to True" */ \
-
-/** @brief Function for checking intended for production code.
- *
- * Check passes if "expr" evaluates to true. */
-#define ASSERT(expr) \
-if (expr)                                                                     \
-{                                                                             \
-}                                                                             \
-else                                                                          \
-{                                                                             \
-  assert_nrf_callback((uint16_t)__LINE__, (uint8_t *)__FILE__);               \
-}
-#else
-#define ASSERT(expr) //!< Assert empty when disabled
-__WEAK void assert_nrf_callback(uint16_t line_num, const uint8_t *file_name);
-#endif /* defined(DEBUG_NRF) || defined(DEBUG_NRF_USER) */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* NRF_ASSERT_H_ */
\ No newline at end of file
--- a/source/nordic-sdk/components/libraries/util/sdk_common.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/** @cond */
-/**@file
- *
- * @ingroup experimental_api
- * @defgroup sdk_common SDK Common Header
- * @breif All common headers needed for SDK examples will be included here so that application
- *       developer does not have to include headers on him/herself.
- * @{
- */
-
-#ifndef SDK_COMMON_H__
-#define SDK_COMMON_H__
-
-#include <stdint.h>
-#include <stdbool.h>
-#include <string.h>
-#include "nordic_common.h"
-#include "compiler_abstraction.h"
-#include "sdk_os.h"
-#include "sdk_errors.h"
-#include "app_util.h"
-
-/** @} */
-/** @endcond */
-#endif // SDK_COMMON_H__
--- a/source/nordic-sdk/components/libraries/util/sdk_errors.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,121 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/**@file
- *
- * @defgroup sdk_error SDK Error codes
- * @{
- * @ingroup app_common
- * @{
- * @details Error codes are 32-bit unsigned integers with the most significant 16-bit reserved for
- *          identifying the module where the error occurred while the least least significant LSB
- *          are used to provide the cause or nature of error. Each module is assigned a 16-bit
- *          unsigned integer. Which it will use to identify all errors that occurred in it. 16-bit
- *          LSB range is with module id as the MSB in the 32-bit error code is reserved for the
- *          module. As an example, if 0x8800 identifies a certain SDK module, all values from 
- *          0x88000000 - 0x8800FFFF are reserved for this module.
- *          It should be noted that common error reasons have been assigned values to make it 
- *          possible to decode error reason easily. As an example, lets module uninitialized has
- *          been assigned an error code 0x000A0. Then, if application encounters an error code
- *          0xZZZZ00A0, it knows that it accessing a certain module without initializing it.
- *          Apart from this, each module is allowed to define error codes that are not covered by
- *          the common ones, however, these values are defined in a range that does not conflict
- *          with common error values. For module, specific error however, it is possible that the
- *          same error value is used by two different modules to indicated errors of very different
- *          nature. If error is already defined by the NRF common error codes, these are reused.
- *          A range is reserved for application as well, it can use this range for defining
- *          application specific errors.
- *
- * @note Success code, NRF_SUCCESS, does not include any module identifier.          
-
- */
-
-#ifndef SDK_ERRORS_H__
-#define SDK_ERRORS_H__
-
-#include "nrf_error.h"
-
-/**
- * @defgroup sdk_err_base Base defined for SDK Modules
- * @{
- */
-#define SDK_ERROR_BASE         (NRF_ERROR_BASE_NUM + 0x8000)   /**< Base value defined for SDK module identifiers. */
-#define SDK_COMMON_ERROR_BASE  (NRF_ERROR_BASE_NUM + 0x0080)   /**< Base error value to be used for SDK error values. */
-/* @} */
-
-/**
- * @defgroup sdk_module_codes Codes reserved as identification for module where the error occurred.
- * @{
- */
-#define DEVICE_MANAGER_ERR_BASE   (0x8000)
-/* @} */
-
-/**
- * @defgroup sdk_common_errors Codes reserved as identification for common errors.
- * @{
- */
-#define MODULE_NOT_INITIALZED      (SDK_COMMON_ERROR_BASE+0x0000)
-#define MUTEX_INIT_FAILED          (SDK_COMMON_ERROR_BASE+0x0001)
-#define MUTEX_LOCK_FAILED          (SDK_COMMON_ERROR_BASE+0x0002)
-#define MUTEX_UNLOCK_FAILED        (SDK_COMMON_ERROR_BASE+0x0003)
-#define MUTEX_COND_INIT_FAILED     (SDK_COMMON_ERROR_BASE+0x0004)
-#define API_NOT_IMPLEMENTED        (SDK_COMMON_ERROR_BASE+0x0010)
-#define FEATURE_NOT_ENABLED        (SDK_COMMON_ERROR_BASE+0x0011)
-/* @} */
-
-
-/**
- * @defgroup dm_specific_errors Error / status codes specific to device manager.
- * @{
- */
-#define DM_NO_APP_CONTEXT                (DEVICE_MANAGER_ERR_BASE+0x0040)
-#define DM_SERVICE_CONTEXT_NOT_APPLIED   (DEVICE_MANAGER_ERR_BASE+0x0041)
-#define DM_CONTEXT_INFO_LOST             (DEVICE_MANAGER_ERR_BASE+0x0042)
-#define DM_DEVICE_CONTEXT_FULL           (DEVICE_MANAGER_ERR_BASE+0x0043)
-/* @} */
-
-/**
- * @brief API Result.
- *
- * @details Indicates success or failure of an API procedure. In case of failure, a comprehensive
- *          error code indicating cause or reason for failure is provided.
- *
- *          Though called an API result, it could used in Asynchronous notifications callback along
- *          with asynchronous callback as event result. This mechanism is employed when an event
- *          marks the end of procedure initiated using API. API result, in this case, will only be
- *          an indicative of whether the procedure has been requested successfully.
- */
-typedef uint32_t ret_code_t;
-/** @} */
-/** @} */
-
-#endif // SDK_ERRORS_H__
--- a/source/nordic-sdk/components/libraries/util/sdk_os.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
- /** @cond */
-/**@file
- *
- * @defgroup sdk_os SDK OS Abstraction
- * @ingroup experimental_api
- * @details In order to made SDK modules independent of use of an embedded OS, and permit
- *          application with varied task architecture, SDK abstracts the OS specific
- *          elements here in order to make all other modules agnostic to the OS or task
- *          architecture.
- * @{
- */
-
-#ifndef SDK_OS_H__
-#define SDK_OS_H__
-
-#define SDK_MUTEX_DEFINE(X)
-#define SDK_MUTEX_INIT(X)
-#define SDK_MUTEX_LOCK(X)
-#define SDK_MUTEX_UNLOCK(X)
-
-/**
- * @defgroup os_data_type Data types.
- */
- 
-/** @} */
-/** @endcond */
-#endif // SDK_OS_H__
--- a/source/nordic-sdk/components/softdevice/common/softdevice_handler/ant_stack_handler_types.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/**@file
- *
- * @defgroup ant_stack_handler_types Types definitions for ANT support in SoftDevice handler.
- * @{
- * @ingroup  softdevice_handler
- * @brief    This file contains the declarations of types required for ANT stack support. These
- *           types will be defined when the preprocessor define ANT_STACK_SUPPORT_REQD is defined.
- */
-
-#ifndef ANT_STACK_HANDLER_TYPES_H__
-#define ANT_STACK_HANDLER_TYPES_H__
-
-#ifdef ANT_STACK_SUPPORT_REQD
-
-#include <stdlib.h>
-
-#define ANT_STACK_EVT_MSG_BUF_SIZE      32                                                /**< Size of ANT event message buffer. This will be provided to the SoftDevice while fetching an event. */
-#define ANT_STACK_EVT_STRUCT_SIZE       (sizeof(ant_evt_t))                               /**< Size of the @ref ant_evt_t structure. This will be used by the @ref softdevice_handler to internal event buffer size needed. */
-
-/**@brief ANT stack event type. */
-typedef struct
-{
-    uint8_t channel;                                                                      /**< Channel number. */
-    uint8_t event;                                                                        /**< Event code. */
-    uint8_t evt_buffer[ANT_STACK_EVT_MSG_BUF_SIZE];                                       /**< Event message buffer. */
-} ant_evt_t;
-
-/**@brief Application ANT stack event handler type. */
-typedef void (*ant_evt_handler_t) (ant_evt_t * p_ant_evt);
-
-/**@brief     Function for registering for ANT events.
- *
- * @details   The application should use this function to register for receiving ANT events from
- *            the SoftDevice. If the application does not call this function, then any ANT event
- *            that may be generated by the SoftDevice will NOT be fetched. Once the application has
- *            registered for the events, it is not possible to  possible to cancel the registration.
- *            However, it is possible to register a different function for handling the events at
- *            any point of time.
- *
- * @param[in] ant_evt_handler Function to be called for each received ANT event.
- *
- * @retval    NRF_SUCCESS     Successful registration.
- * @retval    NRF_ERROR_NULL  Null pointer provided as input.
- */
-uint32_t softdevice_ant_evt_handler_set(ant_evt_handler_t ant_evt_handler);
-
-#else
-
-// The ANT Stack support is not required.
-
-#define ANT_STACK_EVT_STRUCT_SIZE       0                                                 /**< Since the ANT stack support is not required, this is equated to 0, so that the @ref softdevice_handler.h can compute the internal event buffer size without having to care for ANT events.*/
-
-#endif // ANT_STACK_SUPPORT_REQD
-
-#endif // ANT_STACK_HANDLER_TYPES_H__
-
-/** @} */
\ No newline at end of file
--- a/source/nordic-sdk/components/softdevice/common/softdevice_handler/ble_stack_handler_types.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,94 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/**@file
- *
- * @defgroup ble_stack_handler_types Types definitions for BLE support in SoftDevice handler.
- * @{
- * @ingroup  softdevice_handler
- * @brief    This file contains the declarations of types required for BLE stack support. These
- *           types will be defined when the preprocessor define BLE_STACK_SUPPORT_REQD is defined.
- */
-
-#ifndef BLE_STACK_HANDLER_TYPES_H__
-#define BLE_STACK_HANDLER_TYPES_H__
-
-#define BLE_STACK_SUPPORT_REQD
-
-#ifdef BLE_STACK_SUPPORT_REQD
-
-#include <stdlib.h>
-#include "ble.h"
-#include "nrf_sdm.h"
-#include "app_error.h"
-#include "app_util.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif // #ifdef __cplusplus
-
-#define BLE_STACK_EVT_MSG_BUF_SIZE       (sizeof(ble_evt_t) + (GATT_MTU_SIZE_DEFAULT))     /**< Size of BLE event message buffer. This will be provided to the SoftDevice while fetching an event. */
-#define BLE_STACK_HANDLER_SCHED_EVT_SIZE 0                                                 /**< The size of the scheduler event used by SoftDevice handler when passing BLE events using the @ref app_scheduler. */
-
-/**@brief Application stack event handler type. */
-typedef void (*ble_evt_handler_t) (ble_evt_t * p_ble_evt);
-
-/**@brief     Function for registering for BLE events.
- *
- * @details   The application should use this function to register for receiving BLE events from
- *            the SoftDevice. If the application does not call this function, then any BLE event
- *            that may be generated by the SoftDevice will NOT be fetched. Once the application has
- *            registered for the events, it is not possible to cancel the registration.
- *            However, it is possible to register a different function for handling the events at
- *            any point of time.
- *
- * @param[in] ble_evt_handler Function to be called for each received BLE event.
- *
- * @retval    NRF_SUCCESS     Successful registration.
- * @retval    NRF_ERROR_NULL  Null pointer provided as input.
- */
-uint32_t softdevice_ble_evt_handler_set(ble_evt_handler_t ble_evt_handler);
-
-#ifdef __cplusplus
-}
-#endif // #ifdef __cplusplus
-
-#else
-
-#define BLE_STACK_EVT_MSG_BUF_SIZE        0                                                /**< Since the BLE stack support is not required, this is equated to 0, so that the @ref softdevice_handler.h can compute the internal event buffer size without having to care for BLE events.*/
-#define BLE_STACK_HANDLER_SCHED_EVT_SIZE  0
-
-#endif // BLE_STACK_SUPPORT_REQD
-
-#endif // BLE_STACK_HANDLER_TYPES_H__
-
-/** @} */
\ No newline at end of file
--- a/source/nordic-sdk/components/softdevice/common/softdevice_handler/softdevice_handler.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,323 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "softdevice_handler.h"
-#include <stdlib.h>
-#include "nordic_common.h"
-#include "app_error.h"
-#include "app_util.h"
-#include "nrf_assert.h"
-#include "nrf_soc.h"
-
-#if defined(ANT_STACK_SUPPORT_REQD) && defined(BLE_STACK_SUPPORT_REQD)
-    #include "ant_interface.h"
-#elif defined(ANT_STACK_SUPPORT_REQD) 
-    #include "ant_interface.h"
-#elif defined(BLE_STACK_SUPPORT_REQD)
-    #include "ble.h"
-#endif
-
-
-static softdevice_evt_schedule_func_t m_evt_schedule_func;              /**< Pointer to function for propagating SoftDevice events to the scheduler. */
-
-static volatile bool                  m_softdevice_enabled = false;     /**< Variable to indicate whether the SoftDevice is enabled. */
-
-#ifdef BLE_STACK_SUPPORT_REQD
-// The following three definitions is needed only if BLE events are needed to be pulled from the stack.
-static uint8_t                      * mp_ble_evt_buffer;                /**< Buffer for receiving BLE events from the SoftDevice. */
-static uint16_t                       m_ble_evt_buffer_size;            /**< Size of BLE event buffer. */
-static ble_evt_handler_t              m_ble_evt_handler;                /**< Application event handler for handling BLE events. */
-#endif
-
-#ifdef ANT_STACK_SUPPORT_REQD
-// The following two definition is needed only if ANT events are needed to be pulled from the stack.
-static ant_evt_t                      m_ant_evt_buffer;                 /**< Buffer for receiving ANT events from the SoftDevice. */
-static ant_evt_handler_t              m_ant_evt_handler;                /**< Application event handler for handling ANT events.  */
-#endif
-
-static sys_evt_handler_t              m_sys_evt_handler;                /**< Application event handler for handling System (SOC) events.  */
-
-
-/**@brief       Callback function for asserts in the SoftDevice.
- *
- * @details     A pointer to this function will be passed to the SoftDevice. This function will be
- *              called if an ASSERT statement in the SoftDevice fails.
- *
- * @param[in]   pc         The value of the program counter when the ASSERT call failed.
- * @param[in]   line_num   Line number of the failing ASSERT call.
- * @param[in]   file_name  File name of the failing ASSERT call.
- */
-void softdevice_assertion_handler(uint32_t pc, uint16_t line_num, const uint8_t * file_name)
-{
-    UNUSED_PARAMETER(pc);
-    assert_nrf_callback(line_num, file_name);
-}
-
-
-void intern_softdevice_events_execute(void)
-{
-    if (!m_softdevice_enabled)
-    {
-        // SoftDevice not enabled. This can be possible if the SoftDevice was enabled by the
-        // application without using this module's API (i.e softdevice_handler_init)
-
-        return;
-    }
-
-    bool no_more_soc_evts = (m_sys_evt_handler == NULL);
-#ifdef BLE_STACK_SUPPORT_REQD
-    bool no_more_ble_evts = (m_ble_evt_handler == NULL);
-#endif
-#ifdef ANT_STACK_SUPPORT_REQD
-    bool no_more_ant_evts = (m_ant_evt_handler == NULL);
-#endif
-
-    for (;;)
-    {
-        uint32_t err_code;
-
-        if (!no_more_soc_evts)
-        {
-            uint32_t evt_id;
-
-            // Pull event from SOC.
-            err_code = sd_evt_get(&evt_id);
-            
-            if (err_code == NRF_ERROR_NOT_FOUND)
-            {
-                no_more_soc_evts = true;
-            }
-            else if (err_code != NRF_SUCCESS)
-            {
-                APP_ERROR_HANDLER(err_code);
-            }
-            else
-            {
-                // Call application's SOC event handler.
-                m_sys_evt_handler(evt_id);
-            }
-        }
-
-#ifdef BLE_STACK_SUPPORT_REQD
-        // Fetch BLE Events.
-        if (!no_more_ble_evts)
-        {
-            // Pull event from stack
-            uint16_t evt_len = m_ble_evt_buffer_size;
-
-            err_code = sd_ble_evt_get(mp_ble_evt_buffer, &evt_len);
-            if (err_code == NRF_ERROR_NOT_FOUND)
-            {
-                no_more_ble_evts = true;
-            }
-            else if (err_code != NRF_SUCCESS)
-            {
-                APP_ERROR_HANDLER(err_code);
-            }
-            else
-            {
-                // Call application's BLE stack event handler.
-                m_ble_evt_handler((ble_evt_t *)mp_ble_evt_buffer);
-            }
-        }
-#endif
-
-#ifdef ANT_STACK_SUPPORT_REQD
-        // Fetch ANT Events.
-        if (!no_more_ant_evts)
-        {
-            // Pull event from stack
-            err_code = sd_ant_event_get(&m_ant_evt_buffer.channel,
-                                        &m_ant_evt_buffer.event,
-                                        m_ant_evt_buffer.evt_buffer);
-            if (err_code == NRF_ERROR_NOT_FOUND)
-            {
-                no_more_ant_evts = true;
-            }
-            else if (err_code != NRF_SUCCESS)
-            {
-                APP_ERROR_HANDLER(err_code);
-            }
-            else
-            {
-                // Call application's ANT stack event handler.
-                m_ant_evt_handler(&m_ant_evt_buffer);
-            }
-        }
-#endif
-
-        if (no_more_soc_evts)
-        {
-            // There are no remaining System (SOC) events to be fetched from the SoftDevice.
-#if defined(ANT_STACK_SUPPORT_REQD) && defined(BLE_STACK_SUPPORT_REQD)
-            // Check if there are any remaining BLE and ANT events.
-            if (no_more_ble_evts && no_more_ant_evts)
-            {
-                break;
-            }
-#elif defined(BLE_STACK_SUPPORT_REQD)
-            // Check if there are any remaining BLE events.
-            if (no_more_ble_evts)
-            {
-                break;
-            }
-#elif defined(ANT_STACK_SUPPORT_REQD)
-            // Check if there are any remaining ANT events.
-            if (no_more_ant_evts)
-            {
-                break;
-            }
-#else
-            // No need to check for BLE or ANT events since there is no support for BLE and ANT
-            // required.
-            break;
-#endif
-        }
-    }
-}
-
-
-uint32_t softdevice_handler_init(nrf_clock_lfclksrc_t           clock_source,
-                                 void *                         p_ble_evt_buffer,
-                                 uint16_t                       ble_evt_buffer_size,
-                                 softdevice_evt_schedule_func_t evt_schedule_func)
-{
-    uint32_t err_code;
-
-    // Save configuration.
-#if defined (BLE_STACK_SUPPORT_REQD)
-    // Check that buffer is not NULL.
-    if (p_ble_evt_buffer == NULL)
-    {
-        return NRF_ERROR_INVALID_PARAM;
-    }
-    
-    // Check that buffer is correctly aligned.
-    if (!is_word_aligned(p_ble_evt_buffer))
-    {
-        return NRF_ERROR_INVALID_PARAM;
-    }
-
-    mp_ble_evt_buffer     = (uint8_t *)p_ble_evt_buffer;
-    m_ble_evt_buffer_size = ble_evt_buffer_size;
-#else
-    // The variables p_ble_evt_buffer and ble_evt_buffer_size is not needed if BLE Stack support
-    // is not required.
-    UNUSED_PARAMETER(p_ble_evt_buffer);
-    UNUSED_PARAMETER(ble_evt_buffer_size);
-#endif
-
-    m_evt_schedule_func = evt_schedule_func;
-
-    // Initialize SoftDevice.
-    err_code = sd_softdevice_enable(clock_source, softdevice_assertion_handler);
-    if (err_code != NRF_SUCCESS)
-    {
-        return err_code;
-    }
-
-    m_softdevice_enabled = true;
-
-    // Enable BLE event interrupt (interrupt priority has already been set by the stack).
-    return sd_nvic_EnableIRQ(SWI2_IRQn);
-}
-
-
-uint32_t softdevice_handler_sd_disable(void)
-{
-    uint32_t err_code = sd_softdevice_disable();
- 
-    m_softdevice_enabled = !(err_code == NRF_SUCCESS);
-
-    return err_code;
-}
-
-
-#ifdef BLE_STACK_SUPPORT_REQD
-uint32_t softdevice_ble_evt_handler_set(ble_evt_handler_t ble_evt_handler)
-{
-    if (ble_evt_handler == NULL)
-    {
-        return NRF_ERROR_NULL;
-    }
-
-    m_ble_evt_handler = ble_evt_handler;
-
-    return NRF_SUCCESS;
-}
-#endif
-
-
-#ifdef ANT_STACK_SUPPORT_REQD
-uint32_t softdevice_ant_evt_handler_set(ant_evt_handler_t ant_evt_handler)
-{
-    if (ant_evt_handler == NULL)
-    {
-        return NRF_ERROR_NULL;
-    }
-
-    m_ant_evt_handler = ant_evt_handler;
-
-    return NRF_SUCCESS;
-}
-#endif
-
-
-uint32_t softdevice_sys_evt_handler_set(sys_evt_handler_t sys_evt_handler)
-{
-    if (sys_evt_handler == NULL)
-    {
-        return NRF_ERROR_NULL;
-    }
-
-    m_sys_evt_handler = sys_evt_handler;
-
-    return NRF_SUCCESS;
-}
-
-
-/**@brief   Function for handling the Application's BLE Stack events interrupt.
- *
- * @details This function is called whenever an event is ready to be pulled.
- */
-void SWI2_IRQHandler(void)
-{
-    if (m_evt_schedule_func != NULL)
-    {
-        uint32_t err_code = m_evt_schedule_func();
-        APP_ERROR_CHECK(err_code);
-    }
-    else
-    {
-        intern_softdevice_events_execute();
-    }
-}
\ No newline at end of file
--- a/source/nordic-sdk/components/softdevice/common/softdevice_handler/softdevice_handler.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,176 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/** @file
- *
- * @defgroup softdevice_handler SoftDevice Event Handler
- * @{
- * @ingroup  app_common
- * @brief    API for initializing and disabling the SoftDevice
- *
- * @details  This API contains the functions and defines exposed by the @ref lib_softdevice_handler.
- *           For more information on the library and how the application should use it, please refer
- *           @ref lib_softdevice_handler.
- *
- * @note     Use the USE_SCHEDULER parameter of the SOFTDEVICE_HANDLER_INIT() macro to select if
- *           the @ref app_scheduler is to be used or not.
- *
- * @note     Even if the scheduler is not used, softdevice_handler.h will include app_scheduler.h.
- *           So when compiling, app_scheduler.h must be available in one of the compiler include
- *           paths.
- */
-
-#ifndef SOFTDEVICE_HANDLER_H__
-#define SOFTDEVICE_HANDLER_H__
-
-#include <stdlib.h>
-#include "nordic_common.h"
-#include "nrf_sdm.h"
-#include "app_error.h"
-#include "app_util.h"
-#include "ble_stack_handler_types.h"
-#include "ant_stack_handler_types.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif // #ifdef __cplusplus
-
-#define SOFTDEVICE_SCHED_EVT_SIZE       0                                                 /**< Size of button events being passed through the scheduler (is to be used for computing the maximum size of scheduler events). For SoftDevice events, this size is 0, since the events are being pulled in the event handler. */
-#define SYS_EVT_MSG_BUF_SIZE            sizeof(uint32_t)                                  /**< Size of System (SOC) event message buffer. */
-
-/**@brief Type of function for passing events from the stack handler module to the scheduler. */
-typedef uint32_t (*softdevice_evt_schedule_func_t) (void);
-
-/**@brief Application System (SOC) event handler type. */
-typedef void (*sys_evt_handler_t) (uint32_t evt_id);
-
-
-/**@brief     Macro for initializing the stack event handler.
- *
- * @details   It will handle dimensioning and allocation of the memory buffer required for reading
- *            events from the stack, making sure the buffer is correctly aligned. It will also
- *            connect the stack event handler to the scheduler/RTOS (if specified).
- *
- * @param[in] CLOCK_SOURCE     Low frequency clock source and accuracy (type nrf_clock_lfclksrc_t,
- *                             see sd_softdevice_enable() for details).
- * @param[in] EVT_HANDLER      scheduler/RTOS event handler function.
- *
- * @note      Since this macro allocates a buffer, it must only be called once (it is OK to call it
- *            several times as long as it is from the same location, that is to do a
- *            reinitialization).
- */
-/*lint -emacro(506, SOFTDEVICE_HANDLER_INIT) */ /* Suppress "Constant value Boolean */
-#define SOFTDEVICE_HANDLER_INIT(CLOCK_SOURCE, EVT_HANDLER)                                         \
-    do                                                                                             \
-    {                                                                                              \
-        static uint32_t BLE_EVT_BUFFER[CEIL_DIV(BLE_STACK_EVT_MSG_BUF_SIZE, sizeof(uint32_t))];    \
-        uint32_t ERR_CODE;                                                                         \
-        ERR_CODE = softdevice_handler_init((CLOCK_SOURCE),                                         \
-                                           BLE_EVT_BUFFER,                                         \
-                                           sizeof(BLE_EVT_BUFFER),                                 \
-                                           EVT_HANDLER);                                           \
-        APP_ERROR_CHECK(ERR_CODE);                                                                 \
-    } while (0)
-
-
-/**@brief      Function for initializing the stack handler module.
- *
- * @details    Enables the SoftDevice and the stack event interrupt handler.
- *
- * @note       This function must be called before calling any function in the SoftDevice API.
- *
- * @note       Normally initialization should be done using the SOFTDEVICE_HANDLER_INIT() macro,
- *             as that will both allocate the event buffer, and also align the buffer correctly.
- *
- * @param[in]  clock_source        Low frequency clock source to be used by the SoftDevice.
- * @param[in]  p_ble_evt_buffer    Buffer for holding one BLE stack event. Since heap is not being
- *                                 used, this buffer must be provided by the application. The
- *                                 buffer must be large enough to hold the biggest stack event the
- *                                 application is supposed to handle. The buffer must be aligned to
- *                                 a 4 byte boundary. This parameter is unused if BLE stack support
- *                                 is not required.
- * @param[in]  ble_evt_buffer_size Size of SoftDevice BLE event buffer. This parameter is unused if
- *                                 BLE stack support is not required.
- * @param[in]  evt_schedule_func   Function for passing events to the scheduler. Point to
- *                                 ble_ant_stack_evt_schedule() to connect to the scheduler.
- *                                 Set to NULL to make the stack handler module call the event
- *                                 handler directly from the stack event interrupt handler.
- *
- * @retval     NRF_SUCCESS               Successful initialization.
- * @retval     NRF_ERROR_INVALID_PARAM   Invalid parameter (buffer not aligned to a 4 byte
- *                                       boundary) or NULL.
- */
-uint32_t softdevice_handler_init(nrf_clock_lfclksrc_t              clock_source,
-                                 void *                            p_ble_evt_buffer,
-                                 uint16_t                          ble_evt_buffer_size,
-                                 softdevice_evt_schedule_func_t    evt_schedule_func);
-
-
-/**@brief     Function for disabling the SoftDevice.
- *
- * @details   This function will disable the SoftDevice. It will also update the internal state
- *            of this module.
- */
-uint32_t softdevice_handler_sd_disable(void);
-
-
-/**@brief     Function for registering for System (SOC) events.
- *
- * @details   The application should use this function to register for receiving System (SOC)
- *            events from the SoftDevice. If the application does not call this function, then any
- *            System (SOC) events that may be generated by the SoftDevice will NOT be fetched. Once
- *            the application has registered for the events, it is not possible to  possible to
- *            cancel the registration. However, it is possible to register a different function for
- *            handling the events at any point of time.
- *
- * @param[in] sys_evt_handler Function to be called for each received System (SOC) event.
- *
- * @retval    NRF_SUCCESS     Successful registration.
- * @retval    NRF_ERROR_NULL  Null pointer provided as input.
- */
-uint32_t softdevice_sys_evt_handler_set(sys_evt_handler_t sys_evt_handler);
-
-
-// Functions for connecting the Stack Event Handler to the scheduler:
-/**@cond NO_DOXYGEN */
-void intern_softdevice_events_execute(void);
-
-
-/**@endcond */
-
-#ifdef __cplusplus
-}
-#endif // #ifdef __cplusplus
-
-#endif // SOFTDEVICE_HANDLER_H__
-
-/** @} */
\ No newline at end of file
--- a/source/nordic-sdk/components/softdevice/common/softdevice_handler/softdevice_handler_appsh.c	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "softdevice_handler_appsh.h"
-#include "app_scheduler.h"
-#include <string.h>
-
-void softdevice_evt_get(void * p_event_data, uint16_t event_size)
-{
-    APP_ERROR_CHECK_BOOL(event_size == 0);
-    intern_softdevice_events_execute();
-}
-
-uint32_t softdevice_evt_schedule(void)
-{
-    return app_sched_event_put(NULL, 0, softdevice_evt_get);
-}
\ No newline at end of file
--- a/source/nordic-sdk/components/softdevice/common/softdevice_handler/softdevice_handler_appsh.h	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#ifndef SOFTDEVICE_HANDLER_APPSH_H
-#define SOFTDEVICE_HANDLER_APPSH_H
-
-#include "softdevice_handler.h"
-#include <stdint.h>
-
-#define SOFTDEVICE_HANDLER_APPSH_INIT(CLOCK_SOURCE,USE_SCHEDULER) \
-    SOFTDEVICE_HANDLER_INIT(CLOCK_SOURCE,(USE_SCHEDULER) ? softdevice_evt_schedule : NULL)
-
-uint32_t softdevice_evt_schedule(void);
-
-#endif //SOFTDEVICE_HANDLER_APPSH_H
\ No newline at end of file
--- a/source/nordic-sdk/components/softdevice/s130/doc/ble_api.dox	Wed Apr 06 22:38:43 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2017 +0,0 @@
-/**
- * @addtogroup BLE_COMMON 
- * @{
- * @defgroup BLE_COMMON_MSC Message Sequence Charts
- * @{
- * @defgroup BLE_COMMON_IRQ_EVT_MSC Interrupt-driven Event Retrieval
- * @msc
- * hscale = "1.5";
- * APP,SD;
- * |||;
- * APP=>SD [label = "sd_softdevice_enable(clock, assertion_handler);"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * APP=>SD [label = "sd_nvic_EnableIRQ(SD_EVT_IRQn)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * APP rbox SD [label="Application runs and uses SD API"];
- * |||;
- * SD rbox SD [label="Event Available for the App"];
- * |||;
- * APP<-SD [label = "SD_EVT_IRQn", textcolor="#800080", linecolor="#800080"];
- * APP=>APP [label = "SD_EVT_IRQHandler()"];
- * APP=>SD [label = "sd_ble_evt_get(buffer);"];
- * APP<<SD [label = "{NRF_SUCCESS, event}"];
- * |||;
- * @endmsc
- *
- * @defgroup BLE_COMMON_THREAD_EVT_MSC Thread Mode Event Retrieval
- * @msc
- * hscale = "1.5";
- * APP,SD;
- * |||;
- * APP=>SD [label = "sd_softdevice_enable(clock, assertion_handler);"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * APP=>SD [label = "sd_app_evt_wait(void);"];
- * APP rbox APP [label="App Thread Mode blocked, CPU in low power mode"];
- * |||;
- * ...;
- * |||;
- * SD rbox SD [label="Event Available for the App"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * APP=>SD [label = "sd_ble_evt_get(buffer);"];
- * APP<<SD [label = "{NRF_SUCCESS, event}"];
- * APP=>SD [label = "sd_app_evt_wait(void);"];
- * APP rbox APP [label="App Thread Mode blocked, CPU in low power mode"];
- * |||;
- * ...;
- * |||;
- * SD rbox SD [label="Event Available for the App"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * APP=>SD [label = "sd_ble_evt_get(buffer);"];
- * APP<<SD [label = "{NRF_SUCCESS, event}"];
- * APP=>SD [label = "sd_app_evt_wait(void);"];
- * APP rbox APP [label="App Thread Mode blocked, CPU in low power mode"];
- * |||;
- * ...;
- * |||;
- * @endmsc
- *
- * @defgroup BLE_COMMON_APP_BUFF_MSC App Buffer Management
- * @msc
- * hscale = "1.5";
- * APP,SD,PEER;
- * |||;
- * APP=>SD [label = "sd_ble_tx_buffer_count_get();"];
- * APP<<SD [label = "{NRF_SUCCESS, N}"];
- * APP rbox APP [label="available = N"];
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_write(handle, value)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * APP rbox APP [label="available--"];
- * SD:>PEER [label = "ATT Write Command", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_EVT_TX_COMPLETE {1}"];
- * APP rbox APP [label="available += 1"];
- * |||;
- * ...;
- * |||;
- * APP=>SD [label = "sd_ble_gatts_hvx(NOTIFICATION, app_value)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * APP rbox APP [label="available--"];
- * SD:>PEER [label = "ATT Handle Value Notification", textcolor="#000080", linecolor="#000080"];
- * APP=>SD [label = "sd_ble_gatts_hvx(NOTIFICATION, app_value)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * APP rbox APP [label="available--"];
- * SD:>PEER [label = "ATT Handle Value Notification", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_EVT_TX_COMPLETE {2}"];
- * APP rbox APP [label="available += 2"];
- * |||;
- * ...;
- * |||;
- * APP rbox PEER [label="Terminate Connection"];
- * |||;
- * APP rbox APP [label="available = N"];
- * |||;
- * @endmsc
- * @}
- * @}
- */
-
-/**
- * @addtogroup BLE_GAP 
- * @{
- * @defgroup BLE_GAP_MSC Message Sequence Charts
- * @{
- * @defgroup BLE_GAP_ADV_MSC GAP Advertisement
- * @msc
- * hscale = "1.5";
- * APP,SD,SCANNERS;
- * |||;
- * APP=>SD [label = "sd_ble_gap_address_set(addr)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * APP=>SD [label = "sd_ble_gap_adv_data_set(adv, sr)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * APP=>SD [label = "sd_ble_gap_adv_start(params)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * SD->SCANNERS [label = "ADV packet", textcolor="#000080", linecolor="#000080"];
- * SD->SCANNERS [label = "ADV packet", textcolor="#000080", linecolor="#000080"];
- * SD->SCANNERS [label = "ADV packet", textcolor="#000080", linecolor="#000080"];
- * ...;
- * SD->SCANNERS [label = "ADV packet", textcolor="#000080", linecolor="#000080"];
- * |||;
- * --- [label = " Variant #1 App Stops Advertisement "];
- * APP=>SD [label = "sd_ble_gap_adv_stop()"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * --- [label = " Variant #2 Advertisement Timeout "];
- * APP<<=SD [label = "BLE_GAP_EVT_TIMEOUT"];
- * @endmsc
- *
- * @defgroup BLE_GAP_CONN_MSC GAP Peripheral Connection Establishment and Termination
- * @msc
- * hscale = "1.5";
- * APP,SD,CENTRAL;
- * |||;
- * APP rbox CENTRAL [label="Start Connectable Advertising"];
- * |||;
- * SD<:>CENTRAL [label = "Connection Establishment", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONNECTED"];
- * |||;
- * --- [label = " Variant #1 Local Disconnection "];
- * APP=>SD [label = "sd_ble_gap_disconnect(reason)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>CENTRAL [label = "Connection Termination", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_DISCONNECTED {reason}"];
- * |||;
- * --- [label = " Variant #2 Remote Disconnection "];
- * SD<:CENTRAL [label = "Connection Termination", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_DISCONNECTED {reason}"];
- * @endmsc
- *
- * @defgroup BLE_GAP_CPU_MSC GAP Connection Parameter Update
- * @msc
- * hscale = "1.5";
- * APP,SD,CENTRAL;
- * |||;
- * APP rbox CENTRAL [label="Connection Established with conn. params. CP#1"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_conn_param_update(CP#2)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>CENTRAL [label = "L2CAP CPU Request", textcolor="#000080", linecolor="#000080"];
- * |||;
- * --- [label = " Variant #1 Central Accepts "];
- * |||;
- * SD<:CENTRAL [label = "L2CAP CPU Response: Accepted", textcolor="#000080", linecolor="#000080"];
- * |||;
- * SD<:CENTRAL [label = "Connection Update Start", textcolor="#000080", linecolor="#000080"];
- * SD:>CENTRAL [label = "Connection Update Complete", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_PARAM_UPDATE {CP#2}"];
- * |||;
- * --- [label = " Variant #2 Central Rejects "];
- * |||;
- * SD<:CENTRAL [label = "L2CAP CPU Response: Rejected", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_PARAM_UPDATE {CP#1}"];
- * --- [label = " Variant #3 Central Ignores "];
- * |||;
- * ...;
- * |||;
- * SD box SD [label="Timeout"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_PARAM_UPDATE {CP#1}"];
- * @endmsc
- *
- * @defgroup BLE_GAP_RSSI_FILT_MSC GAP RSSI for connections with event filter
- * @msc
- * hscale = "1.5";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * --- [label = " Variant #1: Trigger event when a new RSSI is available"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_rssi_start(conn_handle, 0, 0)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * SD<-PEER [label = "RSSI Sample", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_RSSI_CHANGED {RSSI#1}"];
- * |||;
- * SD<-PEER [label = "RSSI Sample", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_RSSI_CHANGED {RSSI#2}"];
- * |||;
- * SD<-PEER [label = "RSSI Sample", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_RSSI_CHANGED {RSSI#3}"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_rssi_stop()"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * --- [label = " Variant #2: Only trigger event if RSSI changes by 5 dBm or more."];
- * |||;
- * APP=>SD [label = "sd_ble_gap_rssi_start(conn_handle, 0x05, 0x00)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * SD<-PEER [label = "RSSI Sample=0x00", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_RSSI_CHANGED {RSSI#1}"];
- * |||;
- * SD<-PEER [label = "RSSI Sample=0x04", textcolor="#000080", linecolor="#000080"];
- * |||;
- * SD<-PEER [label = "RSSI Sample=0x03", textcolor="#000080", linecolor="#000080"];
- * |||;
- * SD<-PEER [label = "RSSI Sample>=0x05", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_RSSI_CHANGED {RSSI#2}"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_rssi_stop()"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * --- [label = " Variant #3: Only trigger event if more than 3 RSSI samples have deviated from the last reported RSSI by 5 dBm or more."];
- * |||;
- * APP=>SD [label = "sd_ble_gap_rssi_start(conn_handle, 0x05, 0x03)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * SD<-PEER [label = "RSSI Sample=0x00", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_RSSI_CHANGED {RSSI#1}"];
- * |||;
- * SD<-PEER [label = "RSSI Sample=0x04", textcolor="#000080", linecolor="#000080"];
- * |||;
- * SD<-PEER [label = "RSSI Sample=0x0A", textcolor="#000080", linecolor="#000080"];
- * |||;
- * SD<-PEER [label = "RSSI Sample>=0x06", textcolor="#000080", linecolor="#000080"];
- * |||;
- * SD<-PEER [label = "RSSI Sample>=0x09", textcolor="#000080", linecolor="#000080"];
- * |||;
- * SD<-PEER [label = "RSSI Sample>=0x07", textcolor="#000080", linecolor="#000080"];
- * |||;
- * APP<<=SD [label = "BLE_GAP_EVT_RSSI_CHANGED {RSSI#2}"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_rssi_stop()"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * @endmsc
- *
- * @defgroup BLE_GAP_CENTRAL_RSSI_READ_MSC GAP RSSI get sample
- * @msc
- * hscale = "1.5";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_rssi_get(conn_handle, p_rssi)"];
- * APP<<SD [label = "NRF_ERROR_INVALID_STATE"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_rssi_start(conn_handle, BLE_GAP_RSSI_THRESHOLD_INVALID, 0x00)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * APP=>SD [label = "sd_ble_gap_rssi_get(conn_handle, p_rssi)"];
- * APP<<SD [label = "NRF_ERROR_NOT_FOUND"];
- * ...;
- * ...;
- * APP rbox PEER [label="Connection events"];
- * ...;
- * ...;
- * |||;
- * SD<-PEER [label = "RSSI Sample=0x03 [dBm]", textcolor="#000080", linecolor="#000080"];
- * APP=>SD [label = "sd_ble_gap_rssi_get(conn_handle, p_rssi)"];
- * APP<<SD [label = "NRF_SUCCESS, *p_rssi=0x03 [dBm]"];
- * APP=>SD [label = "sd_ble_gap_rssi_stop()"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * @endmsc
- *
- * @defgroup BLE_GAP_PERIPH_PAIRING_JW_MSC GAP Peripheral Pairing: Just Works
- * @msc
- * hscale = "2";
- * APP,SD,CENTRAL;
- * |||;
- * APP rbox CENTRAL [label="Connection Established"];
- * |||;
- * SD<:CENTRAL [label = "SMP Pairing Request", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_SEC_PARAMS_REQUEST {central_params: no_bond, no_mitm, no_io_caps}"];
- * APP=>SD [label = "sd_ble_gap_sec_params_reply(SUCCESS, periph_params: no_bond, no_mitm, no_io_caps, NULL)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>CENTRAL [label = "SMP Pairing Response", textcolor="#000080", linecolor="#000080"];
- * |||;
- * SD abox CENTRAL [label="SMP Pairing Phase 2", textbgcolor="#7f7fff"];
- * |||;
- * APP rbox CENTRAL [label = "Encrypted with STK"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_SEC_UPDATE {ENC_NO_MITM}"];
- * APP<<=SD [label = "BLE_GAP_EVT_AUTH_STATUS {SUCCESS}"];
- * @endmsc
- *
- * @defgroup BLE_GAP_PERIPH_BONDING_JW_MSC GAP Peripheral Bonding: Just Works
- * @msc
- * hscale = "2";
- * APP,SD,CENTRAL;
- * |||;
- * APP rbox CENTRAL [label="Connection Established"];
- * |||;
- * SD<:CENTRAL [label = "SMP Pairing Request", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_SEC_PARAMS_REQUEST {central_params: bond, no_mitm, no_io_caps}"];
- * APP=>SD [label = "sd_ble_gap_sec_params_reply(SUCCESS, periph_params: bond, no_mitm, no_io_caps, p_keyset)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>CENTRAL [label = "SMP Pairing Response", textcolor="#000080", linecolor="#000080"];
- * |||;
- * SD abox CENTRAL [label="SMP Pairing Phase 2", textbgcolor="#7f7fff"];
- * |||;
- * APP rbox CENTRAL [label = "Encrypted with STK"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_SEC_UPDATE {ENC_NO_MITM}"];
- * |||;
- * SD abox CENTRAL [label="SMP Pairing Phase 3", textbgcolor="#7f7fff"];
- * |||;
- * APP<<=SD [label = "BLE_GAP_EVT_AUTH_STATUS {SUCCESS}"];
- * APP rbox APP [label = "Keys stored in keyset"];
- * @endmsc
- *
- * @defgroup BLE_GAP_PERIPH_BONDING_PK_PERIPH_MSC GAP Peripheral Bonding: Passkey Entry, Peripheral displays
- * @msc
- * hscale = "2";
- * APP,SD,CENTRAL;
- * |||;
- * APP rbox CENTRAL [label="Connection Established"];
- * |||;
- * SD<:CENTRAL [label = "SMP Pairing Request", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_SEC_PARAMS_REQUEST {central_params: bond, mitm, keyboard}"];
- * APP=>SD [label = "sd_ble_gap_sec_params_reply(SUCCESS, periph_params: bond, mitm, display, p_keyset)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>CENTRAL [label = "SMP Pairing Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_PASSKEY_DISPLAY {passkey}"];
- * APP rbox APP [label="Passkey displayed to the user"];
- * |||;
- * SD abox CENTRAL [label="SMP Pairing Phase 2", textbgcolor="#7f7fff"];
- * |||;
- * APP rbox CENTRAL [label = "Encrypted with STK"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_SEC_UPDATE {ENC_MITM}"];
- * |||;
- * SD abox CENTRAL [label="SMP Pairing Phase 3", textbgcolor="#7f7fff"];
- * |||;
- * APP<<=SD [label = "BLE_GAP_EVT_AUTH_STATUS {SUCCESS}"];
- * APP rbox APP [label = "Keys stored in keyset"];
- * @endmsc
- *
- * @defgroup BLE_GAP_PERIPH_BONDING_PK_CENTRAL_OOB_MSC GAP Peripheral Bonding: Passkey Entry (Central display) or OOB MSC
- * @msc
- * hscale = "2";
- * APP,SD,CENTRAL;
- * |||;
- * APP rbox CENTRAL [label="Connection Established"];
- * |||;
- * SD<:CENTRAL [label = "SMP Pairing Request", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_SEC_PARAMS_REQUEST {central_params: bond, mitm, display}"];
- * APP=>SD [label = "sd_ble_gap_sec_params_reply(SUCCESS, periph_params: bond, mitm, keyboard, p_keyset)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>CENTRAL [label = "SMP Pairing Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_AUTH_KEY_REQUEST {type}"];
- * APP rbox APP [label="User enters Passkey or data received Out Of Band"];
- * APP=>SD [label = "sd_ble_gap_auth_key_reply(passkey or OOB)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * SD abox CENTRAL [label="SMP Pairing Phase 2", textbgcolor="#7f7fff"];
- * |||;
- * APP rbox CENTRAL [label = "Encrypted with STK"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_SEC_UPDATE {ENC_MITM}"];
- * |||;
- * SD abox CENTRAL [label="SMP Pairing Phase 3", textbgcolor="#7f7fff"];
- * |||;
- * APP<<=SD [label = "BLE_GAP_EVT_AUTH_STATUS {SUCCESS}"];
- * APP rbox APP [label = "Keys stored in keyset"];
- * @endmsc
- *
- * @defgroup BLE_GAP_PERIPH_BONDING_STATIC_PK_PERIPHERAL GAP Bonding: Passkey Entry (Peripheral uses static passkey) MSC
- * @msc
- * hscale = "2";
- * APP,SD,CENTRAL;
- * |||;
- * APP=>SD [label = "sd_ble_opt_set(opt_id = BLE_GAP_OPT_PASSKEY, p_opt->p_passkey=passkey)"];
- * APP rbox CENTRAL [label="Connection Established"];
- * |||;
- * SD<:CENTRAL [label = "SMP Pairing Request", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_SEC_PARAMS_REQUEST {central_params: bond, mitm, keyboard}"];
- * APP=>SD [label = "sd_ble_gap_sec_params_reply(SUCCESS, periph_params: bond, mitm, io_caps = display)"];
- *
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>CENTRAL [label = "SMP Pairing Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_PASSKEY_DISPLAY {passkey}"];
- * APP rbox APP [label="Passkey displayed to the user"];
- * |||;
- * SD abox CENTRAL [label="SMP Pairing Phase 2", textbgcolor="#7f7fff"];
- * |||;
- * APP rbox CENTRAL [label = "Encrypted with STK"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_SEC_UPDATE {ENC_MITM}"];
- * |||;
- * SD abox CENTRAL [label="SMP Pairing Phase 3", textbgcolor="#7f7fff"];
- * |||;
- * APP<<=SD [label = "BLE_GAP_EVT_AUTH_STATUS {SUCCESS, periph_keys}"];
- * APP rbox APP [label = "Store Peripheral Keys"];
- * @endmsc
- *
- * @defgroup BLE_GAP_PERIPH_ENC_MSC GAP Peripheral Encryption Establishment using stored keys
- * @msc
- * hscale = "1.5";
- * APP,SD,CENTRAL;
- * |||;
- * APP rbox CENTRAL [label="Connection Established"];
- * |||;
- * SD<:CENTRAL [label = "LL Encryption Request", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_SEC_INFO_REQUEST {addr, ediv, rand}"];
- * |||;
- * --- [label = " Variant #1 App Replies with Keys "];
- * |||;
- * APP rbox APP [label = "Load Peripheral Keys"];
- * APP=>SD [label = "sd_ble_gap_sec_info_reply(ediv, rand, LTK)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>CENTRAL [label = "LL Encryption Response", textcolor="#000080", linecolor="#000080"];
- * APP rbox CENTRAL [label = "Encrypted with LTK"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_SEC_UPDATE"];
- * |||;
- * --- [label = " Variant #2 App Replies without Keys "];
- * |||;
- * APP=>SD [label = "sd_ble_gap_sec_info_reply(NULL)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>CENTRAL [label = "LL Reject Ind: Pin or Key Missing", textcolor="#000080", linecolor="#000080"];
- * APP rbox CENTRAL [label = "Link is NOT encrypted"];
- * |||;
- * --- [label = " Variant #3 App Replies with Incorrect Keys "];
- * |||;
- * APP rbox APP [label = "Load Incorrect Peripheral Keys"];
- * APP=>SD [label = "sd_ble_gap_sec_info_reply(ediv, rand, LTK)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>CENTRAL [label = "LL Encryption Response", textcolor="#000080", linecolor="#000080"];
- * SD<:CENTRAL [label = "Connection Termination", textcolor="#000080", linecolor="#000080"];
- * APP rbox CENTRAL [label = "Link Terminated"];
- * APP<<=SD [label = "BLE_GAP_EVT_DISCONNECTED {MIC Failure}"];
- * @endmsc
- *
- * @defgroup BLE_GAP_PERIPH_SEC_MSC GAP Peripheral Initiated Security Establishment
- * @msc
- * hscale = "1.5";
- * APP,SD,CENTRAL;
- * |||;
- * APP rbox CENTRAL [label="Connection Established"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_authenticate(params)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>CENTRAL [label = "SMP Security Request", textcolor="#000080", linecolor="#000080"];
- * |||;
- * --- [label = " Variant #1 Central initiates Security Establishment "];
- * |||;
- * APP rbox CENTRAL [label="Encryption or Pairing/Bonding initiated by Central"];
- * |||;
- * --- [label = " Variant #2 Central ignores "];
- * |||;
- * ...;
- * |||;
- * APP<<=SD [label = "BLE_GAP_EVT_TIMEOUT"];
- * |||;
- * @endmsc
- *
- * @defgroup BLE_GAP_PERIPH_PAIRING_KS_OUT_OF_RANGE_MSC GAP Failed Pairing: Keysize out of supported range
- * This occurs if the min key size offered by the peer is above 16, or max key size below 7.
- * @msc
- * hscale = "2";
- * APP,SD,CENTRAL;
- * |||;
- * APP rbox CENTRAL [label="Connection Established"];
- * |||;
- * SD<:CENTRAL [label = "SMP Pairing Request", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_AUTH_STATUS {auth_status: Invalid params, error_src: local}"];
- * SD:>CENTRAL [label = "SMP Pairing failed", textcolor="#000080", linecolor="#000080"];
- * @endmsc
- *
- * @defgroup BLE_GAP_PERIPH_PAIRING_KS_TOO_SMALL_MSC GAP Failed Pairing: Keysize too small
- * This occurs if the max key size offered by the peer is below the min key size specified by
- * the app.
- * @msc
- * hscale = "2";
- * APP,SD,CENTRAL;
- * |||;
- * APP rbox CENTRAL [label="Connection Established"];
- * |||;
- * SD<:CENTRAL [label = "SMP Pairing Request", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_SEC_PARAMS_REQUEST"];
- * APP=>SD [label = "sd_ble_gap_sec_params_reply(SUCCESS)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>CENTRAL [label = "SMP Pairing Response", textcolor="#000080", linecolor="#000080"];
- * SD<:CENTRAL [label = "SMP Pairing Confirm", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_AUTH_STATUS {auth_status: Enc key size, error_src: local}"];
- * SD:>CENTRAL [label = "SMP Pairing failed", textcolor="#000080", linecolor="#000080"];
- * @endmsc
- *
- * @defgroup BLE_GAP_PERIPH_PAIRING_APP_ERROR_MSC GAP Failed Pairing: Pairing aborted by the application
- * When the application detects that the pairing should not be performed, for example an
- * insufficient IO combination, it can use sd_ble_gap_sec_params_reply() to send
- * SMP Pairing failed to the peer.
- *
- * When the stack handles the response from the application it will also validate 
- * the passkey (SMP_STC_PASSKEY_ENTRY_FAILED). If any error is detected it will be
- * reported when sd_ble_gap_sec_params_reply() is called. 
- * @msc
- * hscale = "2";
- * APP,SD,CENTRAL;
- * |||;
- * APP rbox CENTRAL [label="Connection Established"];
- * |||;
- * SD<:CENTRAL [label = "SMP Pairing Request", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_SEC_PARAMS_REQUEST"];
- * SD abox APP [label="Stack looks for errors", textbgcolor="#7f7fff"];
- * APP=>SD [label = "sd_ble_gap_sec_params_reply(<code from application>)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>CENTRAL [label = "SMP Pairing failed", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_AUTH_STATUS {auth_status: <code from application>, error_src: local}"];
- * @endmsc
- *
- * @defgroup BLE_GAP_PERIPH_PAIRING_CONFIRM_FAIL_MSC GAP Failed Pairing: Confirm failed
- * This occurs if the random value doesn't match, usually because the user entered a wrong pin
- * or out of band data was missing.
- * @msc
- * hscale = "2";
- * APP,SD,CENTRAL;
- * |||;
- * APP rbox CENTRAL [label="Connection Established"];
- * |||;
- * SD<:CENTRAL [label = "SMP Pairing Request", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_SEC_PARAMS_REQUEST {central_params: mitm, display}"];
- * APP=>SD [label = "sd_ble_gap_sec_params_reply(SUCCESS, periph_params: mitm, keyboard)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>CENTRAL [label = "SMP Pairing Response", textcolor="#000080", linecolor="#000080"];
- * SD<:CENTRAL [label = "SMP Pairing Confirm", textcolor="#000080", linecolor="#000080"];
- * SD:>CENTRAL [label = "SMP Pairing Confirm", textcolor="#000080", linecolor="#000080"];
- * SD<:CENTRAL [label = "SMP Pairing Random", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_AUTH_STATUS {auth_status: Confirm value, error_src: local}"];
- * SD:>CENTRAL [label = "SMP Pairing failed", textcolor="#000080", linecolor="#000080"];
- * @endmsc
- *
- * @defgroup BLE_GAP_PERIPH_PAIRING_REMOTE_PAIRING_FAIL_MSC GAP Failed Pairing: Pairing failed from master
- * SMP Pairing Failed may be sent from the master at various times. The application should
- * prepare for this and gracefully handle the event.
- * @msc
- * hscale = "2";
- * APP,SD,CENTRAL;
- * |||;
- * APP rbox CENTRAL [label="Connection Established"];
- * |||;
- * SD<:CENTRAL [label = "SMP Pairing Request", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_SEC_PARAMS_REQUEST"];
- * APP=>SD [label = "sd_ble_gap_sec_params_reply(SUCCESS)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>CENTRAL [label = "SMP Pairing Response", textcolor="#000080", linecolor="#000080"];
- * SD<:CENTRAL [label = "SMP Pairing Failed", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_AUTH_STATUS {auth_status: <remote_reason>, error_src: remote}"];
- * @endmsc
- *
- * @defgroup BLE_GAP_PERIPH_PAIRING_TIMEOUT_MSC GAP Failed Pairing: Timeout
- * This occurs if the central device doesn't continue the pairing sequence within 30 seconds.
- * @msc
- * hscale = "2";
- * APP,SD,CENTRAL;
- * |||;
- * APP rbox CENTRAL [label="Connection Established"];
- * |||;
- * SD<:CENTRAL [label = "SMP Pairing Request", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_SEC_PARAMS_REQUEST"];
- * APP=>SD [label = "sd_ble_gap_sec_params_reply(SUCCESS)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>CENTRAL [label = "SMP Pairing Response", textcolor="#000080", linecolor="#000080"];
- * ---  [ label = "Wait 30 sec" ];
- * APP<<=SD [label = "BLE_GAP_EVT_AUTH_STATUS {auth_status: Timeout, error_src: local}"];
-
- * @endmsc
- *
- * @defgroup BLE_GAP_PERIPH_SECURITY_TIMEOUT_MSC GAP Authenticate request: Timeout
- * This occurs if the central device doesn't continue the pairing sequence after
- * the security procedure timeout.
- * @msc
- * hscale = "2";
- * APP,SD,CENTRAL;
- * |||;
- * APP rbox CENTRAL [label="Connection Established"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_authenticate(..., ble_gap_sec_params_t*)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>CENTRAL [label = "Security Request", textcolor="#000080", linecolor="#000080"];
-  ---  [ label = "After req_timeout (in ble_gap_sec_params_t)" ];
- * APP<<=SD [label = "BLE_GAP_EVT_TIMEOUT {error_src: BLE_GAP_TIMEOUT_SRC_SECURITY_REQUEST}"];
- * @endmsc
- *
- *
- *
- *
- *
- * @defgroup BLE_GAP_SCAN_MSC GAP Scanning
- * @msc
- * hscale = "1.5";
- * APP,SD,ADVERTISERS;
- * |||;
- * APP=>SD [label = "sd_ble_gap_scan_start(params)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * SD<-ADVERTISERS [label = "ADV packet", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_ADV_REPORT {bdaddr, rssi, data}"];
- * SD<-ADVERTISERS [label = "ADV packet", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_ADV_REPORT {bdaddr, rssi, data}"];
- * SD<-ADVERTISERS [label = "ADV packet", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_ADV_REPORT {bdaddr, rssi, data}"];
- * ...;
- * SD<-ADVERTISERS [label = "ADV packet", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_ADV_REPORT {bdaddr, rssi, data}"];
- * |||;
- * --- [label = " Variant #1 App Stops Scanning "];
- * APP=>SD [label = "sd_ble_gap_scan_stop()"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * --- [label = " Variant #2 Scanning Timeout "];
- * |||;
- * APP<<=SD [label = "BLE_GAP_EVT_TIMEOUT {BLE_GAP_TIMEOUT_SRC_SCAN}"];
- * @endmsc
- *
- * @defgroup BLE_GAP_CENTRAL_CONN_MSC GAP Central Connection Establishment and Termination
- * @msc
- * hscale = "1.5";
- * APP,SD,PERIPHERAL;
- * |||;
- * PERIPHERAL rbox PERIPHERAL [label="Peripheral Start Connectable Advertising"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_connect(params)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PERIPHERAL [label = "Scanning", textcolor="#000080", linecolor="#000080"];
- * |||;
- * --- [label = " Variant #1 Connection Established "];
- * SD<:>PERIPHERAL [label = "Connection Establishment", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONNECTED"];
- * |||;
- * --- [label = " Variant #2 Connection Establishment Cancelled "];
- * APP=>SD [label = "sd_ble_gap_connect_cancel()"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * --- [label = " Variant #3 Connection Timeout "];
- * |||;
- * APP<<=SD [label = "BLE_GAP_EVT_TIMEOUT {BLE_GAP_TIMEOUT_SRC_CONN}"];
- * @endmsc
- *
- * @defgroup BLE_GAP_CENTRAL_CPU_MSC GAP Central Connection Parameter Update
- * @msc
- * hscale = "1.5";
- * APP,SD,PERIPHERAL;
- * |||;
- * APP rbox PERIPHERAL [label="Connection Established with conn. params. CP#1"];
- * |||;
- * --- [label = " Unsolicited procedure"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_conn_param_update(CP#2)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * SD:>PERIPHERAL [label = "Connection Update Start", textcolor="#000080", linecolor="#000080"];
- * SD<:PERIPHERAL [label = "Connection Update Complete", textcolor="#000080", linecolor="#000080"];
- * |||;
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_PARAM_UPDATE {CP#2}"];
- * |||;
- * --- [label = " Peripheral Solicited procedure"];
- * |||;
- * SD<:PERIPHERAL [label = "L2CAP CPU Request {CP#3}", textcolor="#000080", linecolor="#000080"];
- * |||;
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST {CP#3}"];
- * |||;
- * --- [label = " Variant #1 App Accepts "];
- * APP=>SD [label = "sd_ble_gap_conn_param_update(CP#3)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PERIPHERAL [label = "L2CAP CPU Response: Accepted", textcolor="#000080", linecolor="#000080"];
- * SD:>PERIPHERAL [label = "Connection Update Start", textcolor="#000080", linecolor="#000080"];
- * SD<:PERIPHERAL [label = "Connection Update Complete", textcolor="#000080", linecolor="#000080"];
- * |||;
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_PARAM_UPDATE {CP#3}"];
- * |||;
- * --- [label = " Variant #2 App Rejects "];
- * |||;
- * APP=>SD [label = "sd_ble_gap_conn_param_update(NULL)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PERIPHERAL [label = "L2CAP CPU Response: Rejected", textcolor="#000080", linecolor="#000080"];
- * |||;
- * @endmsc
- *
- * @defgroup BLE_GAP_CENTRAL_ENC_MSC GAP Central Encryption Establishment using stored keys
- * @msc
- * hscale = "1.5";
- * APP,SD,PERIPHERAL;
- * |||;
- * APP rbox PERIPHERAL [label="Connection Established"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_encrypt(ediv, rand, LTK)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * SD:>PERIPHERAL [label = "LL Encryption Request", textcolor="#000080", linecolor="#000080"];
- * |||;
- * --- [label = " Variant #1 Peripheral replies with keys "];
- * |||;
- * PERIPHERAL rbox PERIPHERAL [label = "Peripheral Loads Keys"];
- * SD<:PERIPHERAL [label = "LL Encryption Response", textcolor="#000080", linecolor="#000080"];
- * APP rbox PERIPHERAL [label = "Encrypted with LTK"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_SEC_UPDATE"];
- * |||;
- * --- [label = " Variant #2 Peripheral keys missing "];
- * |||;
- * PERIPHERAL rbox PERIPHERAL [label = "Peripheral Keys Missing"];
- * SD<:PERIPHERAL [label = "LL Reject Ind: Pin or Key Missing", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_SEC_UPDATE"];
- * APP rbox PERIPHERAL [label = "Link is NOT encrypted"];
- * |||;
- * --- [label = " Variant #3 Incorrect peripheral keys "];
- * |||;
- * PERIPHERAL rbox PERIPHERAL [label = "Peripheral Loads Incorrect Keys"];
- * SD<:PERIPHERAL [label = "LL Encryption Response", textcolor="#000080", linecolor="#000080"];
- * SD:>PERIPHERAL [label = "Connection Termination", textcolor="#000080", linecolor="#000080"];
- * APP rbox PERIPHERAL [label = "Link Terminated"];
- * APP<<=SD [label = "BLE_GAP_EVT_DISCONNECTED {Connection Timeout}"];
- * |||;
- * @endmsc
- *
- * @defgroup BLE_GAP_CENTRAL_PAIRING_JW_MSC GAP Central Pairing: Just Works
- * @msc
- * hscale = "2";
- * APP,SD,PERIPHERAL;
- * |||;
- * APP rbox PERIPHERAL [label="Connection Established"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_authenticate(no_bond, no_mitm, no_io_caps)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PERIPHERAL [label = "SMP Pairing Request {no_bond, no mitm, no_io_caps}", textcolor="#000080", linecolor="#000080"];
- * |||;
- * SD<:PERIPHERAL [label = "SMP Pairing Response {no_bond, no mitm, no_io_caps}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_SEC_PARAMS_REQUEST {periph_params: no_bond, no_mitm, no_io_caps}"];
- * |||;
- * --- [label = " Variant #1 Central Accepts Peripheral parameters "];
- * |||;
- * APP=>SD [label = "sd_ble_gap_sec_params_reply(SUCCESS, central_params: NULL, NULL)"];
- * |||;
- * SD abox PERIPHERAL [label="SMP Pairing Phase 2", textbgcolor="#7f7fff"];
- * |||;
- * APP rbox PERIPHERAL [label = "Encrypted with STK"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_SEC_UPDATE {ENC_NO_MITM}"];
- * APP<<=SD [label = "BLE_GAP_EVT_AUTH_STATUS {SUCCESS}"];
- * |||;
- * --- [label = " Variant #2 Central Rejects Peripheral parameters "];
- * |||;
- * APP=>SD [label = "sd_ble_gap_sec_params_reply(BLE_GAP_SEC_STATUS_INVALID_PARAMS, central_params: NULL, NULL)"];
- * |||;
- * SD:>PERIPHERAL [label = "SMP Pairing Failed", textcolor="#000080", linecolor="#000080"];
- * |||;
- * APP<<=SD [label = "BLE_GAP_EVT_AUTH_STATUS {FAILURE}"];
- * @endmsc
- *
- * @defgroup BLE_GAP_CENTRAL_BONDING_JW_MSC GAP Central Bonding: Just Works
- * @msc
- * hscale = "2";
- * APP,SD,PERIPHERAL;
- * |||;
- * APP rbox PERIPHERAL [label="Connection Established"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_authenticate(bond, no_mitm, no_io_caps)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PERIPHERAL [label = "SMP Pairing Request {bond, no mitm, no_io_caps}", textcolor="#000080", linecolor="#000080"];
- * |||;
- * SD<:PERIPHERAL [label = "SMP Pairing Response {bond, no mitm, no_io_caps}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_SEC_PARAMS_REQUEST {periph_params: bond, no_mitm, no_io_caps}"];
- * APP=>SD [label = "sd_ble_gap_sec_params_reply(SUCCESS, central_params: NULL, p_keyset)"];
- * |||;
- * SD abox PERIPHERAL [label="SMP Pairing Phase 2", textbgcolor="#7f7fff"];
- * |||;
- * APP rbox PERIPHERAL [label = "Encrypted with STK"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_SEC_UPDATE {ENC_NO_MITM}"];
- * |||;
- * SD abox PERIPHERAL [label="SMP Pairing Phase 3", textbgcolor="#7f7fff"];
- * |||;
- * APP<<=SD [label = "BLE_GAP_EVT_AUTH_STATUS {SUCCESS}"];
- * APP rbox APP [label = "Keys stored in keyset"];
- * @endmsc
- *
- * @defgroup BLE_GAP_CENTRAL_BONDING_PK_PERIPH_MSC GAP Central Bonding: Passkey Entry, Central displays
- * @msc
- * hscale = "2";
- * APP,SD,PERIPHERAL;
- * |||;
- * APP rbox PERIPHERAL [label="Connection Established"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_authenticate(bond, mitm, display)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PERIPHERAL [label = "SMP Pairing Request {bond, mitm, display}", textcolor="#000080", linecolor="#000080"];
- * |||;
- * SD<:PERIPHERAL [label = "SMP Pairing Response {bond, mitm, keyboard}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_SEC_PARAMS_REQUEST {periph_params: bond, mitm, keyboard}"];
- * APP=>SD [label = "sd_ble_gap_sec_params_reply(SUCCESS, central_params: NULL, p_keyset)"];
- * |||;
- * APP<<=SD [label = "BLE_GAP_EVT_PASSKEY_DISPLAY {passkey}"];
- * APP rbox APP [label="Passkey displayed to the user"];
- * |||;
- * SD abox PERIPHERAL [label="SMP Pairing Phase 2", textbgcolor="#7f7fff"];
- * |||;
- * APP rbox PERIPHERAL [label = "Encrypted with STK"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_SEC_UPDATE {ENC_MITM}"];
- * |||;
- * SD abox PERIPHERAL [label="SMP Pairing Phase 3", textbgcolor="#7f7fff"];
- * |||;
- * APP<<=SD [label = "BLE_GAP_EVT_AUTH_STATUS {SUCCESS}"];
- * APP rbox APP [label = "Keys stored in keyset"];
- * @endmsc
- *
- * @defgroup BLE_GAP_CENTRAL_BONDING_PK_PERIPHERAL_OOB_MSC GAP Central Bonding: Passkey Entry (Peripheral display) or OOB MSC
- * @msc
- * hscale = "2";
- * APP,SD,PERIPHERAL;
- * |||;
- * APP rbox PERIPHERAL [label="Connection Established"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_authenticate(bond, mitm, keyboard)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PERIPHERAL [label = "SMP Pairing Request {bond, mitm, keyboard}", textcolor="#000080", linecolor="#000080"];
- * |||;
- * SD<:PERIPHERAL [label = "SMP Pairing Response {bond, mitm, display}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_SEC_PARAMS_REQUEST {periph_params: bond, mitm, display}"];
- * APP=>SD [label = "sd_ble_gap_sec_params_reply(SUCCESS, central_params: NULL, p_keyset)"];
- * |||;
- * APP<<=SD [label = "BLE_GAP_EVT_AUTH_KEY_REQUEST {type}"];
- * APP rbox APP [label="User enters Passkey or data received Out Of Band"];
- * APP=>SD [label = "sd_ble_gap_auth_key_reply(passkey or OOB)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * SD abox PERIPHERAL [label="SMP Pairing Phase 2", textbgcolor="#7f7fff"];
- * |||;
- * APP rbox PERIPHERAL [label = "Encrypted with STK"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_SEC_UPDATE {ENC_MITM}"];
- * |||;
- * SD abox PERIPHERAL [label="SMP Pairing Phase 3", textbgcolor="#7f7fff"];
- * |||;
- * APP<<=SD [label = "BLE_GAP_EVT_AUTH_STATUS {SUCCESS}"];
- * APP rbox APP [label = "Keys stored in keyset"];
- * @endmsc
- *
- * @defgroup BLE_GAP_CENTRAL_SEC_REQ_MSC GAP Central Security Request Reception
- * @msc
- * hscale = "1.5";
- * APP,SD,PERIPHERAL;
- * |||;
- * APP rbox PERIPHERAL [label="Connection Established"];
- * |||;
- * SD<:PERIPHERAL [label = "SMP Security Request", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_SEC_REQUEST {bond, mitm}"];
- * |||;
- * --- [label = " Variant #1 Central initiates Security Establishment "];
- * |||;
- * APP=>SD [label = "sd_ble_gap_encrypt(ediv, rand, LTK)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * APP rbox PERIPHERAL [label = "Encrypted with LTK"];
- * |||;
- * --- [label = " Variant #2 Central Triggers pairing or bonding "];
- * |||;
- * APP=>SD [label = "sd_ble_gap_authenticate(params)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * APP rbox PERIPHERAL [label = "Pairing procedure"];
- * |||;
- * --- [label = " Variant #3 Central rejects the Securiy Request "];
- * |||;
- * APP=>SD [label = "sd_ble_gap_authenticate(NULL)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * SD:>PERIPHERAL [label = "SMP Pairing Failed: Pairing Not Supported", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_AUTH_STATUS {auth_status: Pairing Not Supp, error_src: local}"];
- * |||;
- * @endmsc
- *
- * @defgroup BLE_GAP_INVALID_SMP_PDU_MSC GAP Unexpected Security Packet Reception
- * @msc
- * hscale = "1.5";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * APP rbox PEER [label="No pairing in progress"];
- * |||;
- * PEER rbox PEER [label="Peer misbehaving"];
- * |||;
- * SD<:PEER [label = "SMP Pairing Failed (or other unexpected SMP PDU)", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_AUTH_STATUS {PDU_INVALID}"];
- * |||;
- * @endmsc
-
- * @defgroup BLE_GAP_CENTRAL_ENC_AUTH_MUTEX GAP Central Encryption and Authentication mutual exclusion
- * @msc
- * hscale = "1.5";
- * APP,SD,PEER;
- * |||;
- * APP=>SD [label = "sd_ble_gap_encrypt(ediv, rand, LTK)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * SD:>PEER [label = "Encryption Start", textcolor="#000080", linecolor="#000080"];
- * |||;
- * APP note SD [label = " Encryption in progress, authentication disallowed"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_authenticate()"];
- * APP<<SD [label = "NRF_ERROR_INVALID_STATE"];
- * |||;
- * SD<:PEER [label = "Encryption Complete", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_SEC_UPDATE "];
- * |||;
- * APP=>SD [label = "sd_ble_gap_conn_param_update()"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * SD:>PEER [label = "Connection Update Start", textcolor="#000080", linecolor="#000080"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_encrypt(ediv, rand, LTK)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * SD rbox SD [label="Encryption queued"];
- * |||;
- * APP note SD [label = " Encryption queued, authentication disallowed"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_authenticate()"];
- * APP<<SD [label = "NRF_ERROR_INVALID_STATE"];
- * |||;
- * SD<:PEER [label = "Connection Update Complete", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_PARAM_UPDATE"];
- * |||;
- * SD:>PEER [label = "Encryption Start", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "Encryption Complete", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_SEC_UPDATE "];
- * |||;
- * APP=>SD [label = "sd_ble_gap_authenticate()"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * APP note SD [label = " Authentication in progress, encryption disallowed"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_encrypt(ediv, rand, LTK)"];
- * APP<<SD [label = "NRF_ERROR_INVALID_STATE"];
- * @endmsc
-
- * @defgroup BLE_GAP_MULTILINK_CPU_MSC GAP Central Connection Parameter Update on multiple links
- * @msc
- * hscale = "1.5";
- * APP,SD,PERIPHERALS;
- * |||;
- * APP rbox PERIPHERALS [label="Connection Established with 4 peers, all with conn. params. CP#0"];
- * |||;
- * APP note PERIPHERALS [label = " Peripheral solicited procedure on link #2"];
- * |||;
- * SD<:PERIPHERALS [label = "L2CAP CPU Request {CP#2}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST {conn_handle_2, CP#3}"];
- * |||;
- * APP note PERIPHERALS [label = " Unsolicited procedure on links #3 and #1"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_conn_param_update(conn_handle_3, CP#3)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * SD:>PERIPHERALS [label = "Connection Update Start on link #3", textcolor="#000080", linecolor="#000080"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_conn_param_update(conn_handle_1, CP#1)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * APP note PERIPHERALS [label = " Respond to solicited procedure on link #2"];
- * APP=>SD [label = "sd_ble_gap_conn_param_update(conn_handle_2, CP#2)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PERIPHERALS [label = "L2CAP CPU Response: Accepted", textcolor="#000080", linecolor="#000080"];
- * |||;
- * APP note PERIPHERALS [label = " Additional procedure on link #2 fails, since another one is pending"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_conn_param_update(conn_handle_2, CP#5)"];
- * APP<<SD [label = "NRF_ERROR_BUSY"];
- * |||;
- * APP note PERIPHERALS [label = " Note: the order of execution is not guaranteed"];
- * |||;
- * SD<:PERIPHERALS [label = "Connection Update Complete on link #3", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_PARAM_UPDATE {conn_handle_3, CP#3}"];
- * |||;
- * SD:>PERIPHERALS [label = "Connection Update Start on link #1", textcolor="#000080", linecolor="#000080"];
- * SD<:PERIPHERALS [label = "Connection Update Complete on link #1", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_PARAM_UPDATE {conn_handle_1, CP#1}"];
- * |||;
- * SD:>PERIPHERALS [label = "Connection Update Start on link #2", textcolor="#000080", linecolor="#000080"];
- * |||;
- * APP note PERIPHERALS [label = " Peripheral solicited procedure on link #4"];
- * |||;
- * SD<:PERIPHERALS [label = "L2CAP CPU Request {CP#4}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST {conn_handle_4, CP#4}"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_conn_param_update(conn_handle_4, CP#4)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PERIPHERALS [label = "L2CAP CPU Response: Accepted", textcolor="#000080", linecolor="#000080"];
- * |||;
- * SD<:PERIPHERALS [label = "Connection Update Complete on link #2", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_PARAM_UPDATE {conn_handle_2, CP#2}"];
- * |||;
- * SD:>PERIPHERALS [label = "Connection Update Start on link #4", textcolor="#000080", linecolor="#000080"];
- * SD<:PERIPHERALS [label = "Connection Update Complete on link #4", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_PARAM_UPDATE {conn_handle_4, CP#4}"];
- * |||;
- * @endmsc
-
- * @defgroup BLE_GAP_MULTILINK_CTRL_PROC_MSC GAP Central Control Procedure Serialization on multiple links
- * @msc
- * hscale = "1.5";
- * APP,SD,PERIPHERALS;
- * |||;
- * APP rbox PERIPHERALS [label="Connection Established with 4 peers, all with conn. params. CP#0"];
- * |||;
- * APP note PERIPHERALS [label = " Peripheral solicited procedure on link #2"];
- * |||;
- * SD<:PERIPHERALS [label = "L2CAP CPU Request {CP#2}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST {conn_handle_2, CP#3}"];
- * |||;
- * APP note PERIPHERALS [label = " Encryption procedure on link #3"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_encrypt(conn_handle_3, LTK#3)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * SD:>PERIPHERALS [label = "Encryption Start on link #3", textcolor="#000080", linecolor="#000080"];
- * |||;
- * APP note PERIPHERALS [label = " Connection Update procedure on link #1"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_conn_param_update(conn_handle_1, CP#1)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * APP note PERIPHERALS [label = " Respond to solicited procedure on link #2"];
- * APP=>SD [label = "sd_ble_gap_conn_param_update(conn_handle_2, CP#2)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PERIPHERALS [label = "L2CAP CPU Response: Accepted", textcolor="#000080", linecolor="#000080"];
- * |||;
- * APP note PERIPHERALS [label = " Encryption procedure on link #4"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_encrypt(conn_handle_4, LTK#4)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * APP note PERIPHERALS [label = " Note: the order of execution is not guaranteed, but encryption always has priority"];
- * |||;
- * SD<:PERIPHERALS [label = "Encryption Complete on link #3", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_SEC_UPDATE {conn_handle_3}"];
- * |||;
- * SD:>PERIPHERALS [label = "Encryption Start on link #4", textcolor="#000080", linecolor="#000080"];
- * SD<:PERIPHERALS [label = "Encryption Complete on link #4", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_SEC_UPDATE {conn_handle_4}"];
- * |||;
- * SD:>PERIPHERALS [label = "Connection Update Start on link #1", textcolor="#000080", linecolor="#000080"];
- * SD<:PERIPHERALS [label = "Connection Update Complete on link #1", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_PARAM_UPDATE {conn_handle_1, CP#1}"];
- * |||;
- * SD:>PERIPHERALS [label = "Connection Update Start on link #2", textcolor="#000080", linecolor="#000080"];
- * SD<:PERIPHERALS [label = "Connection Update Complete on link #2", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GAP_EVT_CONN_PARAM_UPDATE {conn_handle_2, CP#2}"];
- * |||;
- * @endmsc
- *
- * @defgroup BLE_GAP_WL_SHARE_MSC GAP Whitelist Sharing
- * @msc
- * hscale = "1.5";
- * APP,SD;
- * |||;
- * APP=>SD [label = "sd_ble_gap_adv_data_set(adv, sr)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * APP=>SD [label = "sd_ble_gap_adv_start(fp = CONNREQ, WL#1)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * SD rbox SD [label="Advertising with Whitelist #1"];
- * |||;
- * APP note APP [label = "Unable to change whitelist while adv in progress"];
- * APP=>SD [label = "sd_ble_gap_scan_start(selective = 1, WL#2)"];
- * APP<<SD [label = "BLE_ERROR_GAP_WHITELIST_IN_USE"];
- * |||;
- * APP note APP [label = "Scan with the current active whitelist"];
- * APP=>SD [label = "sd_ble_gap_scan_start(selective = 1, NULL)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * SD rbox SD [label="Advertising and scanning with Whitelist #1"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_adv_stop()"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * SD rbox SD [label="Scanning with Whitelist #1"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_scan_stop()"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * APP=>SD [label = "sd_ble_gap_scan_start(selective = 1, WL#2)"];
- * APP<<SD [label = "BLE_ERROR_GAP_WHITELIST_IN_USE"];
- * |||;
- * SD rbox SD [label="Scanning with Whitelist #2"];
- * |||;
- * APP note APP [label = "Connect with the current active whitelist"];
- * APP=>SD [label = "sd_ble_gap_connect(selective = 1, NULL)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * SD note SD [label = "Scanning is automatically stopped"];
- * SD rbox SD [label="Connecting with Whitelist #2"];
- * |||;
- * @endmsc
-
- * @}
- * @}
- */
-
-/**
- * @addtogroup BLE_GATTC 
- * @{
- * @defgroup BLE_GATTC_MSC Message Sequence Charts
- * @{
- * @defgroup BLE_GATTC_PRIM_SRVC_DISC_MSC GATTC Primary Service Discovery
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * --- [label = " Variant #1 Discover All Services "];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_primary_services_discover(handle, NULL)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Read By Group Type Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Read By Group Type Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP {SUCCESS, services}"];
- * APP=>SD [label = "sd_ble_gattc_primary_services_discover(handle + N, NULL)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Read By Group Type Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Read By Group Type Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP {SUCCESS, services}"];
- * APP=>SD [label = "sd_ble_gattc_primary_services_discover(handle + N + M, NULL)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Read By Group Type Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Error Response: Attribute Not Found", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP {ATTRIBUTE_NOT_FOUND}"];
- * |||;
- * --- [label = " Variant #2 Discover a Specific Service "];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_primary_services_discover(handle, uuid)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Find By Type Value Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Find By Type Value Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP {SUCCESS, services}"];
- * APP=>SD [label = "sd_ble_gattc_primary_services_discover(handle + N, uuid)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Find By Type Value Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Find By Type Value Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP {SUCCESS, services}"];
- * APP=>SD [label = "sd_ble_gattc_primary_services_discover(handle + N + M, uuid)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Find By Type Value Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Error Response: Attribute Not Found", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP {ATTRIBUTE_NOT_FOUND}"];
- * @endmsc
- *
- * @defgroup BLE_GATTC_REL_DISC_MSC GATTC Relationship Discovery
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_relationships_discover(handle_range)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Read By Type Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Read By Type Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_REL_DISC_RSP {SUCCESS, includes}"];
- * APP=>SD [label = "sd_ble_gattc_relationships_discover(handle_range + N)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Read By Type Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Read By Type Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_REL_DISC_RSP {SUCCESS, includes}"];
- * APP=>SD [label = "sd_ble_gattc_relationships_discover(handle_range + N + M)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Read By Type Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Error Response: Attribute Not Found", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_REL_DISC_RSP {ATTRIBUTE_NOT_FOUND}"];
- * @endmsc
- *
- * @defgroup BLE_GATTC_CHAR_DISC_MSC GATTC Characteristic Discovery
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_characteristics_discover(handle_range)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Read By Type Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Read By Type Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_CHAR_DISC_RSP {SUCCESS, chars}"];
- * APP=>SD [label = "sd_ble_gattc_characteristics_discover(handle_range + N)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Read By Type Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Read By Type Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_CHAR_DISC_RSP {SUCCESS, chars}"];
- * APP=>SD [label = "sd_ble_gattc_characteristics_discover(handle_range + N + M)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Read By Type Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Error Response: Attribute Not Found", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_CHAR_DISC_RSP {ATTRIBUTE_NOT_FOUND}"];
- * @endmsc
- *
- * @defgroup BLE_GATTC_DESC_DISC_MSC GATTC Descriptor Discovery
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_descriptors_discover(handle_range)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Find Information Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Find Information Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_DESC_DISC_RSP {SUCCESS, descs}"];
- * APP=>SD [label = "sd_ble_gattc_descriptors_discover(handle_range + N)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Find Information Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Find Information Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_DESC_DISC_RSP {SUCCESS, descs}"];
- * APP=>SD [label = "sd_ble_gattc_descriptors_discover(handle_range + N + M)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Find Information Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Error Response: Attribute Not Found", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_DESC_DISC_RSP {ATTRIBUTE_NOT_FOUND}"];
- * @endmsc
- *
- * @defgroup BLE_GATTC_READ_UUID_MSC GATTC Read Characteristic Value by UUID
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_char_value_by_uuid_read(uuid, handle_range)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Read By Type Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Read By Type Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP {SUCCESS, char_values}"];
- * APP=>SD [label = "sd_ble_gattc_char_value_by_uuid_read(uuid, handle_range + N)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Read By Type Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Read By Type Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP {SUCCESS, char_values}"];
- * APP=>SD [label = "sd_ble_gattc_char_value_by_uuid_read(uuid, handle_range + N + M)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Read By Type Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Error Response: Attribute Not Found", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP {ATTRIBUTE_NOT_FOUND}"];
- * @endmsc
- *
- * @defgroup BLE_GATTC_VALUE_READ_MSC GATTC Characteristic or Descriptor Value Read
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * --- [label = " Variant #1 offset == 0 "];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_read(handle, 0)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Read Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Read Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_READ_RSP {SUCCESS, value}"];
- * |||;
- * --- [label = " Variant #2 offset != 0 "];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_read(handle, offset)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Read Blob Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Read Blob Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_READ_RSP {SUCCESS, value}"];
- * APP=>SD [label = "sd_ble_gattc_read(handle, offset + N)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Read Blob Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Read Blob Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_READ_RSP {SUCCESS, value}"];
- * APP=>SD [label = "sd_ble_gattc_read(handle, offset + N + M + 1)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Read Blob Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Error Response: Invalid Offset", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_READ_RSP {INVALID_OFFSET}"];
- * @endmsc
- *
- * @defgroup BLE_GATTC_READ_MULT_MSC GATTC Read Multiple Characteristic Values
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * --- [label = " Variant #1 Successful request "];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_char_values_read(handles)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Read Multiple Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Read Multiple Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_CHAR_VALS_READ_RSP {SUCCESS, char_values}"];
- * |||;
- * --- [label = " Variant #2 Failing request (invalid handle) "];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_char_values_read(handles)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Read Multiple Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Error Response: Invalid Handle", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_CHAR_VALS_READ_RSP {INVALID_HANDLE, error_handle=<invalid handle>}"];
- * @endmsc
- *
- * @defgroup BLE_GATTC_VALUE_WRITE_MSC GATTC Characteristic or Descriptor Value Write
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * --- [label = " Variant #1 write_op == BLE_GATT_OP_WRITE_CMD "];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_write(BLE_GATT_OP_WRITE_CMD, handle, value)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Write Command", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_EVT_TX_COMPLETE"];
- * |||;
- * --- [label = " Variant #2 write_op == BLE_GATT_OP_WRITE_REQ "];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_write(BLE_GATT_OP_WRITE_REQ, handle, value)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Write Request", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Write Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_WRITE_RSP {BLE_GATT_OP_WRITE_REQ, SUCCESS}"];
- * @endmsc
- * @defgroup BLE_GATTC_VALUE_LONG_WRITE_MSC GATTC Characteristic or Descriptor Value Long Write
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_write(BLE_GATT_OP_PREP_WRITE_REQ, handle, offset_1, value_1)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Prepare Write Request {handle, offset_1, value_1}", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Prepare Write Response {handle, offset_1, value_1}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_WRITE_RSP {BLE_GATT_OP_PREP_WRITE_REQ, SUCCESS, value_1}"];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_write(BLE_GATT_OP_PREP_WRITE_REQ, handle, offset_2, value_2)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Prepare Write Request {handle, offset_2, value_2}", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Prepare Write Response {handle, offset_2, value_2}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_WRITE_RSP {BLE_GATT_OP_PREP_WRITE_REQ, SUCCESS, value_2}"];
- * |||;
- * ...;
- * |||;
- * --- [label = " Variant #1 App executes the Long Write procedure "];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_write(BLE_GATT_OP_EXEC_WRITE_REQ, PREPARED_WRITE)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Execute Write Request: flags = 0x01", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Execute Write Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_WRITE_RSP {BLE_GATT_OP_EXEC_WRITE_REQ, SUCCESS}"];
- * |||;
- * --- [label = " Variant #2 App cancels the Long Write procedure "];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_write(BLE_GATT_OP_EXEC_WRITE_REQ, PREPARED_CANCEL)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Execute Write Request: flags = 0x00", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Execute Write Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_WRITE_RSP {BLE_GATT_OP_EXEC_WRITE_REQ, SUCCESS}"];
- * @endmsc
- * @defgroup BLE_GATTC_VALUE_RELIABLE_WRITE_MSC GATTC Characteristic or Descriptor Value Reliable Write
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_write(BLE_GATT_OP_PREP_WRITE_REQ, handle_1, offset, value_1)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Prepare Write Request {handle_1, offset, value_1}", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Prepare Write Response {handle_1, offset, value_1}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_WRITE_RSP {BLE_GATT_OP_PREP_WRITE_REQ, SUCCESS, value_1}"];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_write(BLE_GATT_OP_PREP_WRITE_REQ, handle_2, offset, value_2)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Prepare Write Request {handle_2, offset, value_2}", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Prepare Write Response {handle_2, offset, value_2}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_WRITE_RSP {BLE_GATT_OP_PREP_WRITE_REQ, SUCCESS, value_2}"];
- * |||;
- * ...;
- * |||;
- * --- [label = " Variant #1 App executes the Reliable Write procedure "];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_write(BLE_GATT_OP_EXEC_WRITE_REQ, PREPARED_WRITE)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Execute Write Request: flags = 0x01", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Execute Write Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_WRITE_RSP {BLE_GATT_OP_EXEC_WRITE_REQ, SUCCESS}"];
- * |||;
- * --- [label = " Variant #2 App cancels the Reliable Write procedure "];
- * |||;
- * APP=>SD [label = "sd_ble_gattc_write(BLE_GATT_OP_EXEC_WRITE_REQ, PREPARED_CANCEL)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Execute Write Request: flags = 0x00", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Execute Write Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_WRITE_RSP {BLE_GATT_OP_EXEC_WRITE_REQ, SUCCESS}"];
- * @endmsc
- *
- * @defgroup BLE_GATTC_HVI_MSC GATTC Handle Value Indication
- * <b> GATTC Handle Value Indication MSC </b>
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * SD<:PEER [label = "ATT Handle Value Indication", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_HVX {INDICATION, data}"];
- * APP=>SD [label = "sd_ble_gattc_hv_confirm(handle)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Handle Value Confirmation", textcolor="#000080", linecolor="#000080"];
- * @endmsc
- *
- * @defgroup BLE_GATTC_HVN_MSC GATTC Handle Value Notification
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * SD<:PEER [label = "ATT Handle Value Notification", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTC_EVT_HVX {NOTIFICATION, data}"];
- * @endmsc
- *
- * @defgroup BLE_GATTC_TIMEOUT_MSC GATTC Timeout
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * APP rbox PEER [label="Any GATTC API used"];
- * SD:>PEER [label = "ATT Packet", textcolor="#000080", linecolor="#000080"];
- * APP note PEER [label = "No Response from Peer"];
- * |||;
- * ...;
- * |||;
- * SD box SD [label="Timeout"];
- * APP<<=SD [label = "BLE_GATTC_EVT_TIMEOUT {source}"];
- * APP rbox PEER [label="No additional ATT Traffic Allowed", textbgcolour="#ff7f7f"];
- * APP=>SD [label = "Any API call"];
- * APP<<SD [label = "NRF_ERROR_BUSY"];
- * @endmsc
- * @}
- * @}
- */
-
-/**
- * @addtogroup BLE_GATTS 
- * @{
- * @defgroup BLE_GATTS_MSC Message Sequence Charts
- * @{
- * @defgroup BLE_GATTS_ATT_TABLE_POP_MSC GATTS ATT Table Population
- * @msc
- * hscale = "1.5";
- * APP,SD;
- * |||;
- * APP=>SD [label = "sd_ble_gatts_service_add(uuid#1)"];
- * APP<<SD [label = "{NRF_SUCCESS, handle_srvc#1}"];
- * APP=>SD [label = "sd_ble_gatts_characteristic_add(handle_srvc#1, char_md, value)"];
- * APP<<SD [label = "{NRF_SUCCESS, handle_char#1, ...}"];
- * APP=>SD [label = "sd_ble_gatts_descriptor_add(handle_char#1, value)"];
- * APP<<SD [label = "{NRF_SUCCESS, handle_desc#1}"];
- * APP=>SD [label = "sd_ble_gatts_descriptor_add(handle_char#1, value)"];
- * APP<<SD [label = "{NRF_SUCCESS, handle_desc#2}"];
- * APP=>SD [label = "sd_ble_gatts_characteristic_add(handle_srvc#1, char_md, value)"];
- * APP<<SD [label = "{NRF_SUCCESS, handle_char#2, ...}"];
- * APP=>SD [label = "sd_ble_gatts_descriptor_add(handle_char#2, value)"];
- * APP<<SD [label = "{NRF_SUCCESS, handle_desc#3}"];
- * APP=>SD [label = "sd_ble_gatts_service_add(uuid#2)"];
- * APP<<SD [label = "{NRF_SUCCESS, handle_srvc#2}"];
- * APP=>SD [label = "sd_ble_gatts_include_add(handle_srvc#2, handle_srvc#1)"];
- * APP<<SD [label = "{NRF_SUCCESS, handle_inc#1}"];
- * |||;
- * ...;
- * |||;
- * @endmsc
- *
- * @defgroup BLE_GATTS_READ_REQ_NO_AUTH_MSC GATTS Read Request without Authorization
- * @msc
- * hscale = "1.5";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * SD<:PEER [label = "ATT Read Request", textcolor="#000080", linecolor="#000080"];
- * SD:>PEER [label = "ATT Read Response", textcolor="#000080", linecolor="#000080"];
- * @endmsc
- *
- * @defgroup BLE_GATTS_WRITE_REQ_NO_AUTH_MSC GATTS Write Request without Authorization
- * @msc
- * hscale = "1.5";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * SD<:PEER [label = "ATT Write Request", textcolor="#000080", linecolor="#000080"];
- * SD:>PEER [label = "ATT Write Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTS_EVT_WRITE {WRITE_REQ, data}"];
- * @endmsc
- *
- * @defgroup BLE_GATTS_WRITE_CMD_NO_AUTH_MSC GATTS Write Command with or without Authorization
- * @msc
- * hscale = "1.5";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * SD<:PEER [label = "ATT Write Command", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTS_EVT_WRITE {WRITE_CMD, data}"];
- * @endmsc
- *
- * @defgroup BLE_GATTS_READ_REQ_AUTH_MSC GATTS Read Request with Authorization
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * SD rbox SD [label="Value in ATT Table: current_value"];
- * SD<:PEER [label = "ATT Read Request", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST {READ, current_value}"];
- * --- [label = " Variant #1 App Authorizes "];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(SUCCESS, app_value)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD rbox SD [label="Value in ATT Table: app_value"];
- * SD:>PEER [label = "ATT Read Response {app_value}", textcolor="#000080", linecolor="#000080"];
- * --- [label = " Variant #2 App Disallows "];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(READ_NOT_PERMITTED)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Error Response", textcolor="#000080", linecolor="#000080"];
- * @endmsc
- *
- * @defgroup BLE_GATTS_WRITE_REQ_AUTH_MSC GATTS Write Request with Authorization
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * SD rbox SD [label="Value in ATT Table: current_value"];
- * SD<:PEER [label = "ATT Write Request {peer_data}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST {WRITE, peer_value}"];
- * --- [label = " Variant #1 App Authorizes "];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(SUCCESS)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD rbox SD [label="Value in ATT Table: peer_data"];
- * SD:>PEER [label = "ATT Write Response", textcolor="#000080", linecolor="#000080"];
- * --- [label = " Variant #2 App Disallows "];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE_NOT_PERMITTED)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Error Response", textcolor="#000080", linecolor="#000080"];
- * SD rbox SD [label="Value in ATT Table: current_value"];
- * @endmsc
- *
- * @defgroup BLE_GATTS_QUEUED_WRITE_BUF_NOAUTH_MSC GATTS Queued Writes: Stack handled, no attributes require authorization
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * SD rbox SD [label="Values in ATT Table:\nhandle_1: current_value_1\nhandle_2: current_value_2"];
- * SD<:PEER [label = "ATT Prepare Write Request {handle_1, offset_1, peer_value_1}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_EVT_USER_MEM_REQUEST {BLE_USER_MEM_TYPE_GATTS_QUEUED_WRITES}"];
- * APP=>SD [label = "sd_ble_user_mem_reply {user_mem_block}"];
- * SD:>PEER [label = "ATT Prepare Write Response {handle_1, offset_1, peer_value_1}", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Prepare Write Request {handle_2, offset_2, peer_value_2}", textcolor="#000080", linecolor="#000080"];
- * SD:>PEER [label = "ATT Prepare Write Response {handle_2, offset_2, peer_value_2}", textcolor="#000080", linecolor="#000080"];
- * |||;
- * --- [label = " Variant #1 Attribute Values validation passed "];
- * SD<:PEER [label = "ATT Execute Write Request {WRITE}", textcolor="#000080", linecolor="#000080"];
- * SD rbox SD [label="Values in ATT Table:\nhandle_1: peer_value_1\nhandle_2: peer_value_2"];
- * APP<<=SD [label = "BLE_GATTS_EVT_WRITE {EXEC_WRITE_REQ_NOW}"];
- * APP rbox APP [label="App parses the memory it provided"];
- * SD:>PEER [label = "ATT Execute Write Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_EVT_USER_MEM_RELEASE {user_mem_block}"];
- * |||;
- * --- [label = " Variant #2 Attribute Values validation failed "];
- * SD<:PEER [label = "ATT Execute Write Request {WRITE}", textcolor="#000080", linecolor="#000080"];
- * SD rbox SD [label="Values in ATT Table:\nhandle_1: current_value_1\nhandle_2: current_value_2"];
- * SD:>PEER [label = "ATT Error Response {Invalid Value Length / Offset}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_EVT_USER_MEM_RELEASE {user_mem_block}"];
- * |||;
- * --- [label = " Variant #3 Peer cancels operation "];
- * SD<:PEER [label = "ATT Execute Write Request {CANCEL}", textcolor="#000080", linecolor="#000080"];
- * SD rbox SD [label="Values in ATT Table:\nhandle_1: current_value_1\nhandle_2: current_value_2"];
- * SD:>PEER [label = "ATT Execute Write Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_EVT_USER_MEM_RELEASE {user_mem_block}"];
- * |||;
- * @endmsc
- *
- * @defgroup BLE_GATTS_QUEUED_WRITE_BUF_AUTH_MSC GATTS Queued Writes: Stack handled, one or more attributes require authorization
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * SD rbox SD [label="Values in ATT Table:\nhandle_1: current_value_1\nhandle_2: current_value_2"];
- * SD<:PEER [label = "ATT Prepare Write Request {handle_1, offset_1, peer_value_1}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_EVT_USER_MEM_REQUEST {BLE_USER_MEM_TYPE_GATTS_QUEUED_WRITES}"];
- * APP=>SD [label = "sd_ble_user_mem_reply {user_mem_block}"];
- * SD:>PEER [label = "ATT Prepare Write Response {handle_1, offset_1, peer_value_1}", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Prepare Write Request {handle_2, offset_2, peer_value_2}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST {WRITE, PREP_WRITE_REQ, handle_2, offset_2, peer_value_2}"];
- * |||;
- * --- [label = " Variant #1 App Authorizes both Prepare Write and Execute Write"];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, SUCCESS)"];
- * SD:>PEER [label = "ATT Prepare Write Response {handle_2, offset_2, peer_value_2}", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Execute Write Request {WRITE}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST {WRITE, EXEC_WRITE_REQ_NOW}"];
- * APP rbox APP [label="App parses the memory it provided"];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, SUCCESS)"];
- * SD rbox SD [label="Values in ATT Table:\nhandle_1: peer_value_1\nhandle_2: peer_value_2"];
- * SD:>PEER [label = "ATT Execute Write Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_EVT_USER_MEM_RELEASE {user_mem_block}"];
- * |||;
- * --- [label = " Variant #2 App Disallows Prepare Write and Authorizes Execute Write "];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, INSUF_AUTHORIZATION)"];
- * SD:>PEER [label = "ATT Error Response {Insufficient Authorization}", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Execute Write Request {WRITE}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST {WRITE, EXEC_WRITE_REQ_NOW}"];
- * APP rbox APP [label="App parses the memory it provided"];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, SUCCESS)"];
- * SD rbox SD [label="Values in ATT Table:\nhandle_1: peer_value_1\nhandle_2: current_value_2"];
- * SD:>PEER [label = "ATT Execute Write Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_EVT_USER_MEM_RELEASE {user_mem_block}"];
- * |||;
- * --- [label = " Variant #3 App Authorizes Prepare Write and Disallows Execute Write "];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, SUCCESS)"];
- * SD:>PEER [label = "ATT Prepare Write Response {handle_2, offset_2, peer_value_2}", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Execute Write Request {WRITE}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST {WRITE, EXEC_WRITE_REQ_NOW}"];
- * APP rbox APP [label="App parses the memory it provided"];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, APP_ERROR_CODE)"];
- * SD rbox SD [label="Values in ATT Table:\nhandle_1: current_value_1\nhandle_2: current_value_2"];
- * SD:>PEER [label = "ATT Error Response {APP_ERROR_CODE}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_EVT_USER_MEM_RELEASE {user_mem_block}"];
- * @endmsc
- *
- * @defgroup BLE_GATTS_QUEUED_WRITE_NOBUF_NOAUTH_MSC GATTS Queued Writes: App handled, no attributes require authorization
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * APP rbox SD [label="Values in ATT Table:\nhandle_1: current_value_1\nhandle_2: current_value_2"];
- * SD<:PEER [label = "ATT Prepare Write Request {handle_1, offset_1, peer_value_1}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_EVT_USER_MEM_REQUEST {BLE_USER_MEM_TYPE_GATTS_QUEUED_WRITES}"];
- * APP=>SD [label = "sd_ble_user_mem_reply {NULL}"];
- * APP<<=SD [label = "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST {WRITE, PREP_WRITE_REQ, handle_1, offset_1, peer_value_1}"];
- * APP rbox APP [label="App queues {handle_1, offset_1, peer_value_1}"];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, SUCCESS)"];
- * SD:>PEER [label = "ATT Prepare Write Response {handle_1, offset_1, peer_value_1}", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Prepare Write Request {handle_2, offset_2, peer_value_2}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST {WRITE, PREP_WRITE_REQ, handle_2, offset_2, peer_value_2}"];
- * APP rbox APP [label="App queues {handle_2, offset_2, peer_value_2}"];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, SUCCESS)"];
- * SD:>PEER [label = "ATT Prepare Write Response {handle_2, offset_2, peer_value_2}", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Execute Write Request {WRITE}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST {WRITE, EXEC_WRITE_REQ_NOW}"];
- * |||;
- * --- [label = " Variant #1 Attribute values in stack memory (VLOC_STACK), attribute values validation passed "];
- * APP=>SD [label = "sd_ble_gatts_value_set {handle_1, offset_1, peer_value_1}"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * APP=>SD [label = "sd_ble_gatts_value_set {handle_2, offset_2, peer_value_2}"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD rbox SD [label="Values in ATT Table:\nhandle_1: peer_value_1\nhandle_2: peer_value_2"];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, SUCCESS)"];
- * SD:>PEER [label = "ATT Execute Write Response", textcolor="#000080", linecolor="#000080"];
- * |||;
- * --- [label = " Variant #2 Attribute values in user memory (VLOC_USER), attribute values validation passed "];
- * APP rbox APP [label="Application traverses its queue and executes the write operations (memcpy)"];
- * APP rbox APP [label="Values in ATT Table:\nhandle_1: peer_value_1\nhandle_2: peer_value_2"];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, SUCCESS)"];
- * SD:>PEER [label = "ATT Execute Write Response", textcolor="#000080", linecolor="#000080"];
- * |||;
- * --- [label = " Variant #3 Attribute values validation failed "];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, INVALID_OFFSET)"];
- * APP rbox SD [label="Values in ATT Table:\nhandle_1: current_value_1\nhandle_2: current_value_2"];
- * SD:>PEER [label = "ATT Error Response {Invalid Offset}", textcolor="#000080", linecolor="#000080"];
- * @endmsc
- *
- * @defgroup BLE_GATTS_QUEUED_WRITE_NOBUF_AUTH_MSC GATTS Queued Writes: App handled, one or more attributes require authorization
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * APP rbox APP [label="Values in ATT Table (in user memory):\nhandle_1: current_value_1\nhandle_2: current_value_2"];
- * SD<:PEER [label = "ATT Prepare Write Request {handle_1, offset_1, peer_value_1}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_EVT_USER_MEM_REQUEST {BLE_USER_MEM_TYPE_GATTS_QUEUED_WRITES}"];
- * APP=>SD [label = "sd_ble_user_mem_reply {NULL}"];
- * APP<<=SD [label = "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST {WRITE, PREP_WRITE_REQ, handle_1, offset_1, peer_value_1}"];
- * APP rbox APP [label="App queues {handle_1, offset_1, peer_value_1}"];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, SUCCESS)"];
- * SD:>PEER [label = "ATT Prepare Write Response {handle_1, offset_1, peer_value_1}", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Prepare Write Request {handle_2, offset_2, peer_value_2}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST {WRITE, PREP_WRITE_REQ, handle_2, offset_2, peer_value_2}"];
- * |||;
- * --- [label = " Variant #1 App Authorizes both Prepare Write and Execute Write"];
- * APP rbox APP [label="App queues {handle_2, offset_2, peer_value_2}"];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, SUCCESS)"];
- * SD:>PEER [label = "ATT Prepare Write Response {handle_2, offset_2, peer_value_2}", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Execute Write Request {WRITE}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST {WRITE, EXEC_WRITE_REQ_NOW}"];
- * APP rbox APP [label="Application traverses its queue and executes the write operations (memcpy)"];
- * APP rbox APP [label="Values in ATT Table:\nhandle_1: peer_value_1\nhandle_2: peer_value_2"];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, SUCCESS)"];
- * SD:>PEER [label = "ATT Execute Write Response", textcolor="#000080", linecolor="#000080"];
- * |||;
- * --- [label = " Variant #2 App Disallows Prepare Write and Authorizes Execute Write "];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, INSUF_AUTHORIZATION)"];
- * SD:>PEER [label = "ATT Error Response {Insufficient Authorization}", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Execute Write Request {WRITE}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST {WRITE, EXEC_WRITE_REQ_NOW}"];
- * APP rbox APP [label="Application traverses its queue and executes the write operations (memcpy)"];
- * APP rbox APP [label="Values in ATT Table:\nhandle_1: peer_value_1\nhandle_2: current_value_2"];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, SUCCESS)"];
- * SD:>PEER [label = "ATT Execute Write Response", textcolor="#000080", linecolor="#000080"];
- * |||;
- * --- [label = " Variant #3 App Authorizes Prepare Write and Disallows Execute Write "];
- * APP rbox APP [label="App queues {handle_2, offset_2, peer_value_2}"];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, SUCCESS)"];
- * SD:>PEER [label = "ATT Prepare Write Response {handle_2, offset_2, peer_value_2}", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Execute Write Request {WRITE}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST {WRITE, EXEC_WRITE_REQ_NOW}"];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, APP_ERROR_CODE)"];
- * APP rbox APP [label="Values in ATT Table:\nhandle_1: current_value_1\nhandle_2: current_value_2"];
- * SD:>PEER [label = "ATT Error Response {APP_ERROR_CODE}", textcolor="#000080", linecolor="#000080"];
- * @endmsc
- *
- * @defgroup BLE_GATTS_QUEUED_WRITE_QUEUE_FULL_MSC GATTS Queued Writes: Prepare Queue Full
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * SD rbox SD [label="Values in ATT Table:\nhandle_1: current_value_1\nhandle_2: current_value_2"];
- * SD<:PEER [label = "ATT Prepare Write Request {handle_1, offset_1, peer_value_1}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_EVT_USER_MEM_REQUEST {BLE_USER_MEM_TYPE_GATTS_QUEUED_WRITES}"];
- * |||;
- * --- [label = " Variant #1 Stack handled "];
- * APP=>SD [label = "sd_ble_user_mem_reply {user_mem_block}"];
- * SD:>PEER [label = "ATT Prepare Write Response {handle_1, offset_1, peer_value_1}", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Prepare Write Request {handle_2, offset_2, peer_value_2}", textcolor="#000080", linecolor="#000080"];
- * SD:>PEER [label = "ATT Error Response {Prepare Queue Full}", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Execute Write Request {WRITE}", textcolor="#000080", linecolor="#000080"];
- * SD rbox SD [label="Values in ATT Table:\nhandle_1: peer_value_1\nhandle_2: current_value_2"];
- * APP<<=SD [label = "BLE_GATTS_EVT_WRITE {EXEC_WRITE_REQ_NOW}"];
- * APP rbox APP [label="App parses the memory it provided"];
- * SD:>PEER [label = "ATT Execute Write Response", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_EVT_USER_MEM_RELEASE {user_mem_block}"];
- * |||;
- * --- [label = " Variant #2 App handled "];
- * APP=>SD [label = "sd_ble_user_mem_reply {NULL}"];
- * APP<<=SD [label = "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST {WRITE, PREP_WRITE_REQ, handle_1, offset_1, peer_value_1}"];
- * APP rbox APP [label="App queues {handle_1, offset_1, peer_value_1}"];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, SUCCESS)"];
- * SD:>PEER [label = "ATT Prepare Write Response {handle_1, offset_1, peer_value_1}", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Prepare Write Request {handle_2, offset_2, peer_value_2}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST {WRITE, PREP_WRITE_REQ, handle_2, offset_2, peer_value_2}"];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, PREPARE_QUEUE_FULL)"];
- * SD:>PEER [label = "ATT Error Response {Prepare Queue Full}", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Execute Write Request {WRITE}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST {WRITE, EXEC_WRITE_REQ_NOW}"];
- * APP=>SD [label = "sd_ble_gatts_value_set {handle_1, offset_1, peer_value_1}"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * APP=>SD [label = "sd_ble_gatts_rw_authorize_reply(WRITE, SUCCESS)"];
- * SD rbox SD [label="Values in ATT Table:\nhandle_1: peer_value_1\nhandle_2: current_value_2"];
- * SD:>PEER [label = "ATT Execute Write Response", textcolor="#000080", linecolor="#000080"];
- * @endmsc
- *
- * @defgroup BLE_GATTS_QUEUED_WRITE_EXECUTE_WITHOUT_PREPARE_MSC GATTS Queued Writes: Execute Write without Prepare Write
- * @msc
- * hscale = "2";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * SD rbox SD [label="Values in ATT Table:\nhandle_1: current_value_1\nhandle_2: current_value_2"];
- * |||;
- * SD rbox SD [label="No ATT Prepare Write Request has been received by SD"];
- * |||;
- * --- [label = " Variant #1 Write cancelled "];
- * SD<:PEER [label = "ATT Execute Write Request {CANCEL}", textcolor="#000080", linecolor="#000080"];
- * SD rbox SD [label="Values in ATT Table:\nhandle_1: current_value_1\nhandle_2: current_value_2"];
- * APP<<=SD [label = "BLE_GATTS_EVT_WRITE {EXEC_WRITE_REQ_CANCEL}"];
- * SD:>PEER [label = "ATT Execute Write Response", textcolor="#000080", linecolor="#000080"];
- * |||;
- * --- [label = " Variant #2 Write now "];
- * SD<:PEER [label = "ATT Execute Write Request {WRITE}", textcolor="#000080", linecolor="#000080"];
- * SD rbox SD [label="Values in ATT Table:\nhandle_1: current_value_1\nhandle_2: current_value_2"];
- * APP<<=SD [label = "BLE_GATTS_EVT_WRITE {EXEC_WRITE_REQ_NOW}"];
- * SD:>PEER [label = "ATT Execute Write Response", textcolor="#000080", linecolor="#000080"];
- * @endmsc
- *
- * @defgroup BLE_GATTS_HVI_MSC GATTS Handle Value Indication
- * @msc
- * hscale = "1.5";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * APP rbox PEER [label="Indications Enabled in CCCD"];
- * |||;
- * SD rbox SD [label="Value in ATT Table: current_value"];
- * APP=>SD [label = "sd_ble_gatts_hvx(INDICATION, app_value)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD rbox SD [label="Value in ATT Table: app_value"];
- * SD:>PEER [label = "ATT Handle Value Indication {app_value}", textcolor="#000080", linecolor="#000080"];
- * --- [label = " Variant #1 Peer Confirms "];
- * SD<:PEER [label = "ATT Handle Value Confirmation", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTS_EVT_HVC"];
- * --- [label = " Variant #2 Peer Ignores "];
- * |||;
- * ...;
- * |||;
- * SD box SD [label="Timeout"];
- * APP<<=SD [label = "BLE_GATTS_EVT_TIMEOUT"];
- * @endmsc
- *
- * @defgroup BLE_GATTS_HVN_MSC GATTS Handle Value Notification
- * @msc
- * hscale = "1.5";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * APP rbox PEER [label="Notifications Enabled in CCCD"];
- * |||;
- * SD rbox SD [label="Value in ATT Table: current_value"];
- * APP=>SD [label = "sd_ble_gatts_hvx(NOTIFICATION, app_value)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD rbox SD [label="Value in ATT Table: app_value"];
- * SD:>PEER [label = "ATT Handle Value Notification {app_value}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_EVT_TX_COMPLETE"];
- * @endmsc
- *
- * @defgroup BLE_GATTS_HVX_DISABLED_MSC GATTS Handle Value Indication or Notification disabled
- * @msc
- * hscale = "1.5";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * APP rbox PEER [label="Indications and Notifications Disabled in CCCD"];
- * |||;
- * SD rbox SD [label="Value in ATT Table: current_value"];
- * APP=>SD [label = "sd_ble_gatts_hvx(INDICATION or NOTIFICATION, app_value)"];
- * APP<<SD [label = "NRF_ERROR_INVALID_STATE"];
- * SD rbox SD [label="Value in ATT Table: current_value"];
- * @endmsc
- *
- * @defgroup BLE_GATTS_HVX_SYS_ATTRS_MISSING_MSC GATTS Handle Value Indication or Notification with System Attributes Missing
- * @msc
- * hscale = "1.5";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * APP rbox PEER [label="System Attributes Uninitialized"];
- * |||;
- * SD rbox SD [label="Value in ATT Table: current_value"];
- * APP=>SD [label = "sd_ble_gatts_hvx(INDICATION or NOTIFICATION, app_value)"];
- * APP<<SD [label = "BLE_ERROR_GATTS_SYS_ATTR_MISSING"];
- * SD rbox SD [label="Value in ATT Table: current_value"];
- * APP=>SD [label = "sd_ble_gatts_sys_attr_set()"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * ...;
- * @endmsc
- *
- * @defgroup BLE_GATTS_SC_MSC GATTS Service Changed
- * @msc
- * hscale = "1.5";
- * APP,SD,PEER;
- * |||;
- * APP rbox SD [label="Entries added to the ATT Table between handles N and M"];
- * |||;
- * APP rbox PEER [label="Connection Established with a Bonded Peer"];
- * |||;
- * APP=>SD [label = "sd_ble_gatts_service_changed(N, M)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Handle Value Indication {N, M}", textcolor="#000080", linecolor="#000080"];
- * SD<:PEER [label = "ATT Handle Value Confirmation", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTS_EVT_SC_CONFIRM"];
- * |||;
- * SD rbox PEER [label="Service Discovery"];
- * @endmsc
- *
- * @defgroup BLE_GATTS_SYS_ATTRS_UNK_PEER_MSC GATTS System Attributes Handling: Unknown Peer
- * @msc
- * hscale = "1.5";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established with an Unknown Peer"];
- * |||;
- * SD<:PEER [label = "ATT Read Request {sys_attr_handle}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTS_EVT_SYS_ATTR_MISSING"];
- * APP=>SD [label = "sd_ble_gatts_sys_attr_set(NULL)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Read Response {sys_attr_value}", textcolor="#000080", linecolor="#000080"];
- * @endmsc
- *
- * @defgroup BLE_GATTS_SYS_ATTRS_BONDED_PEER_MSC GATTS System Attributes Handling: Bonded Peer
- * @msc
- * hscale = "1.5";
- * APP,SD,PEER;
- * |||;
- * APP rbox PEER [label="Connection Established with a Bonded Peer"];
- * |||;
- * APP rbox PEER [label="ATT Traffic"];
- * |||;
- * APP rbox PEER [label="Connection Terminated"];
- * APP<<=SD [label = "BLE_GAP_EVT_DISCONNECTED {reason}"];
- * |||;
- * APP=>SD [label = "sd_ble_gatts_sys_attr_get()"];
- * APP<<SD [label = "{NRF_SUCCESS, sys_attr_data}"];
- * APP rbox APP [label="Store System Attributes"];
- * |||;
- * APP rbox SD [label="Shut down IC"];
- * |||;
- * APP rbox SD [label="Power up IC"];
- * |||;
- * APP rbox PEER [label="Connection Established with the Bonded Peer"];
- * SD<:PEER [label = "ATT Read Request {sys_attr_handle}", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_GATTS_EVT_SYS_ATTR_MISSING"];
- * APP rbox APP [label="Load System Attributes"];
- * APP=>SD [label = "sd_ble_gatts_sys_attr_set(sys_attr_data)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "ATT Read Response {sys_attr_value}", textcolor="#000080", linecolor="#000080"];
- * @endmsc
- * @}
- *
- * @addtogroup BLE_GATTS_QUEUED_WRITES_USER_MEM User memory layout for Queued Writes
- * @{ 
- *  The following table shows the memory layout used by the SoftDevice to queue a Queued Write operation (Prepare Write ATT packet) in user memory:
- *
- *  <table style="border:1px solid black;border-collapse:collapse;">
- *  <caption>Queued Write</caption>
- *  <tr>
- *  <th style="border:1px solid black;padding:5px;">Parameter</th>
- *  <th style="border:1px solid black;padding:5px;">Size (octets)</th>
- *  <th style="border:1px solid black;padding:5px;">Description</th>
- *  </tr>
- *  <tr>
- *  <td style="border:1px solid black;padding:5px;">Handle</td>
- *  <td style="border:1px solid black;padding:5px;">2</td>
- *  <td style="border:1px solid black;padding:5px;">Attribute Handle</td>
- *  </tr>
- *  <tr>
- *  <td style="border:1px solid black;padding:5px;">Offset</td>
- *  <td style="border:1px solid black;padding:5px;">2</td>
- *  <td style="border:1px solid black;padding:5px;">Value Offset</td>
- *  </tr>
- *  <tr>
- *  <td style="border:1px solid black;padding:5px;">Length</td>
- *  <td style="border:1px solid black;padding:5px;">2</td>
- *  <td style="border:1px solid black;padding:5px;">Value Length</td>
- *  </tr>
- *  <tr>
- *  <td style="border:1px solid black;padding:5px;">Value</td>
- *  <td style="border:1px solid black;padding:5px;">Length</td>
- *  <td style="border:1px solid black;padding:5px;">Attribute Value</td>
- *  </tr>
- *  </table>
- *
- *  The application can parse the array of Queued Write instances at any time, but it is recommended to do so whenever an Execute Write ATT packet 
- *  has been received over the air. See the GATT Server Queued Writes MSCs for more details.
- *  The array will be terminated by an Queued Write instance with its handle set to @ref BLE_GATT_HANDLE_INVALID.
- * @}
- * @}
- */
-
-/**
- * @addtogroup BLE_L2CAP 
- * @{
- * @defgroup BLE_L2CAP_MSC Message Sequence Charts
- * @{
- * @defgroup BLE_L2CAP_API_MSC L2CAP API
- * @msc
- * hscale = "1.5";
- * APP,SD,PEER;
- * |||;
- * APP=>SD [label = "sd_ble_l2cap_cid_register(cid)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * |||;
- * APP rbox PEER [label="Connection Established"];
- * |||;
- * APP=>SD [label = "sd_ble_l2cap_tx(data)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "L2CAP packet", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_EVT_TX_COMPLETE"];
- * SD<:PEER [label = "L2CAP packet", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_L2CAP_EVT_RX"];
- * SD<:PEER [label = "L2CAP packet", textcolor="#000080", linecolor="#000080"];
- * APP<<=SD [label = "BLE_L2CAP_EVT_RX"];
- * |||;
- * APP=>SD [label = "sd_ble_l2cap_tx(data)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * SD:>PEER [label = "L2CAP packet", textcolor="#000080", linecolor="#000080"];
- * SD=>>APP [label = "BLE_EVT_TX_COMPLETE"];
- * |||;
- * APP rbox PEER [label="Terminate Connection"];
- * |||;
- * APP=>SD [label = "sd_ble_l2cap_cid_unregister(cid)"];
- * APP<<SD [label = "NRF_SUCCESS"];
- * @endmsc
- * @}
- * @}
- */
\ No newline at end of file
--- a/source/nordic-sdk/components/softdevice/s130/include/ble_gap.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nordic-sdk/components/softdevice/s130/include/ble_gap.h	Wed Apr 06 22:39:17 2016 +0100
@@ -70,8 +70,8 @@
   SD_BLE_GAP_ENCRYPT,                          /**< Initiate encryption procedure. */
   SD_BLE_GAP_SEC_INFO_REPLY,                   /**< Reply with Security Information. */
   SD_BLE_GAP_CONN_SEC_GET,                     /**< Obtain connection security level. */
-  SD_BLE_GAP_RSSI_START,                       /**< Start reporting of changes in RSSI. */
-  SD_BLE_GAP_RSSI_STOP,                        /**< Stop reporting of changes in RSSI. */
+  SD_BLE_GAP_RSSI_START,                       /**< Start reporting of changes in RSSI. */ 
+  SD_BLE_GAP_RSSI_STOP,                        /**< Stop reporting of changes in RSSI. */ 
   SD_BLE_GAP_SCAN_START,                       /**< Start Scanning. */
   SD_BLE_GAP_SCAN_STOP,                        /**< Stop Scanning. */
   SD_BLE_GAP_CONNECT,                          /**< Connect. */
@@ -123,7 +123,7 @@
 #define BLE_ERROR_GAP_UUID_LIST_MISMATCH            (NRF_GAP_ERR_BASE + 0x000)  /**< UUID list does not contain an integral number of UUIDs. */
 #define BLE_ERROR_GAP_DISCOVERABLE_WITH_WHITELIST   (NRF_GAP_ERR_BASE + 0x001)  /**< Use of Whitelist not permitted with discoverable advertising. */
 #define BLE_ERROR_GAP_INVALID_BLE_ADDR              (NRF_GAP_ERR_BASE + 0x002)  /**< The upper two bits of the address do not correspond to the specified address type. */
-#define BLE_ERROR_GAP_WHITELIST_IN_USE              (NRF_GAP_ERR_BASE + 0x003)  /**< Attempt to overwrite the whitelist while already in use by another operation. */
+#define BLE_ERROR_GAP_WHITELIST_IN_USE              (NRF_GAP_ERR_BASE + 0x003)  /**< Attempt to overwrite the whitelist while already in use by another operation. */ 
 /**@} */
 
 
@@ -191,7 +191,7 @@
 #define BLE_GAP_AD_TYPE_PUBLIC_TARGET_ADDRESS               0x17 /**< Public Target Address. */
 #define BLE_GAP_AD_TYPE_RANDOM_TARGET_ADDRESS               0x18 /**< Random Target Address. */
 #define BLE_GAP_AD_TYPE_APPEARANCE                          0x19 /**< Appearance. */
-#define BLE_GAP_AD_TYPE_ADVERTISING_INTERVAL                0x1A /**< Advertising Interval. */
+#define BLE_GAP_AD_TYPE_ADVERTISING_INTERVAL                0x1A /**< Advertising Interval. */ 
 #define BLE_GAP_AD_TYPE_LE_BLUETOOTH_DEVICE_ADDRESS         0x1B /**< LE Bluetooth Device Address. */
 #define BLE_GAP_AD_TYPE_LE_ROLE                             0x1C /**< LE Role. */
 #define BLE_GAP_AD_TYPE_SIMPLE_PAIRING_HASH_C256            0x1D /**< Simple Pairing Hash C-256. */
@@ -460,7 +460,7 @@
   uint8_t             irk_count;       /**< Count of IRKs in array, up to @ref BLE_GAP_WHITELIST_IRK_MAX_COUNT. */
 } ble_gap_whitelist_t;
 
-/**@brief Channel mask for RF channels used in advertising and scanning. */
+/**@brief Channel mask for RF channels used in advertising and scanning. */ 
 typedef struct
 {
   uint8_t ch_37_off : 1;  /**< Setting this bit to 1 will turn off advertising on channel 37 */
@@ -827,12 +827,12 @@
  *        - A private address refresh cycle.
  *
  * @note  The specified address cycle interval is used when the address cycle mode is
- *        @ref BLE_GAP_ADDR_CYCLE_MODE_AUTO. If 0 is given, the address will not be automatically
+ *        @ref BLE_GAP_ADDR_CYCLE_MODE_AUTO. If 0 is given, the address will not be automatically 
  *        refreshed at all. The default interval is @ref BLE_GAP_DEFAULT_PRIVATE_ADDR_CYCLE_INTERVAL_S.
  *
  * @note  If the current address cycle mode is @ref BLE_GAP_ADDR_CYCLE_MODE_AUTO, the address will immediately be
  *        refreshed when a custom privacy option is set. A new address can be generated manually by calling
- *        @ref sd_ble_gap_address_set with the same type again.
+ *        @ref sd_ble_gap_address_set with the same type again. 
  *
  * @note  If the IRK is updated, the new IRK becomes the one to be distributed in all
  *        bonding procedures performed after @ref sd_ble_opt_set returns.
@@ -870,7 +870,7 @@
  *        This can be used with @ref sd_ble_opt_set to enable and disable
  *        compatibility modes. Compatibility modes are disabled by default.
  *
- *  @note  Compatibility mode 1 enables interoperability with devices that do not support
+ *  @note  Compatibility mode 1 enables interoperability with devices that do not support 
  *         a value of 0 for the WinOffset parameter in the Link Layer CONNECT_REQ packet.
  *
  *  @retval ::NRF_SUCCESS Set successfully.
@@ -903,7 +903,7 @@
  * @note If the address cycle mode is @ref BLE_GAP_ADDR_CYCLE_MODE_AUTO, the address type is required to
  * be @ref BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE or
  * @ref BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE. The given address is ignored and the
- * SoftDevice will generate a new private address automatically every
+ * SoftDevice will generate a new private address automatically every 
  * @ref BLE_GAP_DEFAULT_PRIVATE_ADDR_CYCLE_INTERVAL_S seconds. If this API
  * call is used again with the same parameters, the SoftDevice will immediately
  * generate a new private address to replace the current address.
@@ -953,9 +953,9 @@
  *
  * @note The format of the advertising data will be checked by this call to ensure interoperability.
  *       Limitations imposed by this API call to the data provided include having a flags data type in the scan response data and
- *       duplicating the local name in the advertising data and scan response data.
+ *       duplicating the local name in the advertising data and scan response data. 
  *
- * @note To clear the advertising data and set it to a 0-length packet, simply provide a valid pointer (p_data/p_sr_data) with its corresponding
+ * @note To clear the advertising data and set it to a 0-length packet, simply provide a valid pointer (p_data/p_sr_data) with its corresponding 
  *        length (dlen/srdlen) set to 0.
  *
  * @note The call will fail if p_data and p_sr_data are both NULL since this would have no effect.
@@ -1140,7 +1140,7 @@
  *                         In the peripheral role, only the timeout, bond and mitm fields of this structure are used.
  *                         In the central role, this pointer may be NULL to reject a Security Request.
  *
- * @details In the central role, this function will send an SMP Pairing Request (or an SMP Pairing Failed if rejected),
+ * @details In the central role, this function will send an SMP Pairing Request (or an SMP Pairing Failed if rejected), 
  *          otherwise in the peripheral role, an SMP Security Request will be sent.
  *
  * @note    Calling this function may result in the following events depending on the outcome and parameters: @ref BLE_GAP_EVT_SEC_PARAMS_REQUEST,
@@ -1164,13 +1164,13 @@
  * @param[in] sec_status Security status, see @ref BLE_GAP_SEC_STATUS.
  * @param[in] p_sec_params Pointer to a @ref ble_gap_sec_params_t security parameters structure. In the central role this must be set to NULL, as the parameters have
  *                         already been provided during a previous call to @ref sd_ble_gap_authenticate.
- * @param[in,out] p_sec_keyset Pointer to a @ref ble_gap_sec_keyset_t security keyset structure. Any keys distributed as a result of the ongoing security procedure
- *                         will be stored into the memory referenced by the pointers inside this structure. The keys will be stored and available to the application
+ * @param[in,out] p_sec_keyset Pointer to a @ref ble_gap_sec_keyset_t security keyset structure. Any keys distributed as a result of the ongoing security procedure 
+ *                         will be stored into the memory referenced by the pointers inside this structure. The keys will be stored and available to the application 
  *                         upon reception of a @ref BLE_GAP_EVT_AUTH_STATUS event.
- *                         The pointer to the ID key data distributed by the <b>local device</b> constitutes however an exception. It can either point to ID key data
- *                         filled in by the user before calling this function, in which case a user-supplied Bluetooth address and IRK will be distributed,
- *                         or the pointer to the ID key data structure can be NULL, in which case the device's configured (or default, if none is configured)
- *                         Bluetooth address and IRK will be distributed.
+ *                         The pointer to the ID key data distributed by the <b>local device</b> constitutes however an exception. It can either point to ID key data 
+ *                         filled in by the user before calling this function, in which case a user-supplied Bluetooth address and IRK will be distributed, 
+ *                         or the pointer to the ID key data structure can be NULL, in which case the device's configured (or default, if none is configured) 
+ *                         Bluetooth address and IRK will be distributed. 
  *
  * @details This function is only used to reply to a @ref BLE_GAP_EVT_SEC_PARAMS_REQUEST, calling it at other times will result in an @ref NRF_ERROR_INVALID_STATE.
  * @note    If the call returns an error code, the request is still pending, and the reply call may be repeated with corrected parameters.
@@ -1255,7 +1255,7 @@
 SVCALL(SD_BLE_GAP_CONN_SEC_GET, uint32_t, sd_ble_gap_conn_sec_get(uint16_t conn_handle, ble_gap_conn_sec_t *p_conn_sec));
 
 
-/**@brief Start reporting the received signal strength to the application.
+/**@brief Start reporting the received signal strength to the application. 
  *
  * A new event is reported whenever the RSSI value changes, until @ref sd_ble_gap_rssi_stop is called.
  *
@@ -1272,7 +1272,7 @@
 
 /**@brief Stop reporting the received signal strength.
  *
- * @note An RSSI change detected before the call but not yet received by the application
+ * @note An RSSI change detected before the call but not yet received by the application 
  * may be reported after @ref sd_ble_gap_rssi_stop has been called.
  *
  * @param[in] conn_handle Connection handle.
@@ -1327,7 +1327,7 @@
 
 /**@brief Create a connection (GAP Link Establishment).
  *
- * @note To use the currently active whitelist set p_scan_params->p_whitelist to NULL.
+ * @note To use the currently active whitelist set p_scan_params->p_whitelist to NULL.    
  *
  * @param[in] p_peer_addr   Pointer to peer address. If the selective bit is set in @ref ble_gap_scan_params_t, then this must be NULL.
  * @param[in] p_scan_params Pointer to scan parameters structure.
--- a/source/nordic-sdk/components/softdevice/s130/include/ble_gattc.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nordic-sdk/components/softdevice/s130/include/ble_gattc.h	Wed Apr 06 22:39:17 2016 +0100
@@ -179,10 +179,10 @@
 } ble_gattc_evt_desc_disc_rsp_t;
 
 /**@brief GATT read by UUID handle value pair. */
-typedef struct
+typedef struct 
 {
   uint16_t            handle;          /**< Attribute Handle. */
-  uint8_t             *p_value;        /**< Pointer to value, variable length (length available as value_len in @ref ble_gattc_evt_char_val_by_uuid_read_rsp_t).
+  uint8_t             *p_value;        /**< Pointer to value, variable length (length available as value_len in @ref ble_gattc_evt_char_val_by_uuid_read_rsp_t). 
                                             Please note that this pointer is absolute to the memory provided by the user when retrieving the event,
                                             so it will effectively point to a location inside the handle_value array. */
 } ble_gattc_handle_value_t;
@@ -263,7 +263,7 @@
 
 /**@brief Initiate or continue a GATT Primary Service Discovery procedure.
  *
- * @details This function initiates or resumes a Primary Service discovery procedure, starting from the supplied handle.
+ * @details This function initiates or resumes a Primary Service discovery procedure, starting from the supplied handle. 
  *          If the last service has not been reached, this function must be called again with an updated start handle value to continue the search.
  *
  * @note If any of the discovered services have 128-bit UUIDs which are not present in the table provided to ble_vs_uuids_assign, a UUID structure with
@@ -358,7 +358,7 @@
 /**@brief Initiate or continue a GATT Read (Long) Characteristic or Descriptor procedure.
  *
  * @details This function initiates or resumes a GATT Read (Long) Characteristic or Descriptor procedure. If the Characteristic or Descriptor
- *          to be read is longer than ATT_MTU - 1, this function must be called multiple times with appropriate offset to read the
+ *          to be read is longer than ATT_MTU - 1, this function must be called multiple times with appropriate offset to read the 
  *          complete value.
  *
  * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
@@ -376,7 +376,7 @@
 
 /**@brief Initiate a GATT Read Multiple Characteristic Values procedure.
  *
- * @details This function initiates a GATT Read Multiple Characteristic Values procedure.
+ * @details This function initiates a GATT Read Multiple Characteristic Values procedure. 
  *
  * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
  * @param[in] p_handles A pointer to the handle(s) of the attribute(s) to be read.
@@ -393,11 +393,11 @@
 
 /**@brief Perform a Write (Characteristic Value or Descriptor, with or without response, signed or not, long or reliable) procedure.
  *
- * @details This function can perform all write procedures described in GATT.
+ * @details This function can perform all write procedures described in GATT. 
  *
- * @note    It is important to note that a write without response will <b>consume an application buffer</b>, and will therefore
- *          generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted. A write (with response) on the other hand will use the
- *          standard client internal buffer and thus will only generate a @ref BLE_GATTC_EVT_WRITE_RSP event as soon as the write response
+ * @note    It is important to note that a write without response will <b>consume an application buffer</b>, and will therefore 
+ *          generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted. A write (with response) on the other hand will use the 
+ *          standard client internal buffer and thus will only generate a @ref BLE_GATTC_EVT_WRITE_RSP event as soon as the write response 
  *          has been received from the peer. Please see the documentation of @ref sd_ble_tx_buffer_count_get for more details.
  *
  * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
--- a/source/nordic-sdk/components/softdevice/s130/include/ble_gatts.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nordic-sdk/components/softdevice/s130/include/ble_gatts.h	Wed Apr 06 22:39:17 2016 +0100
@@ -62,8 +62,8 @@
   SD_BLE_GATTS_VALUE_GET,                        /**< Get an attribute value. */
   SD_BLE_GATTS_HVX,                              /**< Handle Value Notification or Indication. */
   SD_BLE_GATTS_SERVICE_CHANGED,                  /**< Perform a Service Changed Indication to one or more peers. */
-  SD_BLE_GATTS_RW_AUTHORIZE_REPLY,               /**< Reply to an authorization request for a read or write operation on one or more attributes. */
-  SD_BLE_GATTS_SYS_ATTR_SET,                     /**< Set the persistent system attributes for a connection. */
+  SD_BLE_GATTS_RW_AUTHORIZE_REPLY,               /**< Reply to an authorization request for a read or write operation on one or more attributes. */ 
+  SD_BLE_GATTS_SYS_ATTR_SET,                     /**< Set the persistent system attributes for a connection. */  
   SD_BLE_GATTS_SYS_ATTR_GET,                     /**< Retrieve the persistent system attributes. */
 };
 
@@ -93,7 +93,7 @@
 /** @defgroup BLE_GATTS_ATTR_LENS_MAX Maximum attribute lengths
  * @{ */
 #define BLE_GATTS_FIX_ATTR_LEN_MAX (510)  /**< Maximum length for fixed length Attribute Values. */
-#define BLE_GATTS_VAR_ATTR_LEN_MAX (512)  /**< Maximum length for variable length Attribute Values. */
+#define BLE_GATTS_VAR_ATTR_LEN_MAX (512)  /**< Maximum length for variable length Attribute Values. */ 
 /** @} */
 
 /** @defgroup BLE_GATTS_SRVC_TYPES GATT Server Service Types
@@ -177,7 +177,7 @@
   ble_gap_conn_sec_mode_t write_perm;      /**< Write permissions. */
   uint8_t                 vlen       :1;   /**< Variable length attribute. */
   uint8_t                 vloc       :2;   /**< Value location, see @ref BLE_GATTS_VLOCS.*/
-  uint8_t                 rd_auth    :1;   /**< Read authorization and value will be requested from the application on every read operation. */
+  uint8_t                 rd_auth    :1;   /**< Read authorization and value will be requested from the application on every read operation. */ 
   uint8_t                 wr_auth    :1;   /**< Write authorization will be requested from the application on every Write Request operation (but not Write Command). */
 } ble_gatts_attr_md_t;
 
@@ -191,7 +191,7 @@
   uint16_t             init_offs;       /**< Initial attribute value offset in bytes. If different from zero, the first init_offs bytes of the attribute value will be left uninitialized. */
   uint16_t             max_len;         /**< Maximum attribute value length in bytes, see @ref BLE_GATTS_ATTR_LENS_MAX for maximum values. */
   uint8_t*             p_value;         /**< Pointer to the attribute data. Please note that if the @ref BLE_GATTS_VLOC_USER value location is selected in the attribute metadata, this will have to point to a buffer
-                                             that remains valid through the lifetime of the attribute. This excludes usage of automatic variables that may go out of scope or any other temporary location.
+                                             that remains valid through the lifetime of the attribute. This excludes usage of automatic variables that may go out of scope or any other temporary location. 
                                              The stack may access that memory directly without the application's knowledge. For writable characteristics, this value must not be a location in flash memory.*/
 } ble_gatts_attr_t;
 
@@ -200,7 +200,7 @@
 {
   uint16_t  len;        /**< Length in bytes to be written or read. Length in bytes written or read after successful return.*/
   uint16_t  offset;     /**< Attribute value offset. */
-  uint8_t   *p_value;   /**< Pointer to where value is stored or will be stored.
+  uint8_t   *p_value;   /**< Pointer to where value is stored or will be stored. 
                              If value is stored in user memory, only the attribute length is updated when p_value == NULL.
                              Set to NULL when reading to obtain the complete length of the attribute value */
 } ble_gatts_value_t;
@@ -236,7 +236,7 @@
   ble_gatt_char_ext_props_t   char_ext_props;           /**< Characteristic Extended Properties. */
   uint8_t                    *p_char_user_desc;         /**< Pointer to a UTF-8 encoded string (non-NULL terminated), NULL if the descriptor is not required. */
   uint16_t                    char_user_desc_max_size;  /**< The maximum size in bytes of the user description descriptor. */
-  uint16_t                    char_user_desc_size;      /**< The size of the user description, must be smaller or equal to char_user_desc_max_size. */
+  uint16_t                    char_user_desc_size;      /**< The size of the user description, must be smaller or equal to char_user_desc_max_size. */ 
   ble_gatts_char_pf_t*        p_char_pf;                /**< Pointer to a presentation format structure or NULL if the CPF descriptor is not required. */
   ble_gatts_attr_md_t*        p_user_desc_md;           /**< Attribute metadata for the User Description descriptor, or NULL for default values. */
   ble_gatts_attr_md_t*        p_cccd_md;                /**< Attribute metadata for the Client Characteristic Configuration Descriptor, or NULL for default values. */
@@ -380,7 +380,7 @@
 
 /**@brief Add an include declaration to the Attribute Table.
  *
- * @note It is currently only possible to add an include declaration to the last added service (i.e. only sequential population is supported at this time).
+ * @note It is currently only possible to add an include declaration to the last added service (i.e. only sequential population is supported at this time). 
  *
  * @note The included service must already be present in the Attribute Table prior to this call.
  *
@@ -401,7 +401,7 @@
 
 /**@brief Add a characteristic declaration, a characteristic value declaration and optional characteristic descriptor declarations to the Attribute Table.
  *
- * @note It is currently only possible to add a characteristic to the last added service (i.e. only sequential population is supported at this time).
+ * @note It is currently only possible to add a characteristic to the last added service (i.e. only sequential population is supported at this time). 
  *
  * @note Several restrictions apply to the parameters, such as matching permissions between the user description descriptor and the writeable auxiliaries bits,
  *       readable (no security) and writeable (selectable) CCCDs and SCCDs and valid presentation format values.
@@ -426,7 +426,7 @@
 
 /**@brief Add a descriptor to the Attribute Table.
  *
- * @note It is currently only possible to add a descriptor to the last added characteristic (i.e. only sequential population is supported at this time).
+ * @note It is currently only possible to add a descriptor to the last added characteristic (i.e. only sequential population is supported at this time). 
  *
  * @param[in] char_handle   Handle of the characteristic where the descriptor is to be placed, if @ref BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.
  * @param[in] p_attr        Pointer to the attribute structure.
@@ -471,7 +471,7 @@
  *                       p_len will return the total attribute value length (excluding offset),
  *                       and not the number of bytes actually returned in p_data.
  *                       The application may use this information to allocate a suitable buffer size.
- *
+ * 
  * @note                 When retrieving system attribute values with this function, the connection handle
  *                       may refer to an already disconnected connection. Refer to the documentation of
  *                       @ref sd_ble_gatts_sys_attr_get for further information.
@@ -492,14 +492,14 @@
  *          If the application chooses to indicate an attribute value, a @ref BLE_GATTS_EVT_HVC event will be issued as soon as the confirmation arrives from
  *          the peer.
  *
- * @note    The local attribute value may be updated even if an outgoing packet is not sent to the peer due to an error during execution.
- *          When receiveing the error codes @ref NRF_ERROR_INVALID_STATE, @ref NRF_ERROR_BUSY, @ref BLE_ERROR_GATTS_SYS_ATTR_MISSING and
+ * @note    The local attribute value may be updated even if an outgoing packet is not sent to the peer due to an error during execution. 
+ *          When receiveing the error codes @ref NRF_ERROR_INVALID_STATE, @ref NRF_ERROR_BUSY, @ref BLE_ERROR_GATTS_SYS_ATTR_MISSING and 
  *          @ref BLE_ERROR_NO_TX_BUFFERS the Attribute Table has been updated.
  *          The caller can check whether the value has been updated by looking at the contents of *(p_hvx_params->p_len).
  *
- * @note    It is important to note that a notification will <b>consume an application buffer</b>, and will therefore
- *          generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted. An indication on the other hand will use the
- *          standard server internal buffer and thus will only generate a @ref BLE_GATTS_EVT_HVC event as soon as the confirmation
+ * @note    It is important to note that a notification will <b>consume an application buffer</b>, and will therefore 
+ *          generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted. An indication on the other hand will use the 
+ *          standard server internal buffer and thus will only generate a @ref BLE_GATTS_EVT_HVC event as soon as the confirmation 
  *          has been received from the peer. Please see the documentation of @ref sd_ble_tx_buffer_count_get for more details.
  *
  * @param[in] conn_handle  Connection handle.
@@ -564,18 +564,18 @@
 
 /**@brief Update persistent system attribute information.
  *
- * @details Supply information about persistent system attributes to the stack,
+ * @details Supply information about persistent system attributes to the stack, 
  *          previously obtained using @ref sd_ble_gatts_sys_attr_get.
- *          This call is only allowed for active connections, and is usually
+ *          This call is only allowed for active connections, and is usually 
  *          made immediately after a connection is established with an known bonded device,
  *          often as a response to a @ref BLE_GATTS_EVT_SYS_ATTR_MISSING.
  *
- *          p_sysattrs may point directly to the application's stored copy of the system attributes
+ *          p_sysattrs may point directly to the application's stored copy of the system attributes 
  *          obtained using @ref sd_ble_gatts_sys_attr_get.
  *          If the pointer is NULL, the system attribute info is initialized, assuming that
  *          the application does not have any previously saved system attribute data for this device.
  *
- * @note The state of persistent system attributes is reset upon connection establishment and then remembered for its duration.
+ * @note The state of persistent system attributes is reset upon connection establishment and then remembered for its duration. 
  *
  * @note If this call returns with an error code different from @ref NRF_SUCCESS, the storage of persistent system attributes may have been completed only partially.
  *       This means that the state of the attribute table is undefined, and the application should either provide a new set of attributes using this same call or
@@ -586,7 +586,7 @@
  *
  * @param[in]  conn_handle        Connection handle.
  * @param[in]  p_sys_attr_data    Pointer to a saved copy of system attributes supplied to the stack, or NULL.
- * @param[in]  len                Size of data pointed by p_sys_attr_data, in octets.
+ * @param[in]  len                Size of data pointed by p_sys_attr_data, in octets. 
  * @param[in]  flags              Optional additional flags, see @ref BLE_GATTS_SYS_ATTR_FLAGS
  *
  * @retval ::NRF_SUCCESS Successfully set the system attribute information.
@@ -595,14 +595,14 @@
  * @retval ::NRF_ERROR_INVALID_DATA Invalid data supplied, the data should be exactly the same as retrieved with @ref sd_ble_gatts_sys_attr_get.
  * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation.
  * @retval ::NRF_ERROR_BUSY The stack is busy. Retry at later time.
- */
-SVCALL(SD_BLE_GATTS_SYS_ATTR_SET, uint32_t, sd_ble_gatts_sys_attr_set(uint16_t conn_handle, uint8_t const *p_sys_attr_data, uint16_t len, uint32_t flags));
+ */ 
+SVCALL(SD_BLE_GATTS_SYS_ATTR_SET, uint32_t, sd_ble_gatts_sys_attr_set(uint16_t conn_handle, uint8_t const *p_sys_attr_data, uint16_t len, uint32_t flags)); 
 
-
+ 
 /**@brief Retrieve persistent system attribute information from the stack.
  *
  * @details This call is used to retrieve information about values to be stored perisistently by the application
- *          during the lifetime of a connection or after it has been terminated. When a new connection is established with the same bonded device,
+ *          during the lifetime of a connection or after it has been terminated. When a new connection is established with the same bonded device, 
  *          the system attribute information retrieved with this function should be restored using using @ref sd_ble_gatts_sys_attr_set.
  *          If retrieved after disconnection, the data should be read before a new connection established. The connection handle for
  *          the previous, now disconnected, connection will remain valid until a new one is created to allow this API call to refer to it.
@@ -613,7 +613,7 @@
  * @note When the @ref BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS is used with this function, only the system attributes included in user services will be returned.
  *
  * @param[in]     conn_handle       Connection handle of the recently terminated connection.
- * @param[out]    p_sys_attr_data   Pointer to a buffer where updated information about system attributes will be filled in. NULL can be provided to
+ * @param[out]    p_sys_attr_data   Pointer to a buffer where updated information about system attributes will be filled in. NULL can be provided to 
  *                                  obtain the length of the data
  * @param[in,out] p_len             Size of application buffer if p_sys_attr_data is not NULL. Unconditially updated to actual length of system attribute data.
  * @param[in]     flags             Optional additional flags, see @ref BLE_GATTS_SYS_ATTR_FLAGS
@@ -623,8 +623,8 @@
  * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  * @retval ::NRF_ERROR_DATA_SIZE The system attribute information did not fit into the provided buffer.
  * @retval ::NRF_ERROR_NOT_FOUND No system attributes found.
- */
-SVCALL(SD_BLE_GATTS_SYS_ATTR_GET, uint32_t, sd_ble_gatts_sys_attr_get(uint16_t conn_handle, uint8_t *p_sys_attr_data, uint16_t *p_len, uint32_t flags));
+ */ 
+SVCALL(SD_BLE_GATTS_SYS_ATTR_GET, uint32_t, sd_ble_gatts_sys_attr_get(uint16_t conn_handle, uint8_t *p_sys_attr_data, uint16_t *p_len, uint32_t flags)); 
 
 /** @} */
 
--- a/source/nordic-sdk/components/softdevice/s130/include/ble_hci.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nordic-sdk/components/softdevice/s130/include/ble_hci.h	Wed Apr 06 22:39:17 2016 +0100
@@ -31,13 +31,13 @@
  */
 
 /**
-  @addtogroup BLE_COMMON
+  @addtogroup BLE_COMMON 
   @{
 */
 
 
 #ifndef BLE_HCI_H__
-#define BLE_HCI_H__
+#define BLE_HCI_H__ 
 
 /** @defgroup BLE_HCI_STATUS_CODES Bluetooth status codes
  * @{ */
--- a/source/nordic-sdk/components/softdevice/s130/include/ble_l2cap.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nordic-sdk/components/softdevice/s130/include/ble_l2cap.h	Wed Apr 06 22:39:17 2016 +0100
@@ -37,7 +37,7 @@
  */
 
 #ifndef BLE_L2CAP_H__
-#define BLE_L2CAP_H__
+#define BLE_L2CAP_H__ 
 
 #include "ble_types.h"
 #include "ble_ranges.h"
@@ -48,7 +48,7 @@
  * @{ */
 
 /**@brief L2CAP API SVC numbers. */
-enum BLE_L2CAP_SVCS
+enum BLE_L2CAP_SVCS 
 {
   SD_BLE_L2CAP_CID_REGISTER = BLE_L2CAP_SVC_BASE,  /**< Register a CID. */
   SD_BLE_L2CAP_CID_UNREGISTER,                     /**< Unregister a CID. */
@@ -56,7 +56,7 @@
 };
 
 /**@brief L2CAP Event IDs. */
-enum BLE_L2CAP_EVTS
+enum BLE_L2CAP_EVTS 
 {
   BLE_L2CAP_EVT_RX  = BLE_L2CAP_EVT_BASE          /**< L2CAP packet received. */
 };
@@ -72,16 +72,16 @@
 /** @} */
 
 /**@brief Default L2CAP MTU. */
-#define BLE_L2CAP_MTU_DEF           (23)
+#define BLE_L2CAP_MTU_DEF           (23)    
 
 /**@brief Invalid Channel Identifier. */
-#define BLE_L2CAP_CID_INVALID       (0x0000)
+#define BLE_L2CAP_CID_INVALID       (0x0000) 
 
 /**@brief Dynamic Channel Identifier base. */
-#define BLE_L2CAP_CID_DYN_BASE      (0x0040)
+#define BLE_L2CAP_CID_DYN_BASE      (0x0040) 
 
 /**@brief Maximum amount of dynamic CIDs. */
-#define BLE_L2CAP_CID_DYN_MAX       (8)
+#define BLE_L2CAP_CID_DYN_MAX       (8) 
 
 /** @} */
 
@@ -122,7 +122,7 @@
 /**@brief Register a CID with L2CAP.
  *
  * @details This registers a higher protocol layer with the L2CAP multiplexer, and is requried prior to all operations on the CID.
- *
+ *          
  * @param[in] cid L2CAP CID.
  *
  * @retval ::NRF_SUCCESS Successfully registered a CID with the L2CAP layer.
@@ -135,7 +135,7 @@
 /**@brief Unregister a CID with L2CAP.
  *
  * @details This unregisters a previously registerd higher protocol layer with the L2CAP multiplexer.
- *
+ *          
  * @param[in] cid L2CAP CID.
  *
  * @retval ::NRF_SUCCESS Successfully unregistered the CID.
@@ -146,8 +146,8 @@
 
 /**@brief Transmit an L2CAP packet.
  *
- * @note    It is important to note that a call to this function will <b>consume an application buffer</b>, and will therefore
- *          generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted.
+ * @note    It is important to note that a call to this function will <b>consume an application buffer</b>, and will therefore 
+ *          generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted. 
  *          Please see the documentation of @ref sd_ble_tx_buffer_count_get for more details.
  *
  * @param[in] conn_handle Connection Handle.
--- a/source/nordic-sdk/components/softdevice/s130/include/ble_types.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nordic-sdk/components/softdevice/s130/include/ble_types.h	Wed Apr 06 22:39:17 2016 +0100
@@ -90,6 +90,7 @@
 #define BLE_UUID_TYPE_VENDOR_BEGIN  0x02 /**< Vendor UUID types start at this index (128-bit). */
 /** @} */
 
+
 #if 0 /* The following have been duplicated in blecommon.h */
 /** @defgroup BLE_APPEARANCES Bluetooth Appearance values
  *  @note Retrieved from http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml
@@ -176,7 +177,7 @@
 
 /** @brief 128 bit UUID values. */
 typedef struct
-{
+{ 
     unsigned char uuid128[16]; /**< Little-Endian UUID bytes. */
 } ble_uuid128_t;
 
--- a/source/nordic-sdk/components/softdevice/s130/include/nrf_error.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nordic-sdk/components/softdevice/s130/include/nrf_error.h	Wed Apr 06 22:39:17 2016 +0100
@@ -28,11 +28,11 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- */
+ */ 
  /**
   @defgroup nrf_error SoftDevice Global Error Codes
   @{
-
+   
   @brief Global Error definitions
 */
 
--- a/source/nordic-sdk/components/softdevice/s130/include/nrf_sdm.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nordic-sdk/components/softdevice/s130/include/nrf_sdm.h	Wed Apr 06 22:39:17 2016 +0100
@@ -32,9 +32,9 @@
 /**
   @defgroup nrf_sdm_api SoftDevice Manager API
   @{
-
+     
   @brief APIs for SoftDevice management.
-
+ 
 */
 
 /* Header guard */
@@ -50,15 +50,15 @@
  * @{ */
 
 /** @brief SoftDevice Manager SVC Base number. */
-#define SDM_SVC_BASE 0x10
+#define SDM_SVC_BASE 0x10   
 
 /** @} */
 
-/** @brief Defines the SoftDevice Information Structure location (address) as an offset from
+/** @brief Defines the SoftDevice Information Structure location (address) as an offset from 
 the start of the softdevice (without MBR)*/
 #define SOFTDEVICE_INFO_STRUCT_OFFSET (0x2000)
 
-/** @brief Defines the usual size reserverd for the MBR when a softdevice is written to flash.
+/** @brief Defines the usual size reserverd for the MBR when a softdevice is written to flash. 
 This is the offset where the first byte of the softdevice hex file is written.*/
 #define MBR_SIZE (0x1000)
 
@@ -134,7 +134,7 @@
  * perform a reset, using e.g. CMSIS NVIC_SystemReset().
  *
  * @note This callback is executed in HardFault context, thus SVC functions cannot be called from the SoftDevice assert callback.
- *
+ *       
  * @param[in] pc The program counter of the failed assert.
  * @param[in] line_number Line number where the assert failed.
  * @param[in] file_name File name where the assert failed.
@@ -156,7 +156,7 @@
  *
  * @note This function has no effect when returning with an error.
  *
- * @post If return code is ::NRF_SUCCESS
+ * @post If return code is ::NRF_SUCCESS 
  *       - SoC library and protocol stack APIs are made available.
  *       - A portion of RAM will be unavailable (see relevant SDS documentation).
  *       - Some peripherals will be unavailable or available only through the SoC API (see relevant SDS documentation).
@@ -176,7 +176,7 @@
 SVCALL(SD_SOFTDEVICE_ENABLE, uint32_t, sd_softdevice_enable(nrf_clock_lfclksrc_t clock_source, softdevice_assertion_handler_t assertion_handler));
 
 /**@brief Disables the SoftDevice and by extension the protocol stack.
- *
+ * 
  * Idempotent function to disable the SoftDevice.
  *
  * @post SoC library and protocol stack APIs are made unavailable.
@@ -199,14 +199,14 @@
 SVCALL(SD_SOFTDEVICE_IS_ENABLED, uint32_t, sd_softdevice_is_enabled(uint8_t * p_softdevice_enabled));
 
 /**@brief Sets the base address of the interrupt vector table for interrupts forwarded from the SoftDevice
- *
+ * 
  * This function is only intended to be called when a bootloader is enabled.
  *
  * @param[in] address The base address of the interrupt vector table for forwarded interrupts.
-
+ 
  * @retval ::NRF_SUCCESS
  */
-SVCALL(SD_SOFTDEVICE_VECTOR_TABLE_BASE_SET, uint32_t, sd_softdevice_vector_table_base_set(uint32_t address));
+SVCALL(SD_SOFTDEVICE_VECTOR_TABLE_BASE_SET, uint32_t, sd_softdevice_vector_table_base_set(uint32_t address)); 
 
 /** @} */
 
--- a/source/nordic-sdk/components/softdevice/s130/include/nrf_soc.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nordic-sdk/components/softdevice/s130/include/nrf_soc.h	Wed Apr 06 22:39:17 2016 +0100
@@ -28,7 +28,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- */
+ */ 
 /**
  * @defgroup nrf_soc_api SoC Library API
  * @{
--- a/source/nordic-sdk/components/softdevice/s130/include/nrf_svc.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nordic-sdk/components/softdevice/s130/include/nrf_svc.h	Wed Apr 06 22:39:17 2016 +0100
@@ -49,7 +49,7 @@
   { \
     __asm( \
         "svc %0\n" \
-        "bx r14" : : "I" ((uint32_t)number) : "r0" \
+        "bx r14" : : "I" ((uint32_t) number) : "r0" \
     ); \
   }    \
   _Pragma("GCC diagnostic pop")
--- a/source/nordic-sdk/components/softdevice/s130/include/softdevice_assert.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/nordic-sdk/components/softdevice/s130/include/softdevice_assert.h	Wed Apr 06 22:39:17 2016 +0100
@@ -43,7 +43,7 @@
  *
  * @note
  * This function is called when an assertion has triggered.
- *
+ * 
  *
  * @param line_num The line number where the assertion is called
  * @param file_name Pointer to the file name
@@ -51,7 +51,7 @@
 void assert_softdevice_callback(uint16_t line_num, const uint8_t *file_name);
 
 
-/*lint -emacro(506, ASSERT) */ /* Suppress "Constant value Boolean */
+/*lint -emacro(506, ASSERT) */ /* Suppress "Constant value Boolean */ 
 /*lint -emacro(774, ASSERT) */ /* Suppress "Boolean within 'if' always evaluates to True" */ \
 /** @brief Check intended for production code
  *
--- a/source/projectconfig.h	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/projectconfig.h	Wed Apr 06 22:39:17 2016 +0100
@@ -17,7 +17,7 @@
 #ifndef _PROJECTCONFIG_H_
 #define _PROJECTCONFIG_H_
 
-#include "ble/blecommon.h"
+#include "ble/GapAdvertisingData.h"
 
 /*=========================================================================
     MCU & BOARD SELCTION
@@ -112,7 +112,7 @@
     #define CFG_BLE_SEC_PARAM_MAX_KEY_SIZE             16
 
     /*--------------------------------- GAP -------------------------------*/
-    #define CFG_GAP_APPEARANCE                         BLE_APPEARANCE_GENERIC_TAG
+    #define CFG_GAP_APPEARANCE                         GapAdvertisingData::GENERIC_TAG
     #define CFG_GAP_LOCAL_NAME                         "nRF5x"
 
     #define CFG_GAP_CONNECTION_MIN_INTERVAL_MS           50                     /**< Minimum acceptable connection interval */
--- a/source/supress-warnings.cmake	Wed Apr 06 22:38:43 2016 +0100
+++ b/source/supress-warnings.cmake	Wed Apr 06 22:39:17 2016 +0100
@@ -16,6 +16,6 @@
 
 if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
     set_target_properties(ble-nrf51822
-        PROPERTIES COMPILE_FLAGS "-Wno-sign-compare -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers"
+        PROPERTIES COMPILE_FLAGS "-Wno-sign-compare -Wno-unused-variable -Wno-unused-parameter -Wno-unused-function -Wno-missing-field-initializers"
     )
 endif()
\ No newline at end of file