Shuta Nakamae / nRF51822

Fork of nRF51822 by Nordic Semiconductor

Files at this revision

API Documentation at this revision

Comitter:
rgrover1
Date:
Thu Apr 30 08:34:37 2015 +0100
Parent:
111:be2a122ed2f7
Child:
113:2fb5fde31edc
Commit message:
Synchronized with git rev 4ae92f89
Author: Rohit Grover
porting to v8.0 of the SDK

Changed in this revision

btle/btle.cpp Show annotated file Show diff for this revision Revisions of this file
nRF51GattServer.cpp Show annotated file Show diff for this revision Revisions of this file
nRF51GattServer.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/ble/ble_services/ble_dfu/ble_dfu.c Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/ble/ble_services/ble_dfu/ble_dfu.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/ble/common/ble_advdata.c Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/ble/common/ble_advdata.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/ble/device_manager/device_manager.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/ble/device_manager/device_manager_peripheral.c Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/libraries/bootloader_dfu/dfu_bank_internal.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/libraries/bootloader_dfu/dfu_ble_svc.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/libraries/bootloader_dfu/dfu_init_template.c Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/libraries/bootloader_dfu/dfu_types.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/libraries/bootloader_dfu/experimental/dfu_app_handler.c Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/libraries/crc16/crc16.h Show diff for this revision Revisions of this file
nordic-sdk/components/libraries/gpiote/app_gpiote.c Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/libraries/gpiote/app_gpiote.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/libraries/scheduler/app_scheduler.c Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/libraries/scheduler/app_scheduler.h Show diff for this revision Revisions of this file
nordic-sdk/components/libraries/util/app_error.c Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/libraries/util/app_error.h Show diff for this revision Revisions of this file
nordic-sdk/components/libraries/util/app_util.h Show diff for this revision Revisions of this file
nordic-sdk/components/libraries/util/app_util_platform.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/libraries/util/sdk_errors.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/common/softdevice_handler/ble_stack_handler_types.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/common/softdevice_handler/softdevice_handler.c Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/common/softdevice_handler/softdevice_handler.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/common/softdevice_handler/softdevice_handler_appsh.c Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/common/softdevice_handler/softdevice_handler_appsh.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/s110/headers/ble.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/s110/headers/ble_err.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/s110/headers/ble_gap.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/s110/headers/ble_gatt.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/s110/headers/ble_gattc.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/s110/headers/ble_gatts.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/s110/headers/ble_hci.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/s110/headers/ble_l2cap.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/s110/headers/ble_ranges.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/s110/headers/ble_types.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/s110/headers/nrf_error.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/s110/headers/nrf_error_sdm.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/s110/headers/nrf_error_soc.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/s110/headers/nrf_mbr.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/s110/headers/nrf_sd_def.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/s110/headers/nrf_sdm.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/s110/headers/nrf_soc.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/s110/headers/nrf_svc.h Show annotated file Show diff for this revision Revisions of this file
nordic-sdk/components/softdevice/s110/headers/softdevice_assert.h Show annotated file Show diff for this revision Revisions of this file
--- a/btle/btle.cpp	Wed Apr 15 09:24:27 2015 +0100
+++ b/btle/btle.cpp	Thu Apr 30 08:34:37 2015 +0100
@@ -58,11 +58,10 @@
 
 error_t btle_init(void)
 {
-    const bool useScheduler = false;
 #if defined(TARGET_DELTA_DFCM_NNN40) || defined(TARGET_HRM1017)
-    SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_4000MS_CALIBRATION, useScheduler);
+    SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_4000MS_CALIBRATION, NULL);
 #else
-    SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, useScheduler);
+    SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL);
 #endif
 
     // Enable BLE stack
@@ -125,7 +124,11 @@
             nRF51Gap::getInstance().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;
-            nRF51Gap::getInstance().processConnectionEvent(handle, static_cast<Gap::addr_type_t>(peer->addr_type), peer->addr, params);
+            const ble_gap_addr_t *own  = &p_ble_evt->evt.gap_evt.params.connected.own_addr;
+            nRF51Gap::getInstance().processConnectionEvent(handle,
+                                                           static_cast<Gap::addr_type_t>(peer->addr_type), peer->addr,
+                                                           static_cast<Gap::addr_type_t>(own->addr_type),  own->addr,
+                                                           params);
             break;
         }
 
@@ -162,22 +165,21 @@
         case BLE_GAP_EVT_SEC_PARAMS_REQUEST: {
             ble_gap_sec_params_t sec_params = {0};
 
-            sec_params.timeout      = 30; /*< Timeout for Pairing Request or
-                                   * Security Request (in seconds). */
-            sec_params.bond         = 1;  /**< Perform bonding. */
-            sec_params.mitm         = CFG_BLE_SEC_PARAM_MITM;
-            sec_params.io_caps      = CFG_BLE_SEC_PARAM_IO_CAPABILITIES;
-            sec_params.oob          = CFG_BLE_SEC_PARAM_OOB;
-            sec_params.min_key_size = CFG_BLE_SEC_PARAM_MIN_KEY_SIZE;
-            sec_params.max_key_size = CFG_BLE_SEC_PARAM_MAX_KEY_SIZE;
+            sec_params.bond          = 1;  /**< Perform bonding. */
+            sec_params.mitm          = CFG_BLE_SEC_PARAM_MITM;
+            sec_params.io_caps       = CFG_BLE_SEC_PARAM_IO_CAPABILITIES;
+            sec_params.oob           = CFG_BLE_SEC_PARAM_OOB;
+            sec_params.min_key_size  = CFG_BLE_SEC_PARAM_MIN_KEY_SIZE;
+            sec_params.max_key_size  = CFG_BLE_SEC_PARAM_MAX_KEY_SIZE;
 
-            ASSERT_STATUS_RET_VOID(sd_ble_gap_sec_params_reply(nRF51Gap::getInstance().getConnectionHandle(),
-                                                               BLE_GAP_SEC_STATUS_SUCCESS, &sec_params));
+            ble_gap_sec_keyset_t sec_keyset = {0};
+
+            ASSERT_STATUS_RET_VOID(sd_ble_gap_sec_params_reply(nRF51Gap::getInstance().getConnectionHandle(), BLE_GAP_SEC_STATUS_SUCCESS, &sec_params, &sec_keyset));
         }
         break;
 
         case BLE_GAP_EVT_TIMEOUT:
-            if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT) {
+            if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISING) {
                 nRF51Gap::getInstance().processEvent(GapEvents::GAP_EVENT_TIMEOUT);
             }
             break;
--- a/nRF51GattServer.cpp	Wed Apr 15 09:24:27 2015 +0100
+++ b/nRF51GattServer.cpp	Thu Apr 30 08:34:37 2015 +0100
@@ -119,31 +119,38 @@
     @brief  Reads the value of a characteristic, based on the service
             and characteristic index fields
 
-    @param[in]  charHandle
+    @param[in]  attributeHandle
                 The handle of the GattCharacteristic to read from
     @param[in]  buffer
                 Buffer to hold the the characteristic's value
                 (raw byte array in LSB format)
-    @param[in]  len
-                The number of bytes read into the buffer
+    @param[in/out] len
+                input:  Length in bytes to be read.
+                output: Total length of attribute value upon successful return.
 
     @returns    ble_error_t
 
     @retval     BLE_ERROR_NONE
                 Everything executed properly
-
-    @section EXAMPLE
-
-    @code
-
-    @endcode
 */
 /**************************************************************************/
-ble_error_t nRF51GattServer::readValue(GattAttribute::Handle_t charHandle, uint8_t buffer[], uint16_t *const lengthP)
+ble_error_t nRF51GattServer::readValue(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
+{
+    return readValue(BLE_CONN_HANDLE_INVALID, attributeHandle, buffer, lengthP);
+}
+
+ble_error_t nRF51GattServer::readValue(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
 {
+    ble_gatts_value_t value = {
+        .len     = *lengthP,
+        .offset  = 0,
+        .p_value = buffer,
+    };
+
     ASSERT( ERROR_NONE ==
-            sd_ble_gatts_value_get(nrfCharacteristicHandles[charHandle].value_handle, 0, lengthP, buffer),
+            sd_ble_gatts_value_get(connectionHandle, nrfCharacteristicHandles[attributeHandle].value_handle, &value),
             BLE_ERROR_PARAM_OUT_OF_RANGE);
+    *lengthP = value.len;
 
     return BLE_ERROR_NONE;
 }
@@ -165,52 +172,50 @@
 
     @retval     BLE_ERROR_NONE
                 Everything executed properly
-
-    @section EXAMPLE
-
-    @code
-
-    @endcode
 */
 /**************************************************************************/
-ble_error_t nRF51GattServer::updateValue(GattAttribute::Handle_t charHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
+ble_error_t nRF51GattServer::updateValue(GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
+{
+    return updateValue(BLE_CONN_HANDLE_INVALID, attributeHandle, buffer, len, localOnly);
+}
+
+ble_error_t nRF51GattServer::updateValue(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
 {
     uint16_t gapConnectionHandle = nRF51Gap::getInstance().getConnectionHandle();
     ble_error_t returnValue = BLE_ERROR_NONE;
 
+    ble_gatts_value_t value = {
+        .len     = len,
+        .offset  = 0,
+        .p_value = const_cast<uint8_t *>(buffer),
+    };
+
     if (localOnly) {
         /* Only update locally regardless of notify/indicate */
         ASSERT_INT( ERROR_NONE,
-                    sd_ble_gatts_value_set(nrfCharacteristicHandles[charHandle].value_handle, 0, &len, buffer),
+                    sd_ble_gatts_value_set(connectionHandle, nrfCharacteristicHandles[attributeHandle].value_handle, &value),
                     BLE_ERROR_PARAM_OUT_OF_RANGE );
-		return BLE_ERROR_NONE;
+        return BLE_ERROR_NONE;
     }
 
-    if ((p_characteristics[charHandle]->getProperties() &
-         (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE |
-          GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)) &&
-        (gapConnectionHandle != BLE_CONN_HANDLE_INVALID)) {
+    if ((p_characteristics[attributeHandle]->getProperties() & (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)) &&
+        (gapConnectionHandle != connectionHandle)) {
         /* HVX update for the characteristic value */
         ble_gatts_hvx_params_t hvx_params;
 
-        hvx_params.handle = nrfCharacteristicHandles[charHandle].value_handle;
+        hvx_params.handle = nrfCharacteristicHandles[attributeHandle].value_handle;
         hvx_params.type   =
-            (p_characteristics[charHandle]->getProperties() &
-             GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)  ?
-            BLE_GATT_HVX_NOTIFICATION : BLE_GATT_HVX_INDICATION;
+            (p_characteristics[attributeHandle]->getProperties() & GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) ? BLE_GATT_HVX_NOTIFICATION : BLE_GATT_HVX_INDICATION;
         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);
 
-        /* ERROR_INVALID_STATE, ERROR_BUSY, ERROR_GATTS_SYS_ATTR_MISSING and
-         *ERROR_NO_TX_BUFFERS the ATT table has been updated. */
-        if ((error != ERROR_NONE) && (error != ERROR_INVALID_STATE) &&
-                (error != ERROR_BLE_NO_TX_BUFFERS) && (error != ERROR_BUSY) &&
-                (error != ERROR_BLEGATTS_SYS_ATTR_MISSING)) {
+        /* ERROR_INVALID_STATE, ERROR_BUSY, ERROR_GATTS_SYS_ATTR_MISSING and ERROR_NO_TX_BUFFERS the ATT table has been updated. */
+        if ((error != ERROR_NONE) && (error != ERROR_INVALID_STATE) && (error != ERROR_BLE_NO_TX_BUFFERS) && (error != ERROR_BUSY) && (error != ERROR_BLEGATTS_SYS_ATTR_MISSING)) {
             ASSERT_INT( ERROR_NONE,
-                        sd_ble_gatts_value_set(nrfCharacteristicHandles[charHandle].value_handle, 0, &len, buffer),
+                        sd_ble_gatts_value_set(connectionHandle, nrfCharacteristicHandles[attributeHandle].value_handle, &value),
                         BLE_ERROR_PARAM_OUT_OF_RANGE );
         }
 
@@ -222,7 +227,7 @@
         }
     } else {
         ASSERT_INT( ERROR_NONE,
-                    sd_ble_gatts_value_set(nrfCharacteristicHandles[charHandle].value_handle, 0, &len, buffer),
+                    sd_ble_gatts_value_set(connectionHandle, nrfCharacteristicHandles[attributeHandle].value_handle, &value),
                     BLE_ERROR_PARAM_OUT_OF_RANGE );
     }
 
@@ -281,7 +286,7 @@
         }
 
         case BLE_GATTS_EVT_SYS_ATTR_MISSING:
-            sd_ble_gatts_sys_attr_set(gattsEventP->conn_handle, NULL, 0);
+            sd_ble_gatts_sys_attr_set(gattsEventP->conn_handle, NULL, 0, 0);
             return;
 
         case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
--- a/nRF51GattServer.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nRF51GattServer.h	Thu Apr 30 08:34:37 2015 +0100
@@ -21,6 +21,7 @@
 
 #include "blecommon.h"
 #include "ble.h" /* nordic ble */
+#include "Gap.h"
 #include "GattServer.h"
 
 class nRF51GattServer : public GattServer
@@ -33,8 +34,10 @@
 
     /* Functions that must be implemented from GattServer */
     virtual ble_error_t addService(GattService &);
-    virtual ble_error_t readValue(GattAttribute::Handle_t handle, uint8_t buffer[], uint16_t *const lengthP);
+    virtual ble_error_t readValue(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP);
+    virtual ble_error_t readValue(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP);
     virtual ble_error_t updateValue(GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false);
+    virtual ble_error_t updateValue(Gap::Handle_t connectionHandle, GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false);
     virtual ble_error_t initializeGATTDatabase(void);
 
     /* nRF51 Functions */
--- a/nordic-sdk/components/ble/ble_services/ble_dfu/ble_dfu.c	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/ble/ble_services/ble_dfu/ble_dfu.c	Thu Apr 30 08:34:37 2015 +0100
@@ -224,14 +224,20 @@
 static bool is_cccd_configured(ble_dfu_t * p_dfu)
 {
     // Check if the CCCDs are configured.
-    uint16_t cccd_len = BLE_CCCD_VALUE_LEN;
     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->dfu_ctrl_pt_handles.cccd_handle,
-                                               0,
-                                               &cccd_len,
-                                               cccd_val_buf);
+    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)
@@ -387,7 +393,7 @@
  * @param[in] p_dfu     DFU Service Structure.
  * @param[in] p_ble_evt Pointer to the event received from BLE stack.
  */
-static void on_rw_auth_req(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt)
+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;
 
@@ -397,6 +403,12 @@
         (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;
@@ -537,7 +549,7 @@
                 break;
 
             case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
-                on_rw_auth_req(p_dfu, p_ble_evt);
+                on_rw_authorize_req(p_dfu, p_ble_evt);
                 break;
 
             default:
--- a/nordic-sdk/components/ble/ble_services/ble_dfu/ble_dfu.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/ble/ble_services/ble_dfu/ble_dfu.h	Thu Apr 30 08:34:37 2015 +0100
@@ -130,7 +130,7 @@
  *
  * @details This structure contains status information related to the service.
  */
-typedef struct ble_dfu_s
+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). */
@@ -142,7 +142,7 @@
     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. */
-} ble_dfu_t;
+};
 
 /**@brief      DFU service initialization structure.
  *
--- a/nordic-sdk/components/ble/common/ble_advdata.c	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/ble/common/ble_advdata.c	Thu Apr 30 08:34:37 2015 +0100
@@ -122,35 +122,6 @@
 }
 
 
-static uint32_t uint8_array_encode(const uint8_array_t * p_uint8_array,
-                                   uint8_t               adv_type,
-                                   uint8_t             * p_encoded_data,
-                                   uint8_t             * p_len)
-{
-    // Check parameter consistency.
-    if (p_uint8_array->p_data == NULL)
-    {
-        return NRF_ERROR_INVALID_PARAM;
-    }
-
-    // Check for buffer overflow.
-    if ((*p_len) + ADV_DATA_OFFSET + p_uint8_array->size > BLE_GAP_ADV_MAX_SIZE)
-    {
-        return NRF_ERROR_DATA_SIZE;
-    }
-
-    // Encode Length and AD Type.
-    p_encoded_data[(*p_len)++] = 1 + p_uint8_array->size;
-    p_encoded_data[(*p_len)++] = adv_type;
-
-    // Encode array.
-    memcpy(&p_encoded_data[*p_len], p_uint8_array->p_data, p_uint8_array->size);
-    (*p_len) += p_uint8_array->size;
-
-    return NRF_SUCCESS;
-}
-
-
 static uint32_t tx_power_level_encode(int8_t    tx_power_level,
                                       uint8_t * p_encoded_data,
                                       uint8_t * p_len)
@@ -439,18 +410,13 @@
         }
     }
 
-    // Encode flags.
-    if (p_advdata->flags.size > 0)
+    if(p_advdata->flags != 0 )
     {
-        err_code = uint8_array_encode(&p_advdata->flags,
-                                      BLE_GAP_AD_TYPE_FLAGS,
-                                      p_encoded_data,
-                                      p_len);
-        if (err_code != NRF_SUCCESS)
-        {
-            return err_code;
-        }
-    }
+        // 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)
@@ -543,9 +509,8 @@
 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.size == 0)      ||
-        (p_advdata->flags.p_data == NULL) ||
-        ((p_advdata->flags.p_data[0] & BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED) == 0)
+    if (
+        ((p_advdata->flags & BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED) == 0)
        )
     {
         return NRF_ERROR_INVALID_PARAM;
@@ -558,7 +523,7 @@
 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.size > 0)
+    if (p_srdata->flags)
     {
         return NRF_ERROR_INVALID_PARAM;
     }
--- a/nordic-sdk/components/ble/common/ble_advdata.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/ble/common/ble_advdata.h	Thu Apr 30 08:34:37 2015 +0100
@@ -72,7 +72,7 @@
     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_array_t                flags;                               /**< Advertising data Flags field. */
+    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. */
--- a/nordic-sdk/components/ble/device_manager/device_manager.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/ble/device_manager/device_manager.h	Thu Apr 30 08:34:37 2015 +0100
@@ -30,7 +30,7 @@
  *          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
+ *          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.
@@ -79,7 +79,7 @@
  * @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,
+ *          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.
  * @{
@@ -193,7 +193,7 @@
 /**
  * @brief Connection Instance.
  *
- * @details Identifies connection instance for an active device. This instance is allocated by the
+ * @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.
  */
@@ -254,10 +254,9 @@
 /** @brief Security keys. */
 typedef struct dm_sec_keyset
 {
-    union
+    union 
     {
         dm_enc_key_t       * p_enc_key;  /**< Pointer to Device Manager encryption information structure. */
-        ble_gap_enc_info_t * p_enc_info; /**< Pointer to GAP encryption information. */
     } enc_key;
     dm_id_key_t   * p_id_key;            /**< Identity key, or NULL. */
     dm_sign_key_t * p_sign_key;          /**< Signing key, or NULL. */
@@ -294,7 +293,8 @@
  */
 typedef struct
 {
-    uint32_t  len;    /**< Length of data . */
+    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;
 
@@ -364,16 +364,16 @@
  * @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.
+ * @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 api_result_t (*dm_event_cb_t)(dm_handle_t const * p_handle,
-                                      dm_event_t const  * p_event,
-                                      api_result_t        event_result);
+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.
@@ -406,9 +406,9 @@
  */
 typedef enum
 {
-    NOT_ENCRYPTED,                  /**< The link does not security. */
-    ENCRYPTION_IN_PROGRESS, /**< Security is in progress of being established.*/
-    ENCRYPTED              /**< The link is secure.*/
+    NOT_ENCRYPTED,          /**< The link is not secured. */
+    ENCRYPTION_IN_PROGRESS, /**< Link security is being established.*/
+    ENCRYPTED               /**< The link is secure.*/
 } dm_security_status_t;
 /** @} */
 
@@ -423,7 +423,7 @@
  *          - Context Management APIs.
  *          - Utility APIs.
  *
- *          MSCs describe usage of these APIs.
+ *          MSCs describe usage of these APIs.  
  *          See @ref dm_msc.
  * @{
  */
@@ -449,7 +449,7 @@
  *
  * @note It is mandatory that pstorage is initialized before initializing this module.
  */
-api_result_t dm_init(dm_init_param_t const * p_init_param);
+ret_code_t dm_init(dm_init_param_t const * p_init_param);
 
 /**
  * @brief Function for registering the application.
@@ -462,7 +462,7 @@
  *          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.
+ *          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.
@@ -473,8 +473,8 @@
  *
  * @note Currently only one application instance is supported by the module.
  */
-api_result_t dm_register(dm_application_instance_t    * p_appl_instance,
-                         dm_application_param_t const * p_appl_param);
+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.
@@ -521,7 +521,7 @@
  * @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.
  */
-api_result_t dm_security_setup_req(dm_handle_t * p_handle);
+ret_code_t dm_security_setup_req(dm_handle_t * p_handle);
 
 /**
  * @brief Function for reading the status of the security on a link.
@@ -539,7 +539,7 @@
  * @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.
  */
-api_result_t dm_security_status_req(dm_handle_t const * p_handle, dm_security_status_t * p_status);
+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.
@@ -551,7 +551,7 @@
  * @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.
+ *       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
@@ -563,8 +563,8 @@
  *                                 application registration.
  * @retval NRF_ERROR_NULL          If p_handle or p_whitelist is NULL.
  */
-api_result_t dm_whitelist_create(dm_application_instance_t const * p_handle,
-                                 ble_gap_whitelist_t             * p_whitelist);
+ret_code_t dm_whitelist_create(dm_application_instance_t const * p_handle,
+                               ble_gap_whitelist_t             * p_whitelist);
 
 /** @} */
 
@@ -582,8 +582,8 @@
  * @{
  */
 
-api_result_t dm_device_add(dm_handle_t               * p_handle,
-                           dm_device_context_t const * p_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.
@@ -605,7 +605,7 @@
  *       bonded device. The respective events DM_EVT_SERVICE_CONTEXT_DELETED and
  *       DM_EVT_APPL_CONTEXT_DELETED are not notified to the application.
  */
-api_result_t dm_device_delete(dm_handle_t const * p_handle);
+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.
@@ -628,7 +628,7 @@
  *       bonded device. The respective events DM_EVT_SERVICE_CONTEXT_DELETED and
  *       DM_EVT_APPL_CONTEXT_DELETED are not notified to the application.
  */
-api_result_t dm_device_delete_all(dm_application_instance_t const * p_handle);
+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.
@@ -655,8 +655,8 @@
  * @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.
  */
-api_result_t dm_service_context_set(dm_handle_t const          * p_handle,
-                                    dm_service_context_t const * p_context);
+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.
@@ -678,15 +678,15 @@
  * @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.
  */
-api_result_t dm_service_context_get(dm_handle_t const    * p_handle,
-                                    dm_service_context_t * p_context);
+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.
+ *          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.
  *
@@ -698,7 +698,7 @@
  * @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.
  */
-api_result_t dm_service_context_delete(dm_handle_t const * p_handle);
+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.
@@ -728,8 +728,8 @@
  *
  * @note The API returns FEATURE_NOT_ENABLED in case DEVICE_MANAGER_APP_CONTEXT_SIZE is set to zero.
  */
-api_result_t dm_application_context_set(dm_handle_t const              * p_handle,
-                                        dm_application_context_t const * p_context);
+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.
@@ -753,8 +753,8 @@
  * @note The API returns FEATURE_NOT_ENABLED in case DEVICE_MANAGER_APP_CONTEXT_SIZE is set to
  *       zero.
  */
-api_result_t dm_application_context_get(dm_handle_t const        * p_handle,
-                                        dm_application_context_t * p_context);
+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.
@@ -775,7 +775,7 @@
  *
  * @note The API returns FEATURE_NOT_ENABLED if the DEVICE_MANAGER_APP_CONTEXT_SIZE is set to zero.
  */
-api_result_t dm_application_context_delete(dm_handle_t const * p_handle);
+ret_code_t dm_application_context_delete(dm_handle_t const * p_handle);
 
 /** @} */
 
@@ -798,8 +798,8 @@
  *                                 application registration.
  * @retval NRF_ERROR_NULL          If p_handle and/or p_addr is NULL.
  */
-api_result_t dm_application_instance_set(dm_application_instance_t const * p_appl_instance,
-                                         dm_handle_t                     * p_handle);
+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.
@@ -813,8 +813,8 @@
  * @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.
  */
-api_result_t dm_peer_addr_get(dm_handle_t const * p_handle,
-                              ble_gap_addr_t    * p_addr);
+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.
@@ -830,15 +830,15 @@
  * @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
+ * @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.
  */
-api_result_t dm_peer_addr_set(dm_handle_t const    * p_handle,
-                              ble_gap_addr_t const * p_addr);
+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.
@@ -850,16 +850,12 @@
  *
  * @note This routine is permitted before initialization of the module.
  */
-api_result_t dm_handle_initialize(dm_handle_t * p_handle);
+ret_code_t dm_handle_initialize(dm_handle_t * p_handle);
 
 /**
  * @brief Function for getting distributed keys for a device.
  *
- * @details This routine is used to get distributed keys with a bonded device. This API is currently
- *          only available on S120 (GAP Central role).
- *
- * @param[in] p_handle Device Manager handle identifying the peer.
- *
+ * @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.
@@ -868,8 +864,22 @@
  * @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.
  */
-api_result_t dm_distributed_keys_get(dm_handle_t const * p_handle,
-                                     dm_sec_keyset_t   * p_key_dist);
+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);
 
 /** @} */
 /** @} */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nordic-sdk/components/ble/device_manager/device_manager_peripheral.c	Thu Apr 30 08:34:37 2015 +0100
@@ -0,0 +1,2911 @@
+/* Copyright (C) 2013 Nordic Semiconductor. All Rights Reserved.
+ *
+ * The information contained herein is property of Nordic Semiconductor ASA.
+ * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ */
+
+#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 nDM_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/nordic-sdk/components/libraries/bootloader_dfu/dfu_bank_internal.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/libraries/bootloader_dfu/dfu_bank_internal.h	Thu Apr 30 08:34:37 2015 +0100
@@ -46,10 +46,12 @@
 #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 is image write in progress. */
+#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.
--- a/nordic-sdk/components/libraries/bootloader_dfu/dfu_ble_svc.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/libraries/bootloader_dfu/dfu_ble_svc.h	Thu Apr 30 08:34:37 2015 +0100
@@ -26,8 +26,8 @@
  *
  * @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.
+ *       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__
@@ -40,12 +40,13 @@
 #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 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,
+    DFU_BLE_SVC_SET_PEER_DATA = BOOTLOADER_SVC_BASE,    /**< SVC number for the setting of peer data call. */
     BOOTLOADER_SVC_LAST
 };
 
@@ -58,9 +59,10 @@
  */
 typedef struct
 {
-    ble_gap_enc_info_t enc_info;
-    ble_gap_irk_t      irk;
-    ble_gap_addr_t     addr;
+    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
@@ -69,7 +71,7 @@
  * @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.
+ * @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));
 
--- a/nordic-sdk/components/libraries/bootloader_dfu/dfu_init_template.c	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/libraries/bootloader_dfu/dfu_init_template.c	Thu Apr 30 08:34:37 2015 +0100
@@ -88,10 +88,12 @@
            m_extended_packet_length);
 
 /** [DFU init application version] */
-    // In order to support application versioning this check should be updated.
-    // This template allows for any application to be installed however customer could place a
-    // revision number at bottom of application to be verified by bootloader. This could be done at
-    // a relative location to this papplication for example Application start address + 0x0100.
+    // 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.
--- a/nordic-sdk/components/libraries/bootloader_dfu/dfu_types.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/libraries/bootloader_dfu/dfu_types.h	Thu Apr 30 08:34:37 2015 +0100
@@ -45,11 +45,7 @@
 
 #define NRF_UICR_BOOT_START_ADDRESS     (NRF_UICR_BASE + 0x14)                                          /**< Register where the bootloader start address is stored in the UICR register. */
 
-#ifdef S310_STACK
-    #define CODE_REGION_1_START         0x00020000                                                      /**< 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. */
-#else
-    #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. */
-#endif 
+#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. */
@@ -58,8 +54,12 @@
 #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_IMAGE_MAX_SIZE_FULL         (DFU_REGION_TOTAL_SIZE - DFU_APP_DATA_RESERVED)                 /**< Maximum size of a application, excluding save data from the application. */
-#define DFU_IMAGE_MAX_SIZE_BANKED       (((DFU_REGION_TOTAL_SIZE)/2) - DFU_APP_DATA_RESERVED)           /**< Maximum size of a application, excluding save data from the application. */
+#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. */
--- a/nordic-sdk/components/libraries/bootloader_dfu/experimental/dfu_app_handler.c	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/libraries/bootloader_dfu/experimental/dfu_app_handler.c	Thu Apr 30 08:34:37 2015 +0100
@@ -73,9 +73,9 @@
     err_code = dm_distributed_keys_get(&m_dm_handle, &key_set);
     APP_ERROR_CHECK(err_code);
 
-    m_peer_data.addr     = key_set.keys_central.p_id_key->id_addr_info;
-    m_peer_data.enc_info = *key_set.keys_central.enc_key.p_enc_info;
-    m_peer_data.irk      = key_set.keys_central.p_id_key->id_info;
+    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;
 
     err_code = dfu_ble_svc_set_peer_data(&m_peer_data);
     APP_ERROR_CHECK(err_code);
--- a/nordic-sdk/components/libraries/crc16/crc16.h	Wed Apr 15 09:24:27 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is property of Nordic Semiconductor ASA.
- * Terms and conditions of usage are described in detail in NORDIC
- * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
- *
- * Licensees are granted free, non-transferable use of the information. NO
- * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
- * the file.
- *
- */
- 
-/** @file
- *
- * @defgroup crc_compute CRC compute
- * @{
- * @ingroup hci_transport
- *
- * @brief    This module implements the CRC-16 calculation in the blocks.
- */
- 
-#ifndef CRC16_H__
-#define CRC16_H__
-
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**@brief Function for calculating CRC-16 in blocks.
- *
- * Feed each consecutive data block into this function, along with the current value of p_crc as 
- * returned by the previous call of this function. The first call of this function should pass NULL 
- * as the initial value of the crc in p_crc.
- *
- * @param[in] p_data The input data block for computation.
- * @param[in] size   The size of the input data block in bytes.
- * @param[in] p_crc  The previous calculated CRC-16 value or NULL if first call.  
- *
- * @return The updated CRC-16 value, based on the input supplied.
- */
-uint16_t crc16_compute(const uint8_t * p_data, uint32_t size, const uint16_t * p_crc);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif // CRC16_H__
- 
-/** @} */
\ No newline at end of file
--- a/nordic-sdk/components/libraries/gpiote/app_gpiote.c	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/libraries/gpiote/app_gpiote.c	Thu Apr 30 08:34:37 2015 +0100
@@ -94,8 +94,8 @@
         if (((1 << i) & m_enabled_users_mask) != 0)
         {
             uint32_t transition_pins;
-            uint32_t event_low_to_high;
-            uint32_t event_high_to_low;
+            uint32_t event_low_to_high = 0;
+            uint32_t event_high_to_low = 0;
 
             // Find set of pins on which there has been a transition.
             transition_pins = (pins_state ^ ~p_user->sense_high_pins) & p_user->pins_mask;
@@ -103,29 +103,33 @@
             // Toggle SENSE level for all pins that have changed state.
             sense_level_toggle(p_user, transition_pins);
 
-            // Second read after setting sense.
+            // Second read for this user after setting sense.
+            // Level changes for previous processed users would trigger a pending interrupt.
             // Check if any pins have changed while serving this interrupt.
-            pins_changed = NRF_GPIO->IN ^ pins_state;
+            pins_changed = (NRF_GPIO->IN ^ pins_state) & p_user->pins_mask;
             if (pins_changed)
             {
                 // Transition pins detected in late stage.
                 uint32_t late_transition_pins;
+                uint32_t late_pins_state;
 
-                pins_state          |= pins_changed;
+                late_pins_state = pins_state ^ pins_changed;
 
                 // Find set of pins on which there has been a transition.
-                late_transition_pins = (pins_state ^ ~p_user->sense_high_pins) & p_user->pins_mask;
+                late_transition_pins = (late_pins_state ^ ~p_user->sense_high_pins) & p_user->pins_mask;
 
                 // Toggle SENSE level for all pins that have changed state in last phase.
                 sense_level_toggle(p_user, late_transition_pins);
 
                 // Update pins that has changed state since the interrupt occurred.
-                transition_pins |= late_transition_pins;
+                //transition_pins |= late_transition_pins;
+                event_high_to_low = (~late_pins_state & p_user->pins_high_to_low_mask) & late_transition_pins;
+                event_low_to_high = (late_pins_state & p_user->pins_low_to_high_mask) & late_transition_pins;
             }
 
             // Call user event handler if an event has occurred.
-            event_high_to_low = (~pins_state & p_user->pins_high_to_low_mask) & transition_pins;
-            event_low_to_high = (pins_state & p_user->pins_low_to_high_mask) & transition_pins;
+            event_high_to_low |= (~pins_state & p_user->pins_high_to_low_mask) & transition_pins;
+            event_low_to_high |= (pins_state & p_user->pins_low_to_high_mask) & transition_pins;
 
             if ((event_low_to_high | event_high_to_low) != 0)
             {
@@ -133,6 +137,27 @@
             }
         }
     }
+    
+    // Second read after setting sense.
+    // Check if any pins have changed while serving this interrupt.
+//    pins_changed = NRF_GPIO->IN ^ pins_state;
+//    if (pins_changed)
+//    {
+//        // Transition pins detected in late stage.
+//        uint32_t late_transition_pins;
+
+//        pins_state          ^= pins_changed;
+
+//        // Find set of pins on which there has been a transition.
+//        late_transition_pins = (pins_state ^ ~p_user->sense_high_pins) & p_user->pins_mask;
+
+//        // Toggle SENSE level for all pins that have changed state in last phase.
+//        sense_level_toggle(p_user, late_transition_pins);
+
+//        // Update pins that has changed state since the interrupt occurred.
+//        transition_pins |= late_transition_pins;
+//    }
+
 }
 
 
--- a/nordic-sdk/components/libraries/gpiote/app_gpiote.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/libraries/gpiote/app_gpiote.h	Thu Apr 30 08:34:37 2015 +0100
@@ -53,7 +53,7 @@
  *
  * @param[in]   MAX_USERS   Maximum number of GPIOTE users.
  *
- * @return      Required buffer size (in bytes).
+ * @retval      Required buffer size (in bytes).
  */
 #define APP_GPIOTE_BUF_SIZE(MAX_USERS)  ((MAX_USERS) * GPIOTE_USER_NODE_SIZE)
 
@@ -139,7 +139,7 @@
  *
  * @param[in]   user_id                   Id of user to enable.
  *
- * @return      NRF_SUCCESS               On success.
+ * @retval      NRF_SUCCESS               On success.
  * @retval      NRF_ERROR_INVALID_PARAM   Invalid user_id provided, No a valid user.
  * @retval      NRF_ERROR_INALID_STATE    If @ref app_gpiote_init has not been called on the GPIOTE
  *                                        module.
@@ -153,7 +153,7 @@
  *                              the specified user. All bits corresponding to pins in the state
  *                              'high' will have value '1', all others will have value '0'.
  *
- * @return      NRF_SUCCESS               On success.
+ * @retval      NRF_SUCCESS               On success.
  * @retval      NRF_ERROR_INVALID_PARAM   Invalid user_id provided, No a valid user.
  * @retval      NRF_ERROR_INALID_STATE    If @ref app_gpiote_init has not been called on the GPIOTE
  *                                        module.
@@ -167,7 +167,7 @@
  * @param[in] polarity        Specify operation on input that shall trigger IN event.
  * @param[in] event_handler   Event handler invoked on the IN event in the GPIOTE interrupt.
  *
- * @return   NRF_SUCCESS                 On success.
+ * @retval   NRF_SUCCESS                 On success.
  * @retval   NRF_ERROR_INVALID_PARAM     Invalid channel or pin number.
  * @retval   NRF_ERROR_NOT_SUPPORTED     Driver doesn't support IN events.
  */
@@ -178,7 +178,7 @@
 
 /**@brief Function for unregistering event handlers for GPIOTE IN events.
  *
- * @return   NRF_SUCCESS                 On success.
+ * @retval   NRF_SUCCESS                 On success.
  * @retval   NRF_ERROR_NOT_SUPPORTED     Driver doesn't support IN events.
  */
 uint32_t app_gpiote_input_event_handler_unregister(const uint8_t channel);
@@ -187,28 +187,28 @@
  *
  * @param[in] event_handler    Event handler invoked at the end of the GPIOTE interrupt.
  *
- * @return   NRF_SUCCESS                 On success.
+ * @retval   NRF_SUCCESS                 On success.
  * @retval   NRF_ERROR_NOT_SUPPORTED     Driver doesn't support IN events.
  */
 uint32_t app_gpiote_end_irq_event_handler_register(app_gpiote_input_event_handler_t event_handler);
 
 /**@brief Function for unregistering event handler invoked at the end of a GPIOTE interrupt.
  *
- * @return   NRF_SUCCESS                 On success.
+ * @retval   NRF_SUCCESS                 On success.
  * @retval   NRF_ERROR_NOT_SUPPORTED     Driver doesn't support IN events.
  */
 uint32_t app_gpiote_end_irq_event_handler_unregister(void);
 
 /**@brief Function for enabling interrupts in the GPIOTE driver.
  *
- * @return   NRF_SUCCESS                 On success.
+ * @retval   NRF_SUCCESS                 On success.
  * @retval   NRF_ERROR_NOT_SUPPORTED     Driver doesn't support.
  */
 uint32_t app_gpiote_enable_interrupts(void);
 
 /**@brief Function for disabling interrupts in the GPIOTE driver.
  *
- * @return   NRF_SUCCESS                 On success.
+ * @retval   NRF_SUCCESS                 On success.
  * @retval   NRF_ERROR_NOT_SUPPORTED     Driver doesn't support.
  */
 uint32_t app_gpiote_disable_interrupts(void);
--- a/nordic-sdk/components/libraries/scheduler/app_scheduler.c	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/libraries/scheduler/app_scheduler.c	Thu Apr 30 08:34:37 2015 +0100
@@ -35,13 +35,6 @@
 static uint16_t         m_queue_event_size;     /**< Maximum event size in queue. */
 static uint16_t         m_queue_size;           /**< Number of queue entries. */
 
-/**@brief Macro for checking if a queue is full. */
-#define APP_SCHED_QUEUE_FULL() (next_index(m_queue_end_index) == m_queue_start_index)
-
-/**@brief Macro for checking if a queue is empty. */
-#define APP_SCHED_QUEUE_EMPTY() (m_queue_end_index == m_queue_start_index)
-
-
 /**@brief Function for incrementing a queue index, and handle wrap-around.
  *
  * @param[in]   index   Old index.
@@ -54,6 +47,26 @@
 }
 
 
+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);
--- a/nordic-sdk/components/libraries/scheduler/app_scheduler.h	Wed Apr 15 09:24:27 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,152 +0,0 @@
-/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is property of Nordic Semiconductor ASA.
- * Terms and conditions of usage are described in detail in NORDIC
- * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
- *
- * Licensees are granted free, non-transferable use of the information. NO
- * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
- * the file.
- *
- */
-
-/** @file
- *
- * @defgroup app_scheduler Scheduler
- * @{
- * @ingroup app_common
- *
- * @brief The scheduler is used for transferring execution from the interrupt context to the main
- *        context.
- *
- * @details See @ref seq_diagrams_sched for sequence diagrams illustrating the flow of events
- *          when using the Scheduler.
- *
- * @section app_scheduler_req Requirements:
- *
- * @subsection main_context_logic Logic in main context:
- *
- *   - Define an event handler for each type of event expected.
- *   - Initialize the scheduler by calling the APP_SCHED_INIT() macro before entering the
- *     application main loop.
- *   - Call app_sched_execute() from the main loop each time the application wakes up because of an
- *     event (typically when sd_app_evt_wait() returns).
- *
- * @subsection int_context_logic Logic in interrupt context:
- *
- *   - In the interrupt handler, call app_sched_event_put()
- *     with the appropriate data and event handler. This will insert an event into the
- *     scheduler's queue. The app_sched_execute() function will pull this event and call its
- *     handler in the main context.
- *
- * @if (SD_S110 && !SD_S310)
- * For an example usage of the scheduler, see the implementations of
- * @ref ble_sdk_app_hids_mouse and @ref ble_sdk_app_hids_keyboard.
- * @endif
- *
- * @image html scheduler_working.jpg The high level design of the scheduler
- */
-
-#ifndef APP_SCHEDULER_H__
-#define APP_SCHEDULER_H__
-
-#include <stdint.h>
-#include "app_error.h"
-
-#define APP_SCHED_EVENT_HEADER_SIZE 8       /**< Size of app_scheduler.event_header_t (only for use inside APP_SCHED_BUF_SIZE()). */
-
-/**@brief Compute number of bytes required to hold the scheduler buffer.
- *
- * @param[in] EVENT_SIZE   Maximum size of events to be passed through the scheduler.
- * @param[in] QUEUE_SIZE   Number of entries in scheduler queue (i.e. the maximum number of events
- *                         that can be scheduled for execution).
- *
- * @return    Required scheduler buffer size (in bytes).
- */
-#define APP_SCHED_BUF_SIZE(EVENT_SIZE, QUEUE_SIZE)                                                 \
-            (((EVENT_SIZE) + APP_SCHED_EVENT_HEADER_SIZE) * ((QUEUE_SIZE) + 1))
-            
-/**@brief Scheduler event handler type. */
-typedef void (*app_sched_event_handler_t)(void * p_event_data, uint16_t event_size);
-
-/**@brief Macro for initializing the event scheduler.
- *
- * @details It will also handle dimensioning and allocation of the memory buffer required by the
- *          scheduler, making sure the buffer is correctly aligned.
- *
- * @param[in] EVENT_SIZE   Maximum size of events to be passed through the scheduler.
- * @param[in] QUEUE_SIZE   Number of entries in scheduler queue (i.e. the maximum number of events
- *                         that can be scheduled for execution).
- *
- * @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, e.g. to do a reinitialization).
- */
-#define APP_SCHED_INIT(EVENT_SIZE, QUEUE_SIZE)                                                     \
-    do                                                                                             \
-    {                                                                                              \
-        static uint32_t APP_SCHED_BUF[CEIL_DIV(APP_SCHED_BUF_SIZE((EVENT_SIZE), (QUEUE_SIZE)),     \
-                                               sizeof(uint32_t))];                                 \
-        uint32_t ERR_CODE = app_sched_init((EVENT_SIZE), (QUEUE_SIZE), APP_SCHED_BUF);             \
-        APP_ERROR_CHECK(ERR_CODE);                                                                 \
-    } while (0)
-
-/**@brief Function for initializing the Scheduler.
- *
- * @details It must be called before entering the main loop.
- *
- * @param[in]   max_event_size   Maximum size of events to be passed through the scheduler.
- * @param[in]   queue_size       Number of entries in scheduler queue (i.e. the maximum number of
- *                               events that can be scheduled for execution).
- * @param[in]   p_evt_buffer   Pointer to memory buffer for holding the scheduler queue. It must
- *                               be dimensioned using the APP_SCHED_BUFFER_SIZE() macro. The buffer
- *                               must be aligned to a 4 byte boundary.
- *
- * @note Normally initialization should be done using the APP_SCHED_INIT() macro, as that will both
- *       allocate the scheduler buffer, and also align the buffer correctly.
- *
- * @retval      NRF_SUCCESS               Successful initialization.
- * @retval      NRF_ERROR_INVALID_PARAM   Invalid parameter (buffer not aligned to a 4 byte
- *                                        boundary).
- */
-uint32_t app_sched_init(uint16_t max_event_size, uint16_t queue_size, void * p_evt_buffer);
-
-/**@brief Function for executing all scheduled events.
- *
- * @details This function must be called from within the main loop. It will execute all events
- *          scheduled since the last time it was called.
- */
-void app_sched_execute(void);
-
-/**@brief Function for scheduling an event.
- *
- * @details Puts an event into the event queue.
- *
- * @param[in]   p_event_data   Pointer to event data to be scheduled.
- * @param[in]   event_size   Size of event data to be scheduled.
- * @param[in]   handler        Event handler to receive the event.
- *
- * @return      NRF_SUCCESS on success, otherwise an error code.
- */
-uint32_t app_sched_event_put(void *                    p_event_data,
-                             uint16_t                  event_size,
-                             app_sched_event_handler_t handler);
-
-#ifdef APP_SCHEDULER_WITH_PAUSE
-/**@brief A function to pause the scheduler.
- *
- * @details When the scheduler is paused events are not pulled from the scheduler queue for
- *          processing. The function can be called multiple times. To unblock the scheduler the
- *          function @ref app_sched_resume has to be called the same number of times.
- */
-void app_sched_pause(void);
-
-/**@brief A function to resume a scheduler.
- *
- * @details To unblock the scheduler this function has to be called the same number of times as
- *          @ref app_sched_pause function.
- */
-void app_sched_resume(void);
-#endif
-#endif // APP_SCHEDULER_H__
-
-/** @} */
\ No newline at end of file
--- a/nordic-sdk/components/libraries/util/app_error.c	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/libraries/util/app_error.c	Thu Apr 30 08:34:37 2015 +0100
@@ -53,7 +53,7 @@
     NVIC_SystemReset();
 #else
     
-#ifdef BSP_DEFINES_ONLY
+#ifdef BSP_DEFINES_ONLY 
     LEDS_ON(LEDS_MASK);
 #else
     UNUSED_VARIABLE(bsp_indication_set(BSP_INDICATE_FATAL_ERROR));
--- a/nordic-sdk/components/libraries/util/app_error.h	Wed Apr 15 09:24:27 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,92 +0,0 @@
-/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is property of Nordic Semiconductor ASA.
- * Terms and conditions of usage are described in detail in NORDIC
- * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
- *
- * Licensees are granted free, non-transferable use of the information. NO
- * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
- * the file.
- *
- */
- 
-/** @file
- *
- * @defgroup app_error Common application error handler
- * @{
- * @ingroup app_common
- *
- * @brief Common application error handler and macros for utilizing a common error handler.
- */
-
-#ifndef APP_ERROR_H__
-#define APP_ERROR_H__
-
-#include <stdint.h>
-#include <stdbool.h>
-#include "nrf_error.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**@brief Function for error handling, which is called when an error has occurred. 
- *
- * @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. 
- */
-void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name);
-
-#ifdef __cplusplus
-}
-#endif
-
-/**@brief Macro for calling error handler function. 
- *
- * @param[in] ERR_CODE Error code supplied to the error handler.
- */
-#ifdef DEBUG
-#define APP_ERROR_HANDLER(ERR_CODE)                         \
-    do                                                      \
-    {                                                       \
-        app_error_handler((ERR_CODE), __LINE__, (uint8_t*) __FILE__);  \
-    } while (0)
-#else
-#define APP_ERROR_HANDLER(ERR_CODE)                         \
-    do                                                      \
-    {                                                       \
-        app_error_handler((ERR_CODE), 0, 0);  \
-    } while (0)
-#endif
-/**@brief Macro for calling error handler function if supplied error code any other than NRF_SUCCESS. 
- *
- * @param[in] ERR_CODE Error code supplied to the error handler.
- */    
-#define APP_ERROR_CHECK(ERR_CODE)                           \
-    do                                                      \
-    {                                                       \
-        const uint32_t LOCAL_ERR_CODE = (ERR_CODE);         \
-        if (LOCAL_ERR_CODE != NRF_SUCCESS)                  \
-        {                                                   \
-            APP_ERROR_HANDLER(LOCAL_ERR_CODE);              \
-        }                                                   \
-    } while (0)    
-    
-/**@brief Macro for calling error handler function if supplied boolean value is false. 
- *
- * @param[in] BOOLEAN_VALUE Boolean value to be evaluated.
- */
-#define APP_ERROR_CHECK_BOOL(BOOLEAN_VALUE)                   \
-    do                                                        \
-    {                                                         \
-        const uint32_t LOCAL_BOOLEAN_VALUE = (BOOLEAN_VALUE); \
-        if (!LOCAL_BOOLEAN_VALUE)                             \
-        {                                                     \
-            APP_ERROR_HANDLER(0);                             \
-        }                                                     \
-    } while (0)        
-
-#endif // APP_ERROR_H__
-
-/** @} */
\ No newline at end of file
--- a/nordic-sdk/components/libraries/util/app_util.h	Wed Apr 15 09:24:27 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,232 +0,0 @@
-/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is property of Nordic Semiconductor ASA.
- * Terms and conditions of usage are described in detail in NORDIC
- * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
- *
- * Licensees are granted free, non-transferable use of the information. NO
- * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
- * the file.
- *
- */
-
-/** @file
- *
- * @defgroup app_util Utility Functions and Definitions
- * @{
- * @ingroup app_common
- *
- * @brief Various types and definitions available to all applications.
- */
-
-#ifndef APP_UTIL_H__
-#define APP_UTIL_H__
-
-#include <stdint.h>
-#include <stdbool.h>
-#include "compiler_abstraction.h"
-
-enum
-{
-    UNIT_0_625_MS = 625,                                /**< Number of microseconds in 0.625 milliseconds. */
-    UNIT_1_25_MS  = 1250,                               /**< Number of microseconds in 1.25 milliseconds. */
-    UNIT_10_MS    = 10000                               /**< Number of microseconds in 10 milliseconds. */
-};
-
-/**@brief Macro for doing static (i.e. compile time) assertion.
- *
- * @note If the assertion fails when compiling using Keil, the compiler will report error message
- *       "error: #94: the size of an array must be greater than zero" (while gcc will list the
- *       symbol static_assert_failed, making the error message more readable).
- *       If the supplied expression can not be evaluated at compile time, Keil will report
- *       "error: #28: expression must have a constant value".
- *
- * @note The macro is intentionally implemented not using do while(0), allowing it to be used
- *       outside function blocks (e.g. close to global type- and variable declarations).
- *       If used in a code block, it must be used before any executable code in this block.
- *
- * @param[in]   EXPR   Constant expression to be verified.
- */
-
-#if defined(__GNUC__)
-#define STATIC_ASSERT(EXPR) typedef char __attribute__((unused)) static_assert_failed[(EXPR) ? 1 : -1]
-#else
-#define STATIC_ASSERT(EXPR) typedef char static_assert_failed[(EXPR) ? 1 : -1]
-#endif
-
-
-/**@brief type for holding an encoded (i.e. little endian) 16 bit unsigned integer. */
-typedef uint8_t uint16_le_t[2];
-
-/**@brief type for holding an encoded (i.e. little endian) 32 bit unsigned integer. */
-typedef uint8_t uint32_le_t[4];
-
-/**@brief Byte array type. */
-typedef struct
-{
-    uint16_t  size;                 /**< Number of array entries. */
-    uint8_t * p_data;               /**< Pointer to array entries. */
-} uint8_array_t;
-    
-/**@brief Perform rounded integer division (as opposed to truncating the result).
- *
- * @param[in]   A   Numerator.
- * @param[in]   B   Denominator.
- *
- * @return      Rounded (integer) result of dividing A by B.
- */
-#define ROUNDED_DIV(A, B) (((A) + ((B) / 2)) / (B))
-
-/**@brief Check if the integer provided is a power of two.
- *
- * @param[in]   A   Number to be tested.
- *
- * @return      true if value is power of two.
- * @return      false if value not power of two.
- */
-#define IS_POWER_OF_TWO(A) ( ((A) != 0) && ((((A) - 1) & (A)) == 0) )
-
-/**@brief To convert milliseconds to ticks.
- * @param[in] TIME          Number of milliseconds to convert.
- * @param[in] RESOLUTION    Unit to be converted to in [us/ticks].
- */
-#define MSEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000) / (RESOLUTION))
-
-
-/**@brief Perform integer division, making sure the result is rounded up.
- *
- * @details One typical use for this is to compute the number of objects with size B is needed to
- *          hold A number of bytes.
- *
- * @param[in]   A   Numerator.
- * @param[in]   B   Denominator.
- *
- * @return      Integer result of dividing A by B, rounded up.
- */
-#define CEIL_DIV(A, B)      \
-    /*lint -save -e573 */   \
-    ((((A) - 1) / (B)) + 1) \
-    /*lint -restore */
-
-/**@brief Function for encoding a uint16 value.
- *
- * @param[in]   value            Value to be encoded.
- * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
- *
- * @return      Number of bytes written.
- */
-static __INLINE uint8_t uint16_encode(uint16_t value, uint8_t * p_encoded_data)
-{
-    p_encoded_data[0] = (uint8_t) ((value & 0x00FF) >> 0);
-    p_encoded_data[1] = (uint8_t) ((value & 0xFF00) >> 8);
-    return sizeof(uint16_t);
-}
-    
-/**@brief Function for encoding a uint32 value.
- *
- * @param[in]   value            Value to be encoded.
- * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
- *
- * @return      Number of bytes written.
- */
-static __INLINE uint8_t uint32_encode(uint32_t value, uint8_t * p_encoded_data)
-{
-    p_encoded_data[0] = (uint8_t) ((value & 0x000000FF) >> 0);
-    p_encoded_data[1] = (uint8_t) ((value & 0x0000FF00) >> 8);
-    p_encoded_data[2] = (uint8_t) ((value & 0x00FF0000) >> 16);
-    p_encoded_data[3] = (uint8_t) ((value & 0xFF000000) >> 24);
-    return sizeof(uint32_t);
-}
-
-/**@brief Function for decoding a uint16 value.
- *
- * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
- *
- * @return      Decoded value.
- */
-static __INLINE uint16_t uint16_decode(const uint8_t * p_encoded_data)
-{
-        return ( (((uint16_t)((uint8_t *)p_encoded_data)[0])) | 
-                 (((uint16_t)((uint8_t *)p_encoded_data)[1]) << 8 ));
-}
-
-/**@brief Function for decoding a uint32 value.
- *
- * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
- *
- * @return      Decoded value.
- */
-static __INLINE uint32_t uint32_decode(const uint8_t * p_encoded_data)
-{
-    return ( (((uint32_t)((uint8_t *)p_encoded_data)[0]) << 0)  |
-             (((uint32_t)((uint8_t *)p_encoded_data)[1]) << 8)  |
-             (((uint32_t)((uint8_t *)p_encoded_data)[2]) << 16) |
-             (((uint32_t)((uint8_t *)p_encoded_data)[3]) << 24 ));
-}
-    
-/** @brief Function for converting the input voltage (in milli volts) into percentage of 3.0 Volts.
- *
- *  @details The calculation is based on a linearized version of the battery's discharge
- *           curve. 3.0V returns 100% battery level. The limit for power failure is 2.1V and
- *           is considered to be the lower boundary.
- *
- *           The discharge curve for CR2032 is non-linear. In this model it is split into
- *           4 linear sections:
- *           - Section 1: 3.0V - 2.9V = 100% - 42% (58% drop on 100 mV)
- *           - Section 2: 2.9V - 2.74V = 42% - 18% (24% drop on 160 mV)
- *           - Section 3: 2.74V - 2.44V = 18% - 6% (12% drop on 300 mV)
- *           - Section 4: 2.44V - 2.1V = 6% - 0% (6% drop on 340 mV)
- *
- *           These numbers are by no means accurate. Temperature and
- *           load in the actual application is not accounted for!
- *
- *  @param[in] mvolts The voltage in mV
- *
- *  @return    Battery level in percent.
-*/
-static __INLINE uint8_t battery_level_in_percent(const uint16_t mvolts)
-{
-    uint8_t battery_level;
-
-    if (mvolts >= 3000)
-    {
-        battery_level = 100;
-    }
-    else if (mvolts > 2900)
-    {
-        battery_level = 100 - ((3000 - mvolts) * 58) / 100;
-    }
-    else if (mvolts > 2740)
-    {
-        battery_level = 42 - ((2900 - mvolts) * 24) / 160;
-    }
-    else if (mvolts > 2440)
-    {
-        battery_level = 18 - ((2740 - mvolts) * 12) / 300;
-    }
-    else if (mvolts > 2100)
-    {
-        battery_level = 6 - ((2440 - mvolts) * 6) / 340;
-    }
-    else
-    {
-        battery_level = 0;
-    }
-
-    return battery_level;
-}
-
-/**@brief Function for checking if a pointer value is aligned to a 4 byte boundary.
- *
- * @param[in]   p   Pointer value to be checked.
- *
- * @return      TRUE if pointer is aligned to a 4 byte boundary, FALSE otherwise.
- */
-static __INLINE bool is_word_aligned(void * p)
-{
-    return (((uintptr_t)p & 0x03) == 0);
-}
-
-#endif // APP_UTIL_H__
-
-/** @} */
\ No newline at end of file
--- a/nordic-sdk/components/libraries/util/app_util_platform.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/libraries/util/app_util_platform.h	Thu Apr 30 08:34:37 2015 +0100
@@ -32,11 +32,14 @@
 /**@brief The interrupt priorities available to the application while the SoftDevice is active. */
 typedef enum
 {
-    APP_IRQ_PRIORITY_HIGH = 1,
 #ifndef SOFTDEVICE_PRESENT
-    APP_IRQ_PRIORITY_MID  = 2,
+    APP_IRQ_PRIORITY_HIGHEST = 0,
 #endif
-    APP_IRQ_PRIORITY_LOW  = 3
+    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. */
--- a/nordic-sdk/components/libraries/util/sdk_errors.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/libraries/util/sdk_errors.h	Thu Apr 30 08:34:37 2015 +0100
@@ -94,7 +94,7 @@
  *          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 api_result_t;
+typedef uint32_t ret_code_t;
 /** @} */
 /** @} */
 
--- a/nordic-sdk/components/softdevice/common/softdevice_handler/ble_stack_handler_types.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/common/softdevice_handler/ble_stack_handler_types.h	Thu Apr 30 08:34:37 2015 +0100
@@ -30,7 +30,6 @@
 #include "ble.h"
 #include "nrf_sdm.h"
 #include "app_error.h"
-#include "app_scheduler.h"
 #include "app_util.h"
 
 #ifdef __cplusplus
--- a/nordic-sdk/components/softdevice/common/softdevice_handler/softdevice_handler.c	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/common/softdevice_handler/softdevice_handler.c	Thu Apr 30 08:34:37 2015 +0100
@@ -29,22 +29,18 @@
 
 static softdevice_evt_schedule_func_t m_evt_schedule_func;              /**< Pointer to function for propagating SoftDevice events to the scheduler. */
 
-#if defined (BLE_STACK_SUPPORT_REQD) || defined (ANT_STACK_SUPPORT_REQD)
-// The following two definition is needed only if ANT or BLE events are needed to be pulled from the stack.
-static uint8_t *                      m_evt_buffer;                     /**< Buffer for receiving events from the SoftDevice. */
-#endif
-
-#ifdef BLE_STACK_SUPPORT_REQD
-static uint16_t                       m_ble_evt_buffer_size;            /**< Size of BLE event buffer. */
-#endif
-
 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
 
@@ -118,7 +114,7 @@
             // Pull event from stack
             uint16_t evt_len = m_ble_evt_buffer_size;
 
-            err_code = sd_ble_evt_get(m_evt_buffer, &evt_len);
+            err_code = sd_ble_evt_get(mp_ble_evt_buffer, &evt_len);
             if (err_code == NRF_ERROR_NOT_FOUND)
             {
                 no_more_ble_evts = true;
@@ -130,7 +126,7 @@
             else
             {
                 // Call application's BLE stack event handler.
-                m_ble_evt_handler((ble_evt_t *)m_evt_buffer);
+                m_ble_evt_handler((ble_evt_t *)mp_ble_evt_buffer);
             }
         }
 #endif
@@ -140,9 +136,9 @@
         if (!no_more_ant_evts)
         {
             // Pull event from stack
-            err_code = sd_ant_event_get(&((ant_evt_t *)m_evt_buffer)->channel,
-                                        &((ant_evt_t *)m_evt_buffer)->event,
-                                        ((ant_evt_t *)m_evt_buffer)->evt_buffer);
+            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;
@@ -154,7 +150,7 @@
             else
             {
                 // Call application's ANT stack event handler.
-                m_ant_evt_handler((ant_evt_t *)m_evt_buffer);
+                m_ant_evt_handler(&m_ant_evt_buffer);
             }
         }
 #endif
@@ -191,40 +187,35 @@
 
 
 uint32_t softdevice_handler_init(nrf_clock_lfclksrc_t           clock_source,
-                                 void *                         p_evt_buffer,
-                                 uint16_t                       evt_buffer_size,
+                                 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) || defined (ANT_STACK_SUPPORT_REQD)
+#if defined (BLE_STACK_SUPPORT_REQD)
     // Check that buffer is not NULL.
-    if (p_evt_buffer == NULL)
+    if (p_ble_evt_buffer == NULL)
     {
         return NRF_ERROR_INVALID_PARAM;
     }
     
     // Check that buffer is correctly aligned.
-    if (!is_word_aligned(p_evt_buffer))
+    if (!is_word_aligned(p_ble_evt_buffer))
     {
         return NRF_ERROR_INVALID_PARAM;
     }
 
-    m_evt_buffer = (uint8_t *)p_evt_buffer;
+    mp_ble_evt_buffer     = (uint8_t *)p_ble_evt_buffer;
+    m_ble_evt_buffer_size = ble_evt_buffer_size;
 #else
-    // The variable p_evt_buffer is not needed if neither BLE Stack nor ANT stack support is 
-    // required.
-    UNUSED_PARAMETER(p_evt_buffer);
+    // 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
 
-#if defined (BLE_STACK_SUPPORT_REQD)     
-    m_ble_evt_buffer_size = evt_buffer_size;
-#else
-    // The variable evt_buffer_size is not needed if BLE Stack support is NOT required.
-    UNUSED_PARAMETER(evt_buffer_size);
-#endif
-    
     m_evt_schedule_func = evt_schedule_func;
 
     // Initialize SoftDevice.
--- a/nordic-sdk/components/softdevice/common/softdevice_handler/softdevice_handler.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/common/softdevice_handler/softdevice_handler.h	Thu Apr 30 08:34:37 2015 +0100
@@ -36,7 +36,6 @@
 #include "nordic_common.h"
 #include "nrf_sdm.h"
 #include "app_error.h"
-#include "app_scheduler.h"
 #include "app_util.h"
 #include "ble_stack_handler_types.h"
 #include "ant_stack_handler_types.h"
@@ -59,12 +58,11 @@
  *
  * @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 (if specified).
+ *            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] USE_SCHEDULER    TRUE if the application is using the event scheduler, FALSE
- *                             otherwise.
+ * @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
@@ -72,20 +70,15 @@
  */
 /*lint -emacro(506, SOFTDEVICE_HANDLER_INIT) */ /* Suppress "Constant value Boolean */
 #define SOFTDEVICE_HANDLER_INIT(CLOCK_SOURCE,                                                      \
-                                USE_SCHEDULER)                                                     \
+                                EVT_HANDLER)                                                     \
     do                                                                                             \
     {                                                                                              \
-        static uint32_t EVT_BUFFER[CEIL_DIV(MAX(                                                   \
-                                                MAX(BLE_STACK_EVT_MSG_BUF_SIZE,                    \
-                                                    ANT_STACK_EVT_STRUCT_SIZE),                    \
-                                                SYS_EVT_MSG_BUF_SIZE                               \
-                                               ),                                                  \
-                                            sizeof(uint32_t))];                                    \
+        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),                                         \
-                                           EVT_BUFFER,                                             \
-                                           sizeof(EVT_BUFFER),                                     \
-                                           (USE_SCHEDULER) ? softdevice_evt_schedule : NULL);      \
+                                           BLE_EVT_BUFFER,                                         \
+                                           sizeof(BLE_EVT_BUFFER),                                 \
+                                           EVT_HANDLER);      \
         APP_ERROR_CHECK(ERR_CODE);                                                                 \
     } while (0)
 
@@ -100,13 +93,13 @@
  *             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_evt_buffer        Buffer for holding one stack event. Since heap is not being
+ * @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 neither BLE nor
- *                                 ANT stack support is required.
- * @param[in]  evt_buffer_size     Size of SoftDevice event buffer. This parameter is unused if
+ *                                 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.
@@ -118,8 +111,8 @@
  *                                       boundary) or NULL.
  */
 uint32_t softdevice_handler_init(nrf_clock_lfclksrc_t              clock_source,
-                                 void *                            p_evt_buffer,
-                                 uint16_t                          evt_buffer_size,
+                                 void *                            p_ble_evt_buffer,
+                                 uint16_t                          ble_evt_buffer_size,
                                  softdevice_evt_schedule_func_t    evt_schedule_func);
 
 
@@ -152,16 +145,7 @@
 /**@cond NO_DOXYGEN */
 void intern_softdevice_events_execute(void);
 
-static __INLINE void softdevice_evt_get(void * p_event_data, uint16_t event_size)
-{
-    APP_ERROR_CHECK_BOOL(event_size == 0);
-    intern_softdevice_events_execute();
-}
 
-static __INLINE uint32_t softdevice_evt_schedule(void)
-{
-    return app_sched_event_put(NULL, 0, softdevice_evt_get);
-}
 /**@endcond */
 
 #ifdef __cplusplus
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nordic-sdk/components/softdevice/common/softdevice_handler/softdevice_handler_appsh.c	Thu Apr 30 08:34:37 2015 +0100
@@ -0,0 +1,26 @@
+/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
+ *
+ * The information contained herein is property of Nordic Semiconductor ASA.
+ * Terms and conditions of usage are described in detail in NORDIC
+ * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ */
+
+#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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nordic-sdk/components/softdevice/common/softdevice_handler/softdevice_handler_appsh.h	Thu Apr 30 08:34:37 2015 +0100
@@ -0,0 +1,24 @@
+/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
+ *
+ * The information contained herein is property of Nordic Semiconductor ASA.
+ * Terms and conditions of usage are described in detail in NORDIC
+ * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ */
+
+#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/nordic-sdk/components/softdevice/s110/headers/ble.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/s110/headers/ble.h	Thu Apr 30 08:34:37 2015 +0100
@@ -1,17 +1,46 @@
-/* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is confidential property of Nordic Semiconductor. The use,
- * copying, transfer or disclosure of such information is prohibited except by express written
- * agreement with Nordic Semiconductor.
- *
+/* 
+ * 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.
+ * 
+ *   4. This software must only be used in a processor manufactured by Nordic
+ *   Semiconductor ASA, or in a processor manufactured by a third party that
+ *   is used in combination with a processor manufactured by Nordic Semiconductor.
+ * 
+ * 
+ * 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.
+ * 
  */
+
 /**
   @addtogroup BLE_COMMON BLE SoftDevice Common
   @{
   @defgroup ble_api Events, type definitions and API calls
   @{
 
-  @brief Module independent events, type definitions and API calls for the S110 SoftDevice.
+  @brief Module independent events, type definitions and API calls for the BLE SoftDevice.
 
  */
 
@@ -36,7 +65,7 @@
 {
   SD_BLE_ENABLE = BLE_SVC_BASE,         /**< Enable and initialize the BLE stack */
   SD_BLE_EVT_GET,                       /**< Get an event from the pending events queue. */
-  SD_BLE_TX_BUFFER_COUNT_GET,           /**< Get the total number of available application transmission buffers from the stack. */
+  SD_BLE_TX_BUFFER_COUNT_GET,           /**< Get the total number of available application transmission buffers from the BLE stack. */
   SD_BLE_UUID_VS_ADD,                   /**< Add a Vendor Specific UUID. */
   SD_BLE_UUID_DECODE,                   /**< Decode UUID bytes. */
   SD_BLE_UUID_ENCODE,                   /**< Encode UUID bytes. */
@@ -46,6 +75,16 @@
   SD_BLE_OPT_GET,                       /**< Get a BLE option. */
 };
 
+/**
+ * @brief BLE Module Independent Event IDs.
+ */
+enum BLE_COMMON_EVTS
+{
+  BLE_EVT_TX_COMPLETE  = BLE_EVT_BASE,  /**< Transmission Complete. @ref ble_evt_tx_complete_t */
+  BLE_EVT_USER_MEM_REQUEST,             /**< User Memory request. @ref ble_evt_user_mem_request_t */
+  BLE_EVT_USER_MEM_RELEASE              /**< User Memory release. @ref ble_evt_user_mem_release_t */
+};
+
 /**@brief Common Option IDs.
  * IDs that uniquely identify a common option.
  */
@@ -77,38 +116,28 @@
 /** @addtogroup BLE_COMMON_STRUCTURES Structures
  * @{ */
 
-/**
- * @brief BLE Module Independent Event IDs.
- */
-enum BLE_COMMON_EVTS
-{
-  BLE_EVT_TX_COMPLETE  = BLE_EVT_BASE,  /**< Transmission Complete. */
-  BLE_EVT_USER_MEM_REQUEST,             /**< User Memory request. */
-  BLE_EVT_USER_MEM_RELEASE              /**< User Memory release. */
-};
-
 /**@brief User Memory Block. */
 typedef struct
 {
-  uint8_t*          p_mem;      /**< Pointer to the start of the user memory block. */
+  uint8_t          *p_mem;      /**< Pointer to the start of the user memory block. */
   uint16_t          len;        /**< Length in bytes of the user memory block. */
 } ble_user_mem_block_t;
 
 /**
- * @brief TX complete event.
+ * @brief Event structure for @ref BLE_EVT_TX_COMPLETE.
  */
 typedef struct
 {
   uint8_t count;                        /**< Number of packets transmitted. */
 } ble_evt_tx_complete_t;
 
-/**@brief Event structure for BLE_EVT_USER_MEM_REQUEST. */
+/**@brief Event structure for @ref BLE_EVT_USER_MEM_REQUEST. */
 typedef struct
 {
   uint8_t                     type;     /**< User memory type, see @ref BLE_USER_MEM_TYPES. */
 } ble_evt_user_mem_request_t;
 
-/**@brief Event structure for BLE_EVT_USER_MEM_RELEASE. */
+/**@brief Event structure for @ref BLE_EVT_USER_MEM_RELEASE. */
 typedef struct
 {
   uint8_t                     type;       /**< User memory type, see @ref BLE_USER_MEM_TYPES. */
@@ -119,7 +148,7 @@
 /**@brief Event structure for events not associated with a specific function module. */
 typedef struct
 {
-  uint16_t conn_handle;                 /**< Connection Handle on which this event occured. */
+  uint16_t conn_handle;                 /**< Connection Handle on which this event occurred. */
   union
   {
     ble_evt_tx_complete_t           tx_complete;        /**< Transmission Complete. */
@@ -163,14 +192,17 @@
 /**@brief Mutual exclusion of radio activity and CPU execution.
  *
  *        This option configures the application's access to the CPU when the radio is active. The
- *        application can configure itself to have access to the CPU while the radio is active.
- *        By default, the application will be not able to share CPU time with the SoftDevice
+ *        application can configure itself to be blocked from using the CPU while the radio is
+ *        active. By default, the application will be able to share CPU time with the SoftDevice
  *        during radio activity. This parameter structure is used together with @ref sd_ble_opt_set
  *        to configure the @ref BLE_COMMON_OPT_RADIO_CPU_MUTEX option.
  *
- * @note  Note that the mutual exclusion of radio activity and CPU execution should remain enabled
- *        when running the SoftDevice on hardware affected by PAN #44 "CCM may exceed real time 
- *        requirements"and PAN #45 "AAR may exceed real time requirements".
+ * @note  Note that the application should use this option to configure the SoftDevice to block the
+ *        CPU during radio activity (i.e enable mutual exclusion) when running the SoftDevice on
+ *        hardware affected by PAN #44 "CCM may exceed real time requirements"and PAN #45 "AAR may
+ *        exceed real time requirements".
+ *
+ * @note  Note that when acting as a scanner, the mutex is only enabled for radio TX activity.
  *
  * @note  @ref sd_ble_opt_get is not supported for this option.
  *
@@ -198,7 +230,7 @@
  */
 typedef struct
 {
-  ble_gatts_enable_params_t  gatts_enable_params; /**< GATTS init options @ref ble_gatts_enable_params_t. */  
+  ble_gatts_enable_params_t  gatts_enable_params; /**< GATTS init options @ref ble_gatts_enable_params_t. */
 } ble_enable_params_t;
 
 /** @} */
@@ -206,49 +238,53 @@
 /** @addtogroup BLE_COMMON_FUNCTIONS Functions
  * @{ */
 
-/**@brief Enable the bluetooth stack
+/**@brief Enable the BLE stack
  *
  * @param[in] p_ble_enable_params Pointer to ble_enable_params_t
  *
- * @details This call initializes the bluetooth stack, no other BLE related call can be called before this one has been executed.
+ * @details This call initializes the BLE stack, no other BLE related function can be called before this one.
  *
- * @return @ref NRF_SUCCESS BLE stack has been initialized successfully
+ * @return @ref NRF_SUCCESS BLE the BLE stack has been initialized successfully
+ * @retval @ref NRF_ERROR_INVALID_STATE the BLE stack had already been initialized and cannot be reinitialized.
  * @return @ref NRF_ERROR_INVALID_ADDR Invalid or not sufficiently aligned pointer supplied.
+ * @return @ref NRF_ERROR_INVALID_LENGTH The specified Attribute Table size is either too small or not a multiple of 4.
+ *                                       The minimum acceptable size is defined by @ref BLE_GATTS_ATTR_TAB_SIZE_MIN.
+ * @return @ref NRF_ERROR_NO_MEM         The Attribute Table size is too large. Decrease size in @ref ble_gatts_enable_params_t.
  */
 SVCALL(SD_BLE_ENABLE, uint32_t, sd_ble_enable(ble_enable_params_t * p_ble_enable_params));
 
 /**@brief Get an event from the pending events queue.
  *
- * @param[in] p_dest Pointer to buffer to be filled in with an event, or NULL to retrieve the event length. This buffer <b>must be 4-byte aligned in memory</b>.
+ * @param[out] p_dest Pointer to buffer to be filled in with an event, or NULL to retrieve the event length. This buffer <b>must be 4-byte aligned in memory</b>.
  * @param[in, out] p_len Pointer the length of the buffer, on return it is filled with the event length.
  *
  * @details This call allows the application to pull a BLE event from the BLE stack. The application is signalled that an event is 
- * available from the BLE Stack by the triggering of the SD_EVT_IRQn interrupt (mapped to IRQ 22).
+ * available from the BLE stack by the triggering of the SD_EVT_IRQn interrupt.
  * The application is free to choose whether to call this function from thread mode (main context) or directly from the Interrupt Service Routine
  * that maps to SD_EVT_IRQn. In any case however, and because the BLE stack runs at a higher priority than the application, this function should be called
- * in a loop (until @ref NRF_ERROR_NOT_FOUND is returned) every time SD_EVT_IRQn is raised to ensure that all available events are pulled from the stack. 
+ * in a loop (until @ref NRF_ERROR_NOT_FOUND is returned) every time SD_EVT_IRQn is raised to ensure that all available events are pulled from the BLE stack. 
  * Failure to do so could potentially leave events in the internal queue without the application being aware of this fact.
  * Sizing the p_dest buffer is equally important, since the application needs to provide all the memory necessary for the event to be copied into
  * application memory. If the buffer provided is not large enough to fit the entire contents of the event, @ref NRF_ERROR_DATA_SIZE will be returned
  * and the application can then call again with a larger buffer size.
  * Please note that because of the variable length nature of some events, sizeof(ble_evt_t) will not always be large enough to fit certain events, 
- * and so it is the application's responsability to provide an amount of memory large enough so that the relevant event is copied in full.
+ * and so it is the application's responsibility to provide an amount of memory large enough so that the relevant event is copied in full.
  * The application may "peek" the event length by providing p_dest as a NULL pointer and inspecting the value of *p_len upon return.
  *
  * @note The pointer supplied must be aligned to the extend defined by @ref BLE_EVTS_PTR_ALIGNMENT
  *
- * @return @ref NRF_SUCCESS Event pulled and stored into the supplied buffer.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid or not sufficiently aligned pointer supplied.
- * @return @ref NRF_ERROR_NOT_FOUND No events ready to be pulled.
- * @return @ref NRF_ERROR_DATA_SIZE Event ready but could not fit into the supplied buffer.
+ * @retval ::NRF_SUCCESS Event pulled and stored into the supplied buffer.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid or not sufficiently aligned pointer supplied.
+ * @retval ::NRF_ERROR_NOT_FOUND No events ready to be pulled.
+ * @retval ::NRF_ERROR_DATA_SIZE Event ready but could not fit into the supplied buffer.
  */
-SVCALL(SD_BLE_EVT_GET, uint32_t, sd_ble_evt_get(uint8_t* p_dest, uint16_t *p_len));
+SVCALL(SD_BLE_EVT_GET, uint32_t, sd_ble_evt_get(uint8_t *p_dest, uint16_t *p_len));
 
 
-/**@brief Get the total number of available application transmission buffers in the BLE stack.
+/**@brief Get the total number of available application transmission buffers per link in the BLE stack.
  *
  * @details This call allows the application to obtain the total number of
- *          transmission buffers available for application data. Please note that
+ *          transmission buffers available per link for application data. Please note that
  *          this does not give the number of free buffers, but rather the total amount of them.
  *          The application has two options to handle its own application transmission buffers:
  *          - Use a simple arithmetic calculation: at boot time the application should use this function
@@ -269,17 +305,17 @@
  *          The API functions that <b>may</b> consume an application buffer depending on 
  *          the parameters supplied to them can be found below:
  *
- *          - @ref sd_ble_gattc_write (write witout response only)
+ *          - @ref sd_ble_gattc_write (write without response only)
  *          - @ref sd_ble_gatts_hvx (notifications only)
  *          - @ref sd_ble_l2cap_tx (all packets)
  *
  * @param[out] p_count Pointer to a uint8_t which will contain the number of application transmission buffers upon
  *                     successful return.
  *
- * @return @ref NRF_SUCCESS Number of application transmission buffers retrieved successfully.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_SUCCESS Number of application transmission buffers retrieved successfully.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  */
-SVCALL(SD_BLE_TX_BUFFER_COUNT_GET, uint32_t, sd_ble_tx_buffer_count_get(uint8_t* p_count));
+SVCALL(SD_BLE_TX_BUFFER_COUNT_GET, uint32_t, sd_ble_tx_buffer_count_get(uint8_t *p_count));
 
 
 /**@brief Add a Vendor Specific UUID.
@@ -301,20 +337,20 @@
  *
  * @param[in]  p_vs_uuid    Pointer to a 16-octet (128-bit) little endian Vendor Specific UUID disregarding
  *                          bytes 12 and 13.
- * @param[out] p_uuid_type  Pointer where the type field in @ref ble_uuid_t corresponding to this UUID will be stored.
+ * @param[out] p_uuid_type  Pointer to a uint8_t where the type field in @ref ble_uuid_t corresponding to this UUID will be stored.
  *
- * @return @ref NRF_SUCCESS Successfully added the Vendor Specific UUID.
- * @return @ref NRF_ERROR_INVALID_ADDR If p_vs_uuid or p_uuid_type is NULL or invalid.
- * @return @ref NRF_ERROR_NO_MEM If there are no more free slots for VS UUIDs.
- * @return @ref NRF_ERROR_FORBIDDEN If p_vs_uuid has already been added to the VS UUID table.
+ * @retval ::NRF_SUCCESS Successfully added the Vendor Specific UUID.
+ * @retval ::NRF_ERROR_INVALID_ADDR If p_vs_uuid or p_uuid_type is NULL or invalid.
+ * @retval ::NRF_ERROR_NO_MEM If there are no more free slots for VS UUIDs.
+ * @retval ::NRF_ERROR_FORBIDDEN If p_vs_uuid has already been added to the VS UUID table.
  */
-SVCALL(SD_BLE_UUID_VS_ADD, uint32_t, sd_ble_uuid_vs_add(ble_uuid128_t const * const p_vs_uuid, uint8_t * const p_uuid_type));
+SVCALL(SD_BLE_UUID_VS_ADD, uint32_t, sd_ble_uuid_vs_add(ble_uuid128_t const *p_vs_uuid, uint8_t *p_uuid_type));
 
 
 /** @brief Decode little endian raw UUID bytes (16-bit or 128-bit) into a 24 bit @ref ble_uuid_t structure.
  * 
  * @details The raw UUID bytes excluding bytes 12 and 13 (i.e. bytes 0-11 and 14-15) of p_uuid_le are compared 
- * to the corresponding ones in each entry of the table of vendor specific UUIDs pouplated with @ref sd_ble_uuid_vs_add 
+ * to the corresponding ones in each entry of the table of vendor specific UUIDs populated with @ref sd_ble_uuid_vs_add 
  * to look for a match. If there is such a match, bytes 12 and 13 are returned as p_uuid->uuid and the index 
  * relative to @ref BLE_UUID_TYPE_VENDOR_BEGIN as p_uuid->type. 
  *
@@ -322,57 +358,57 @@
  *
  * @param[in]      uuid_le_len Length in bytes of the buffer pointed to by p_uuid_le (must be 2 or 16 bytes).
  * @param[in]      p_uuid_le   Pointer pointing to little endian raw UUID bytes.
- * @param[in,out]  p_uuid      Pointer to a @ref ble_uuid_t structure to be filled in.
+ * @param[out]  p_uuid      Pointer to a @ref ble_uuid_t structure to be filled in.
  *
- * @return @ref NRF_SUCCESS Successfully decoded into the @ref ble_uuid_t structure.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_INVALID_LENGTH Invalid UUID length.
- * @return @ref NRF_ERROR_NOT_FOUND For a 128-bit UUID, no match in the populated table of UUIDs.
+ * @retval ::NRF_SUCCESS Successfully decoded into the @ref ble_uuid_t structure.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_LENGTH Invalid UUID length.
+ * @retval ::NRF_ERROR_NOT_FOUND For a 128-bit UUID, no match in the populated table of UUIDs.
  */                                                 
-SVCALL(SD_BLE_UUID_DECODE, uint32_t, sd_ble_uuid_decode(uint8_t uuid_le_len, uint8_t const * const p_uuid_le, ble_uuid_t * const p_uuid));
+SVCALL(SD_BLE_UUID_DECODE, uint32_t, sd_ble_uuid_decode(uint8_t uuid_le_len, uint8_t const *p_uuid_le, ble_uuid_t *p_uuid));
 
 
 /** @brief Encode a @ref ble_uuid_t structure into little endian raw UUID bytes (16-bit or 128-bit).
  *
- * @note The pointer to the destination buffer p_uuid_le may be NULL, in which case only the validitiy and size of p_uuid is computed.
+ * @note The pointer to the destination buffer p_uuid_le may be NULL, in which case only the validity and size of p_uuid is computed.
  *
  * @param[in]      p_uuid        Pointer to a @ref ble_uuid_t structure that will be encoded into bytes.
  * @param[out]     p_uuid_le_len Pointer to a uint8_t that will be filled with the encoded length (2 or 16 bytes).
  * @param[out]     p_uuid_le     Pointer to a buffer where the little endian raw UUID bytes (2 or 16) will be stored.
  *
- * @return @ref NRF_SUCCESS Successfully encoded into the buffer.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid UUID type.
+ * @retval ::NRF_SUCCESS Successfully encoded into the buffer.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid UUID type.
  */
-SVCALL(SD_BLE_UUID_ENCODE, uint32_t, sd_ble_uuid_encode(ble_uuid_t const * const p_uuid, uint8_t * const  p_uuid_le_len, uint8_t * const p_uuid_le));
+SVCALL(SD_BLE_UUID_ENCODE, uint32_t, sd_ble_uuid_encode(ble_uuid_t const *p_uuid, uint8_t *p_uuid_le_len, uint8_t *p_uuid_le));
 
 
 /**@brief Get Version Information.
  *
  * @details This call allows the application to get the BLE stack version information.
  *
- * @param[in] p_version Pointer to ble_version_t structure to be filled in.
+ * @param[out] p_version Pointer to a ble_version_t structure to be filled in.
  *
- * @return @ref NRF_SUCCESS  Version information stored successfully.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_BUSY The stack is busy (typically doing a locally-initiated disconnection procedure).
+ * @retval ::NRF_SUCCESS  Version information stored successfully.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_BUSY The BLE stack is busy (typically doing a locally-initiated disconnection procedure).
  */
-SVCALL(SD_BLE_VERSION_GET, uint32_t, sd_ble_version_get(ble_version_t * p_version));
+SVCALL(SD_BLE_VERSION_GET, uint32_t, sd_ble_version_get(ble_version_t *p_version));
 
 
 /**@brief Provide a user memory block.
  *
  * @note This call can only be used as a response to a @ref BLE_EVT_USER_MEM_REQUEST event issued to the application.
  *
- * @param[in] conn_handle                 Connection handle.
- * @param[in] p_block                     Pointer to a user memory block structure.
+ * @param[in] conn_handle Connection handle.
+ * @param[in,out] p_block Pointer to a user memory block structure.
  *
- * @return @ref NRF_SUCCESS               Successfully queued a response to the peer.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
- * @return @ref NRF_ERROR_INVALID_STATE   No execute write request pending.
+ * @retval ::NRF_SUCCESS Successfully queued a response to the peer.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection state or no execute write request pending.
+ * @retval ::NRF_ERROR_BUSY The BLE stack is busy. Retry at later time.
  */
-SVCALL(SD_BLE_USER_MEM_REPLY, uint32_t, sd_ble_user_mem_reply(uint16_t conn_handle, ble_user_mem_block_t *p_block));
-
+SVCALL(SD_BLE_USER_MEM_REPLY, uint32_t, sd_ble_user_mem_reply(uint16_t conn_handle, ble_user_mem_block_t const *p_block));
 
 /**@brief Set a BLE option.
  *
@@ -386,7 +422,7 @@
  * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, check parameter limits and constraints.
  * @retval ::NRF_ERROR_INVALID_STATE Unable to set the parameter at this time.
- * @retval ::NRF_ERROR_BUSY The stack is busy or the previous procedure has not completed.
+ * @retval ::NRF_ERROR_BUSY The BLE stack is busy or the previous procedure has not completed.
  */
 SVCALL(SD_BLE_OPT_SET, uint32_t, sd_ble_opt_set(uint32_t opt_id, ble_opt_t const *p_opt));
 
@@ -403,7 +439,7 @@
  * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, check parameter limits and constraints.
  * @retval ::NRF_ERROR_INVALID_STATE Unable to retrieve the parameter at this time.
- * @retval ::NRF_ERROR_BUSY The stack is busy or the previous procedure has not completed.
+ * @retval ::NRF_ERROR_BUSY The BLE stack is busy or the previous procedure has not completed.
  * @retval ::NRF_ERROR_NOT_SUPPORTED This option is not supported.
  *
  */
--- a/nordic-sdk/components/softdevice/s110/headers/ble_err.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/s110/headers/ble_err.h	Thu Apr 30 08:34:37 2015 +0100
@@ -1,12 +1,40 @@
-/*
- * Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is confidential property of Nordic Semiconductor. The use,
- * copying, transfer or disclosure of such information is prohibited except by express written
- * agreement with Nordic Semiconductor.
- *
+/* 
+ * 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.
+ * 
+ *   4. This software must only be used in a processor manufactured by Nordic
+ *   Semiconductor ASA, or in a processor manufactured by a third party that
+ *   is used in combination with a processor manufactured by Nordic Semiconductor.
+ * 
+ * 
+ * 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.
+ * 
  */
- /**
+
+/**
   @addtogroup BLE_COMMON
   @{
   @addtogroup  nrf_error
@@ -32,6 +60,7 @@
 #define BLE_ERROR_INVALID_CONN_HANDLE    (NRF_ERROR_STK_BASE_NUM+0x002) /**< Invalid connection handle. */
 #define BLE_ERROR_INVALID_ATTR_HANDLE    (NRF_ERROR_STK_BASE_NUM+0x003) /**< Invalid attribute handle. */
 #define BLE_ERROR_NO_TX_BUFFERS          (NRF_ERROR_STK_BASE_NUM+0x004) /**< Buffer capacity exceeded. */
+#define BLE_ERROR_INVALID_ROLE           (NRF_ERROR_STK_BASE_NUM+0x005) /**< Invalid role. */
 /** @} */
 
 
--- a/nordic-sdk/components/softdevice/s110/headers/ble_gap.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/s110/headers/ble_gap.h	Thu Apr 30 08:34:37 2015 +0100
@@ -1,10 +1,39 @@
-/* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is confidential property of Nordic Semiconductor. The use,
- * copying, transfer or disclosure of such information is prohibited except by express written
- * agreement with Nordic Semiconductor.
- *
+/* 
+ * 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.
+ * 
+ *   4. This software must only be used in a processor manufactured by Nordic
+ *   Semiconductor ASA, or in a processor manufactured by a third party that
+ *   is used in combination with a processor manufactured by Nordic Semiconductor.
+ * 
+ * 
+ * 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.
+ * 
  */
+
 /**
   @addtogroup BLE_GAP Generic Access Profile (GAP)
   @{
@@ -18,8 +47,7 @@
 #include "ble_ranges.h"
 #include "nrf_svc.h"
 
-
-/**@addtogroup BLE_GAP_ENUMERATIONS Enumerations 
+/**@addtogroup BLE_GAP_ENUMERATIONS Enumerations
  * @{ */
 
 /**@brief GAP API SVC numbers.
@@ -28,7 +56,7 @@
 {
   SD_BLE_GAP_ADDRESS_SET  = BLE_GAP_SVC_BASE,  /**< Set own Bluetooth Address. */
   SD_BLE_GAP_ADDRESS_GET,                      /**< Get own Bluetooth Address. */
-  SD_BLE_GAP_ADV_DATA_SET,                     /**< Set Advertisement Data. */
+  SD_BLE_GAP_ADV_DATA_SET,                     /**< Set Advertising Data. */
   SD_BLE_GAP_ADV_START,                        /**< Start Advertising. */
   SD_BLE_GAP_ADV_STOP,                         /**< Stop Advertising. */
   SD_BLE_GAP_CONN_PARAM_UPDATE,                /**< Connection Parameter Update. */
@@ -43,12 +71,53 @@
   SD_BLE_GAP_AUTHENTICATE,                     /**< Initiate Pairing/Bonding. */
   SD_BLE_GAP_SEC_PARAMS_REPLY,                 /**< Reply with Security Parameters. */
   SD_BLE_GAP_AUTH_KEY_REPLY,                   /**< Reply with an authentication key. */
+  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_SCAN_START,                       /**< Start Scanning. */
+  SD_BLE_GAP_SCAN_STOP,                        /**< Stop Scanning. */
+  SD_BLE_GAP_CONNECT,                          /**< Connect. */
+  SD_BLE_GAP_CONNECT_CANCEL,                   /**< Cancel ongoing connection procedure. */
+  SD_BLE_GAP_RSSI_GET,                         /**< Get the last RSSI sample. */
 };
-/**@} */
+
+/**@brief GAP Event IDs.
+ * IDs that uniquely identify an event coming from the stack to the application.
+ */
+enum BLE_GAP_EVTS
+{
+  BLE_GAP_EVT_CONNECTED  = BLE_GAP_EVT_BASE,    /**< Connection established. @ref ble_gap_evt_connected_t */
+  BLE_GAP_EVT_DISCONNECTED,                     /**< Disconnected from peer. @ref ble_gap_evt_disconnected_t */
+  BLE_GAP_EVT_CONN_PARAM_UPDATE,                /**< Connection Parameters updated. ble_gap_evt_conn_param_update_t */
+  BLE_GAP_EVT_SEC_PARAMS_REQUEST,               /**< Request to provide security parameters. @ref ble_gap_evt_sec_params_request_t */
+  BLE_GAP_EVT_SEC_INFO_REQUEST,                 /**< Request to provide security information. @ref ble_gap_evt_sec_info_request_t */
+  BLE_GAP_EVT_PASSKEY_DISPLAY,                  /**< Request to display a passkey to the user. @ref ble_gap_evt_passkey_display_t */
+  BLE_GAP_EVT_AUTH_KEY_REQUEST,                 /**< Request to provide an authentication key. @ref ble_gap_evt_auth_key_request_t */
+  BLE_GAP_EVT_AUTH_STATUS,                      /**< Authentication procedure completed with status. @ref ble_gap_evt_auth_status_t */
+  BLE_GAP_EVT_CONN_SEC_UPDATE,                  /**< Connection security updated. @ref ble_gap_evt_conn_sec_update_t */
+  BLE_GAP_EVT_TIMEOUT,                          /**< Timeout expired. @ref ble_gap_evt_timeout_t */
+  BLE_GAP_EVT_RSSI_CHANGED,                     /**< RSSI report. @ref ble_gap_evt_rssi_changed_t */
+  BLE_GAP_EVT_ADV_REPORT,                       /**< Advertising report. @ref ble_gap_evt_adv_report_t */
+  BLE_GAP_EVT_SEC_REQUEST,                      /**< Security Request. @ref ble_gap_evt_sec_request_t */
+  BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST,        /**< Connection Parameter Update Request. @ref ble_gap_evt_conn_param_update_request_t */
+  BLE_GAP_EVT_SCAN_REQ_REPORT,                  /**< Scan request report. @ref ble_gap_evt_scan_req_report_t */
+};
+
+/**@brief GAP Option IDs.
+ * IDs that uniquely identify a GAP option.
+ */
+enum BLE_GAP_OPTS
+{
+  BLE_GAP_OPT_CH_MAP  = BLE_GAP_OPT_BASE,       /**< Channel Map. @ref ble_gap_opt_ch_map_t  */
+  BLE_GAP_OPT_LOCAL_CONN_LATENCY,               /**< Local connection latency. @ref ble_gap_opt_local_conn_latency_t */
+  BLE_GAP_OPT_PASSKEY,                          /**< Set passkey. @ref ble_gap_opt_passkey_t */
+  BLE_GAP_OPT_PRIVACY,                          /**< Custom privacy. @ref ble_gap_opt_privacy_t */
+  BLE_GAP_OPT_SCAN_REQ_REPORT,                  /**< Scan request report. @ref ble_gap_opt_scan_req_report_t */
+  BLE_GAP_OPT_COMPAT_MODE                       /**< Compatibility mode. @ref ble_gap_opt_compat_mode_t */
+};
+/** @} */
 
 /**@addtogroup BLE_GAP_DEFINES Defines
  * @{ */
@@ -72,8 +141,10 @@
 
 /**@defgroup BLE_GAP_TIMEOUT_SOURCES GAP Timeout sources
  * @{ */
-#define BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT              0x00 /**< Advertisement timeout. */
+#define BLE_GAP_TIMEOUT_SRC_ADVERTISING                0x00 /**< Advertising timeout. */
 #define BLE_GAP_TIMEOUT_SRC_SECURITY_REQUEST           0x01 /**< Security request timeout. */
+#define BLE_GAP_TIMEOUT_SRC_SCAN                       0x02 /**< Scanning timeout. */
+#define BLE_GAP_TIMEOUT_SRC_CONN                       0x03 /**< Connection timeout. */
 /**@} */
 
 
@@ -155,8 +226,29 @@
  /**@}  */
 
 
+/**@defgroup BLE_GAP_SCAN_INTERVALS GAP Scan interval max and min
+ * @{ */
+#define BLE_GAP_SCAN_INTERVAL_MIN       0x0004 /**< Minimum Scan interval in 625 us units, i.e. 2.5 ms. */
+#define BLE_GAP_SCAN_INTERVAL_MAX       0x4000 /**< Maximum Scan interval in 625 us units, i.e. 10.24 s. */
+ /** @}  */
+
+
+/**@defgroup BLE_GAP_SCAN_WINDOW GAP Scan window max and min
+ * @{ */
+#define BLE_GAP_SCAN_WINDOW_MIN         0x0004 /**< Minimum Scan window in 625 us units, i.e. 2.5 ms. */
+#define BLE_GAP_SCAN_WINDOW_MAX         0x4000 /**< Maximum Scan window in 625 us units, i.e. 10.24 s. */
+ /** @}  */
+
+
+/**@defgroup BLE_GAP_SCAN_TIMEOUT GAP Scan timeout max and min
+ * @{ */
+#define BLE_GAP_SCAN_TIMEOUT_MIN        0x0001 /**< Minimum Scan timeout in seconds. */
+#define BLE_GAP_SCAN_TIMEOUT_MAX        0xFFFF /**< Maximum Scan timeout in seconds. */
+ /** @}  */
+
+
 /**@brief Maximum size of advertising data in octets. */
-#define  BLE_GAP_ADV_MAX_SIZE       31
+#define  BLE_GAP_ADV_MAX_SIZE           31
 
 
 /**@defgroup BLE_GAP_ADV_TYPES GAP Advertising types
@@ -179,7 +271,7 @@
 
 /**@defgroup BLE_GAP_ADV_TIMEOUT_VALUES GAP Advertising timeout values
  * @{ */
-#define BLE_GAP_ADV_TIMEOUT_LIMITED_MAX      180 /**< Maximum advertising time in limited discoverable mode (TGAP(lim_adv_timeout) = 180s in spec (Addendum 2)). */
+#define BLE_GAP_ADV_TIMEOUT_LIMITED_MAX      180 /**< Maximum advertising time in limited discoverable mode (TGAP(lim_adv_timeout) = 180s). */
 #define BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED  0 /**< Unlimited advertising in general discoverable mode. */
 /**@} */
 
@@ -210,7 +302,7 @@
 
 /**@defgroup BLE_GAP_SEC_STATUS GAP Security status
  * @{ */
-#define BLE_GAP_SEC_STATUS_SUCCESS                0x00  /**< Successful parameters. */
+#define BLE_GAP_SEC_STATUS_SUCCESS                0x00  /**< Procedure completed with success. */
 #define BLE_GAP_SEC_STATUS_TIMEOUT                0x01  /**< Procedure timed out. */
 #define BLE_GAP_SEC_STATUS_PDU_INVALID            0x02  /**< Invalid PDU received. */
 #define BLE_GAP_SEC_STATUS_PASSKEY_ENTRY_FAILED   0x81  /**< Passkey entry failed (user cancelled or other). */
@@ -239,7 +331,7 @@
 #define BLE_GAP_CP_MAX_CONN_INTVL_NONE           0xFFFF  /**< No new maximum connction interval specified in connect parameters. */
 #define BLE_GAP_CP_MAX_CONN_INTVL_MIN            0x0006  /**< Lowest maximum connection interval permitted, in units of 1.25 ms, i.e. 7.5 ms. */
 #define BLE_GAP_CP_MAX_CONN_INTVL_MAX            0x0C80  /**< Highest maximum connection interval permitted, in units of 1.25 ms, i.e. 4 s. */
-#define BLE_GAP_CP_SLAVE_LATENCY_MAX             0x03E8  /**< Highest slave latency permitted, in connection events. */
+#define BLE_GAP_CP_SLAVE_LATENCY_MAX             0x01F3  /**< Highest slave latency permitted, in connection events. */
 #define BLE_GAP_CP_CONN_SUP_TIMEOUT_NONE         0xFFFF  /**< No new supervision timeout specified in connect parameters. */
 #define BLE_GAP_CP_CONN_SUP_TIMEOUT_MIN          0x000A  /**< Lowest supervision timeout permitted, in units of 10 ms, i.e. 100 ms. */
 #define BLE_GAP_CP_CONN_SUP_TIMEOUT_MAX          0x0C80  /**< Highest supervision timeout permitted, in units of 10 ms, i.e. 32 s. */
@@ -249,6 +341,8 @@
 /**@brief GAP device name maximum length. */
 #define BLE_GAP_DEVNAME_MAX_LEN           31
 
+/**@brief Disable RSSI events for connections */
+#define BLE_GAP_RSSI_THRESHOLD_INVALID    0xFF
 
 /**@defgroup BLE_GAP_CONN_SEC_MODE_SET_MACROS GAP attribute security requirement setters
  *
@@ -269,6 +363,9 @@
 /**@} */
 
 
+/**@brief GAP Security Random Number Length. */
+#define BLE_GAP_SEC_RAND_LEN 8
+
 /**@brief GAP Security Key Length. */
 #define BLE_GAP_SEC_KEY_LEN 16
 
@@ -305,6 +402,12 @@
  *
  * @note  When ble_conn_params_t is received in an event, both min_conn_interval and
  *        max_conn_interval will be equal to the connection interval set by the central.
+ *
+ * @note If both conn_sup_timeout and max_conn_interval are specified, then the following constraint applies:
+ *       conn_sup_timeout * 4 > (1 + slave_latency) * max_conn_interval
+ *       that corresponds to the following Bluetooth Spec requirement:
+ *       The Supervision_Timeout in milliseconds shall be larger than
+ *       (1 + Conn_Latency) * Conn_Interval_Max * 2, where Conn_Interval_Max is given in milliseconds.
  */
 typedef struct
 {
@@ -315,9 +418,7 @@
 } ble_gap_conn_params_t;
 
 
-/**@brief GAP link requirements.
- *
- * See Bluetooth Core specification, Volume 3 Part C 10.2 for details.
+/**@brief GAP connection security modes.
  *
  * Security Mode 0 Level 0: No access permissions at all (this level is not defined by the Bluetooth Core specification).\n
  * Security Mode 1 Level 1: No security is needed (aka open link).\n
@@ -352,56 +453,73 @@
 /**@brief Whitelist structure. */
 typedef struct
 {
-  ble_gap_addr_t   ** pp_addrs;        /**< Pointer to array of device address pointers, pointing to addresses to be used in whitelist. NULL if none are given. */
+  ble_gap_addr_t    **pp_addrs;        /**< Pointer to an array of device address pointers, pointing to addresses to be used in whitelist. NULL if none are given. */
   uint8_t             addr_count;      /**< Count of device addresses in array, up to @ref BLE_GAP_WHITELIST_ADDR_MAX_COUNT. */
-  ble_gap_irk_t    ** pp_irks;         /**< Pointer to array of Identity Resolving Key (IRK) pointers, each pointing to an IRK in the whitelist. NULL if none are given. */
+  ble_gap_irk_t     **pp_irks;         /**< Pointer to an array of Identity Resolving Key (IRK) pointers, each pointing to an IRK in the whitelist. NULL if none are given. */
   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. */ 
+typedef struct
+{
+  uint8_t ch_37_off : 1;  /**< Setting this bit to 1 will turn off advertising on channel 37 */
+  uint8_t ch_38_off : 1;  /**< Setting this bit to 1 will turn off advertising on channel 38 */
+  uint8_t ch_39_off : 1;  /**< Setting this bit to 1 will turn off advertising on channel 39 */
+} ble_gap_adv_ch_mask_t;
 
 /**@brief GAP advertising parameters.*/
 typedef struct
 {
   uint8_t               type;                 /**< See @ref BLE_GAP_ADV_TYPES. */
-  ble_gap_addr_t*       p_peer_addr;          /**< For BLE_GAP_CONN_MODE_DIRECTED mode only, known peer address. */
+  ble_gap_addr_t       *p_peer_addr;          /**< For @ref BLE_GAP_ADV_TYPE_ADV_DIRECT_IND mode only, known peer address. */
   uint8_t               fp;                   /**< Filter Policy, see @ref BLE_GAP_ADV_FILTER_POLICIES. */
-  ble_gap_whitelist_t * p_whitelist;          /**< Pointer to whitelist, NULL if none is given. */
+  ble_gap_whitelist_t  *p_whitelist;          /**< Pointer to whitelist, NULL if none is given. */
   uint16_t              interval;             /**< Advertising interval between 0x0020 and 0x4000 in 0.625 ms units (20ms to 10.24s), see @ref BLE_GAP_ADV_INTERVALS.
                                                    - If type equals @ref BLE_GAP_ADV_TYPE_ADV_DIRECT_IND, this parameter must be set to 0 for high duty cycle directed advertising.
-                                                   - If type equals @ref BLE_GAP_ADV_TYPE_ADV_DIRECT_IND, set @ref BLE_GAP_ADV_INTERVAL_MIN <= interval <= @ref BLE_GAP_ADV_INTERVAL_MAX for low duty cycle advertising */
+                                                   - If type equals @ref BLE_GAP_ADV_TYPE_ADV_DIRECT_IND, set @ref BLE_GAP_ADV_INTERVAL_MIN <= interval <= @ref BLE_GAP_ADV_INTERVAL_MAX for low duty cycle advertising.*/
   uint16_t              timeout;              /**< Advertising timeout between 0x0001 and 0x3FFF in seconds, 0x0000 disables timeout. See also @ref BLE_GAP_ADV_TIMEOUT_VALUES. If type equals @ref BLE_GAP_ADV_TYPE_ADV_DIRECT_IND, this parameter must be set to 0 for High duty cycle directed advertising. */
+  ble_gap_adv_ch_mask_t channel_mask;         /**< Advertising channel mask. @see ble_gap_channel_mask_t for documentation. */
 } ble_gap_adv_params_t;
 
 
 /**@brief GAP scanning parameters. */
 typedef struct
 {
-  uint8_t    filter;                    /**< Filter based on discovery mode, see @ref BLE_GAP_DISC_MODES. */
-  uint8_t    active    : 1;             /**< If 1, perform active scanning (scan requests). */
-  uint8_t    selective : 1;             /**< If 1, ignore unknown devices (non whitelisted). */
-  uint16_t   interval;                  /**< Scan interval between 0x0020 and 0x4000 in 0.625ms units (20ms to 10.24s). */
-  uint16_t   window;                    /**< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
-  uint16_t   timeout;                   /**< Scan timeout between 0x0001 and 0x3FFF in seconds, 0x0000 disables timeout. */
+  uint8_t                 active    : 1;        /**< If 1, perform active scanning (scan requests). */
+  uint8_t                 selective : 1;        /**< If 1, ignore unknown devices (non whitelisted). */
+  ble_gap_whitelist_t *   p_whitelist;          /**< Pointer to whitelist, NULL if none is given. */
+  uint16_t                interval;             /**< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
+  uint16_t                window;               /**< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
+  uint16_t                timeout;              /**< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */
 } ble_gap_scan_params_t;
 
 
+/** @brief Keys that can be exchanged during a bonding procedure. */
+typedef struct
+{
+  uint8_t enc     : 1;                        /**< Long Term Key and Master Identification. */
+  uint8_t id      : 1;                        /**< Identity Resolving Key and Identity Address Information. */
+  uint8_t sign    : 1;                        /**< Connection Signature Resolving Key. */
+} ble_gap_sec_kdist_t;
+
+
 /**@brief GAP security parameters. */
 typedef struct
 {
-  uint16_t   timeout;                   /**< Timeout for SMP transactions or Security Request in seconds, see @ref sd_ble_gap_authenticate and @ref sd_ble_gap_sec_params_reply for more information. */
-  uint8_t    bond    : 1;               /**< Perform bonding. */
-  uint8_t    mitm    : 1;               /**< Man In The Middle protection required. */
-  uint8_t    io_caps : 3;               /**< IO capabilities, see @ref BLE_GAP_IO_CAPS. */
-  uint8_t    oob     : 1;               /**< Out Of Band data available. */
-  uint8_t    min_key_size;              /**< Minimum encryption key size in octets between 7 and 16. */
-  uint8_t    max_key_size;              /**< Maximum encryption key size in octets between min_key_size and 16. */
+  uint8_t               bond    : 1;               /**< Perform bonding. */
+  uint8_t               mitm    : 1;               /**< Man In The Middle protection required. */
+  uint8_t               io_caps : 3;               /**< IO capabilities, see @ref BLE_GAP_IO_CAPS. */
+  uint8_t               oob     : 1;               /**< Out Of Band data available. */
+  uint8_t               min_key_size;              /**< Minimum encryption key size in octets between 7 and 16. If 0 then not applicable in this instance. */
+  uint8_t               max_key_size;              /**< Maximum encryption key size in octets between min_key_size and 16. */
+  ble_gap_sec_kdist_t   kdist_periph;              /**< Key distribution bitmap: keys that the peripheral device will distribute. */
+  ble_gap_sec_kdist_t   kdist_central;             /**< Key distribution bitmap: keys that the central device will distribute. */
 } ble_gap_sec_params_t;
 
 
 /**@brief GAP Encryption Information. */
 typedef struct
 {
-  uint16_t  div;                        /**< Encryption Diversifier. */
   uint8_t   ltk[BLE_GAP_SEC_KEY_LEN];   /**< Long Term Key. */
   uint8_t   auth : 1;                   /**< Authenticated Key. */
   uint8_t   ltk_len : 7;                /**< LTK length in octets. */
@@ -412,107 +530,68 @@
 typedef struct
 {
   uint16_t  ediv;                       /**< Encrypted Diversifier. */
-  uint8_t   rand[8];                    /**< Random Number. */
+  uint8_t   rand[BLE_GAP_SEC_RAND_LEN]; /**< Random Number. */
 } ble_gap_master_id_t;
 
 
-/**@brief GAP Identity Information. */
-typedef struct
-{
-  ble_gap_addr_t  addr;                       /**< Bluetooth address to which this key applies. */
-  uint8_t         irk[BLE_GAP_SEC_KEY_LEN];   /**< Identity Resolution Key. */
-} ble_gap_id_info_t;
-
-
 /**@brief GAP Signing Information. */
 typedef struct
 {
-  uint8_t   csrk[BLE_GAP_SEC_KEY_LEN]; /* Connection Signature Resolving Key. */
+  uint8_t   csrk[BLE_GAP_SEC_KEY_LEN];        /**< Connection Signature Resolving Key. */
 } ble_gap_sign_info_t;
 
 
-/**@brief GAP Event IDs.
- * Those IDs uniquely identify an event coming from the stack to the application.
- */
-enum BLE_GAP_EVTS
-{
-  BLE_GAP_EVT_CONNECTED  = BLE_GAP_EVT_BASE,    /**< Connection established. */
-  BLE_GAP_EVT_DISCONNECTED,                     /**< Disconnected from peer. */
-  BLE_GAP_EVT_CONN_PARAM_UPDATE,                /**< Connection Parameters updated. */
-  BLE_GAP_EVT_SEC_PARAMS_REQUEST,               /**< Request to provide security parameters. */
-  BLE_GAP_EVT_SEC_INFO_REQUEST,                 /**< Request to provide security information. */
-  BLE_GAP_EVT_PASSKEY_DISPLAY,                  /**< Request to display a passkey to the user. */
-  BLE_GAP_EVT_AUTH_KEY_REQUEST,                 /**< Request to provide an authentication key. */
-  BLE_GAP_EVT_AUTH_STATUS,                      /**< Authentication procedure completed with status. */
-  BLE_GAP_EVT_CONN_SEC_UPDATE,                  /**< Connection security updated. */
-  BLE_GAP_EVT_TIMEOUT,                          /**< Timeout expired. */
-  BLE_GAP_EVT_RSSI_CHANGED,                     /**< Signal strength measurement report. */
-};
-
-
-/**
- * @brief GAP Option IDs.
- * IDs that uniquely identify a GAP option.
- */
-enum BLE_GAP_OPTS
-{
-  BLE_GAP_OPT_LOCAL_CONN_LATENCY  = BLE_GAP_OPT_BASE,    /**< Local connection latency. */
-  BLE_GAP_OPT_PASSKEY,                                   /**< Set passkey to be used during pairing. This option can be used to make the SoftDevice use an application provided passkey instead of generating a random passkey.*/
-  BLE_GAP_OPT_PRIVACY,                                   /**< Set or get custom IRK or custom private address cycle interval. */
-};
-/**@} */
-
-
-/**@brief Event data for connected event. */
+/**@brief Event structure for @ref BLE_GAP_EVT_CONNECTED. */
 typedef struct
 {
   ble_gap_addr_t        peer_addr;              /**< Bluetooth address of the peer device. */
+  ble_gap_addr_t        own_addr;               /**< Bluetooth address of the local device used during connection setup. */
   uint8_t               irk_match :1;           /**< If 1, peer device's address resolved using an IRK. */
   uint8_t               irk_match_idx  :7;      /**< Index in IRK list where the address was matched. */
   ble_gap_conn_params_t conn_params;            /**< GAP Connection Parameters. */
 } ble_gap_evt_connected_t;
 
 
-/**@brief Event data for disconnected event. */
+/**@brief Event structure for @ref BLE_GAP_EVT_DISCONNECTED. */
 typedef struct
 {
-  uint8_t reason;                               /**< HCI error code. */
+  uint8_t reason;                               /**< HCI error code, see @ref BLE_HCI_STATUS_CODES. */
 } ble_gap_evt_disconnected_t;
 
 
-/**@brief Event data for connection parameter update event. */
+/**@brief Event structure for @ref BLE_GAP_EVT_CONN_PARAM_UPDATE. */
 typedef struct
 {
   ble_gap_conn_params_t conn_params;            /**<  GAP Connection Parameters. */
 } ble_gap_evt_conn_param_update_t;
 
 
-/**@brief Event data for security parameters request event. */
+/**@brief Event structure for @ref BLE_GAP_EVT_SEC_PARAMS_REQUEST. */
 typedef struct
 {
   ble_gap_sec_params_t peer_params;             /**< Initiator Security Parameters. */
 } ble_gap_evt_sec_params_request_t;
 
 
-/**@brief Event data for security info request event. */
+/**@brief Event structure for @ref BLE_GAP_EVT_SEC_INFO_REQUEST. */
 typedef struct
 {
-  ble_gap_addr_t peer_addr;                     /**< Bluetooth address of the peer device. */
-  uint16_t       div;                           /**< Encryption diversifier for LTK lookup. */
-  uint8_t        enc_info  : 1;                 /**< If 1, Encryption Information required. */
-  uint8_t        id_info   : 1;                 /**< If 1, Identity Information required. */
-  uint8_t        sign_info : 1;                 /**< If 1, Signing Information required. */
+  ble_gap_addr_t      peer_addr;                     /**< Bluetooth address of the peer device. */
+  ble_gap_master_id_t master_id;                     /**< Master Identification for LTK lookup. */
+  uint8_t             enc_info  : 1;                 /**< If 1, Encryption Information required. */
+  uint8_t             id_info   : 1;                 /**< If 1, Identity Information required. */
+  uint8_t             sign_info : 1;                 /**< If 1, Signing Information required. */
 } ble_gap_evt_sec_info_request_t;
 
 
-/**@brief Event data for passkey display event. */
+/**@brief Event structure for @ref BLE_GAP_EVT_PASSKEY_DISPLAY. */
 typedef struct
 {
   uint8_t passkey[BLE_GAP_PASSKEY_LEN];         /**< 6-digit passkey in ASCII ('0'-'9' digits only). */
 } ble_gap_evt_passkey_display_t;
 
 
-/**@brief Event data for authentication key request event. */
+/**@brief Event structure for @ref BLE_GAP_EVT_AUTH_KEY_REQUEST. */
 typedef struct
 {
   uint8_t key_type;                             /**< See @ref BLE_GAP_AUTH_KEY_TYPES. */
@@ -530,102 +609,186 @@
 } ble_gap_sec_levels_t;
 
 
-/**@brief Keys that have been exchanged. */
+/**@brief Encryption Key. */
+typedef struct
+{
+  ble_gap_enc_info_t    enc_info;             /**< Encryption Information. */
+  ble_gap_master_id_t   master_id;            /**< Master Identification. */
+} ble_gap_enc_key_t;
+
+
+/**@brief Identity Key. */
 typedef struct
 {
-  uint8_t ltk       : 1;                        /**< Long Term Key. */
-  uint8_t ediv_rand : 1;                        /**< Encrypted Diversifier and Random value. */
-  uint8_t irk       : 1;                        /**< Identity Resolving Key. */
-  uint8_t address   : 1;                        /**< Public or static random address. */
-  uint8_t csrk      : 1;                        /**< Connection Signature Resolving Key. */
+  ble_gap_irk_t         id_info;              /**< Identity Information. */
+  ble_gap_addr_t        id_addr_info;         /**< Identity Address Information. */
+} ble_gap_id_key_t;
+
+
+/**@brief Security Keys. */
+typedef struct
+{
+  ble_gap_enc_key_t     *p_enc_key;           /**< Encryption Key, or NULL. */
+  ble_gap_id_key_t      *p_id_key;            /**< Identity Key, or NULL. */
+  ble_gap_sign_info_t   *p_sign_key;          /**< Signing Key, or NULL. */
 } ble_gap_sec_keys_t;
 
 
-/**@brief Event data for authentication status event. */
+/**@brief Security key set (both Peripheral and Central keys).
+ *         Note that when distributing Bluetooth addresses pertaining to the local device those
+ *         will have to be filled in by the user. */
+typedef struct
+{
+  ble_gap_sec_keys_t keys_periph;     /**< Keys distributed by the device in the Peripheral role. */
+  ble_gap_sec_keys_t keys_central;    /**< Keys distributed by the device in the Central role. */
+} ble_gap_sec_keyset_t;
+
+
+/**@brief Event structure for @ref BLE_GAP_EVT_AUTH_STATUS. */
 typedef struct
 {
   uint8_t               auth_status;            /**< Authentication status, see @ref BLE_GAP_SEC_STATUS. */
-  uint8_t               error_src;              /**< On error, source that caused the failure, see @ref BLE_GAP_SEC_STATUS_SOURCES. */
+  uint8_t               error_src : 2;          /**< On error, source that caused the failure, see @ref BLE_GAP_SEC_STATUS_SOURCES. */
+  uint8_t               bonded : 1;             /**< Procedure resulted in a bond. */
   ble_gap_sec_levels_t  sm1_levels;             /**< Levels supported in Security Mode 1. */
   ble_gap_sec_levels_t  sm2_levels;             /**< Levels supported in Security Mode 2. */
-  ble_gap_sec_keys_t    periph_kex;             /**< Bitmap stating which keys were exchanged (distributed) by the peripheral. */
-  ble_gap_sec_keys_t    central_kex;            /**< Bitmap stating which keys were exchanged (distributed) by the central. */
-  struct periph_keys_t
-  {
-    ble_gap_enc_info_t    enc_info;             /**< Peripheral's Encryption information. */
-  } periph_keys;                                /**< Actual keys distributed from the Peripheral to the Central. */ 
-  struct central_keys_t
-  {
-    ble_gap_irk_t         irk;                  /**< Central's IRK. */
-    ble_gap_addr_t        id_info;              /**< Central's Identity Info. */
-  } central_keys;                               /**< Actual keys distributed from the Central to the Peripheral. */
+  ble_gap_sec_kdist_t   kdist_periph;           /**< Bitmap stating which keys were exchanged (distributed) by the peripheral. */
+  ble_gap_sec_kdist_t   kdist_central;          /**< Bitmap stating which keys were exchanged (distributed) by the central. */
 } ble_gap_evt_auth_status_t;
 
 
-/**@brief Event data for connection security update event. */
+/**@brief Event structure for @ref BLE_GAP_EVT_CONN_SEC_UPDATE. */
 typedef struct
 {
   ble_gap_conn_sec_t conn_sec;                  /**< Connection security level. */
 } ble_gap_evt_conn_sec_update_t;
 
 
-/**@brief Event data for timeout event. */
+/**@brief Event structure for @ref BLE_GAP_EVT_TIMEOUT. */
 typedef struct
 {
   uint8_t src;                                  /**< Source of timeout event, see @ref BLE_GAP_TIMEOUT_SOURCES. */
 } ble_gap_evt_timeout_t;
 
 
-/**@brief Event data for advertisement report event. */
+/**@brief Event structure for @ref BLE_GAP_EVT_RSSI_CHANGED. */
 typedef struct
 {
   int8_t  rssi;                               /**< Received Signal Strength Indication in dBm. */
 } ble_gap_evt_rssi_changed_t;
 
 
-/**@brief GAP event callback event structure. */
+/**@brief Event structure for @ref BLE_GAP_EVT_ADV_REPORT. */
+typedef struct
+{
+  ble_gap_addr_t peer_addr;                     /**< Bluetooth address of the peer device. */
+  int8_t         rssi;                          /**< Received Signal Strength Indication in dBm. */
+  uint8_t        scan_rsp : 1;                  /**< If 1, the report corresponds to a scan response and the type field may be ignored. */
+  uint8_t        type     : 2;                  /**< See @ref BLE_GAP_ADV_TYPES. Only valid if the scan_rsp field is 0. */
+  uint8_t        dlen     : 5;                  /**< Advertising or scan response data length. */
+  uint8_t        data[BLE_GAP_ADV_MAX_SIZE];    /**< Advertising or scan response data. */
+} ble_gap_evt_adv_report_t;
+
+
+/**@brief Event structure for @ref BLE_GAP_EVT_SEC_REQUEST. */
+typedef struct
+{
+  uint8_t    bond    : 1;                       /**< Perform bonding. */
+  uint8_t    mitm    : 1;                       /**< Man In The Middle protection required. */
+} ble_gap_evt_sec_request_t;
+
+
+/**@brief Event structure for @ref BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST. */
+typedef struct
+{
+  ble_gap_conn_params_t conn_params;            /**<  GAP Connection Parameters. */
+} ble_gap_evt_conn_param_update_request_t;
+
+
+/**@brief Event structure for @ref BLE_GAP_EVT_SCAN_REQ_REPORT. */
+typedef struct
+{
+  int8_t                  rssi;              /**< Received Signal Strength Indication in dBm. */
+  ble_gap_addr_t          peer_addr;         /**< Bluetooth address of the peer device. */
+} ble_gap_evt_scan_req_report_t;
+
+
+
+/**@brief GAP event structure. */
 typedef struct
 {
   uint16_t conn_handle;                                     /**< Connection Handle on which event occured. */
   union                                                     /**< union alternative identified by evt_id in enclosing struct. */
   {
-    ble_gap_evt_connected_t          connected;             /**< Connected Event Parameters. */
-    ble_gap_evt_disconnected_t       disconnected;          /**< Disconnected Event Parameters. */
-    ble_gap_evt_conn_param_update_t  conn_param_update;     /**< Connection Parameter Update Parameters. */
-    ble_gap_evt_sec_params_request_t sec_params_request;    /**< Security Parameters Request Event Parameters. */
-    ble_gap_evt_sec_info_request_t   sec_info_request;      /**< Security Information Request Event Parameters. */
-    ble_gap_evt_passkey_display_t    passkey_display;       /**< Passkey Display Event Parameters. */
-    ble_gap_evt_auth_key_request_t   auth_key_request;      /**< Authentication Key Request Event Parameters. */
-    ble_gap_evt_auth_status_t        auth_status;           /**< Authentication Status Event Parameters. */
-    ble_gap_evt_conn_sec_update_t    conn_sec_update;       /**< Connection Security Update Event Parameters. */
-    ble_gap_evt_timeout_t            timeout;               /**< Timeout Event Parameters. */
-    ble_gap_evt_rssi_changed_t       rssi_changed;          /**< RSSI Event parameters. */
-  } params;
+    ble_gap_evt_connected_t                   connected;                    /**< Connected Event Parameters. */
+    ble_gap_evt_disconnected_t                disconnected;                 /**< Disconnected Event Parameters. */
+    ble_gap_evt_conn_param_update_t           conn_param_update;            /**< Connection Parameter Update Parameters. */
+    ble_gap_evt_sec_params_request_t          sec_params_request;           /**< Security Parameters Request Event Parameters. */
+    ble_gap_evt_sec_info_request_t            sec_info_request;             /**< Security Information Request Event Parameters. */
+    ble_gap_evt_passkey_display_t             passkey_display;              /**< Passkey Display Event Parameters. */
+    ble_gap_evt_auth_key_request_t            auth_key_request;             /**< Authentication Key Request Event Parameters. */
+    ble_gap_evt_auth_status_t                 auth_status;                  /**< Authentication Status Event Parameters. */
+    ble_gap_evt_conn_sec_update_t             conn_sec_update;              /**< Connection Security Update Event Parameters. */
+    ble_gap_evt_timeout_t                     timeout;                      /**< Timeout Event Parameters. */
+    ble_gap_evt_rssi_changed_t                rssi_changed;                 /**< RSSI Event parameters. */
+    ble_gap_evt_adv_report_t                  adv_report;                   /**< Advertising Report Event Parameters. */
+    ble_gap_evt_sec_request_t                 sec_request;                  /**< Security Request Event Parameters. */
+    ble_gap_evt_conn_param_update_request_t   conn_param_update_request;    /**< Connection Parameter Update Parameters. */
+    ble_gap_evt_scan_req_report_t             scan_req_report;              /**< Scan Request Report parameters. */
+  } params;                                                                 /**< Event Parameters. */
 
 } ble_gap_evt_t;
 
 
+/**@brief Channel Map option.
+ *        Used with @ref sd_ble_opt_get to get the current channel map
+ *        or @ref sd_ble_opt_set to set a new channel map. When setting the
+ *        channel map, it applies to all current and future connections. When getting the
+ *        current channel map, it applies to a single connection and the connection handle
+ *        must be supplied.
+ *
+ * @note  Setting the channel map may take some time, depending on connection parameters.
+ *        The time taken may be different for each connection and the get operation will
+ *        return the previous channel map until the new one has taken effect.
+ *
+ * @note  After setting the channel map, by spec it can not be set again until at least 1 s has passed.
+ *        See Bluetooth Specification Version 4.1 Volume 2, Part E, Section 7.3.46.
+ *
+ * @retval ::NRF_SUCCESS Get or set successful.
+ * @retval ::NRF_ERROR_BUSY Channel map was set again before enough time had passed.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied for get.
+ * @retval ::NRF_ERROR_NOT_SUPPORTED Returned by sd_ble_opt_set in peripheral-only SoftDevices.
+ *
+ */
+typedef struct
+{
+  uint16_t conn_handle;                   /**< Connection Handle (only applicable for get) */
+  uint8_t ch_map[5];                      /**< Channel Map (37-bit). */
+} ble_gap_opt_ch_map_t;
+
+
 /**@brief Local connection latency option.
  *
- *         Local connection latency is a feature which enables the slave to improve
- *         current consumption by ignoring the slave latency set by the peer. The
- *         local connection latency can only be set to a multiple of the slave latency,
- *         and cannot be longer than half of the supervision timeout.
+ *        Local connection latency is a feature which enables the slave to improve
+ *        current consumption by ignoring the slave latency set by the peer. The
+ *        local connection latency can only be set to a multiple of the slave latency,
+ *        and cannot be longer than half of the supervision timeout.
  *
- *         Used with @ref sd_ble_opt_set to set the local connection latency. The
- *         @ref sd_ble_opt_get is not supported for this option, but the actual 
- *         local connection latency (unless set to NULL) is set as a return parameter
- *         when setting the option.
+ *        Used with @ref sd_ble_opt_set to set the local connection latency. The
+ *        @ref sd_ble_opt_get is not supported for this option, but the actual
+ *        local connection latency (unless set to NULL) is set as a return parameter
+ *        when setting the option.
  *
- *  @note  The latency set will be truncated down to the closest slave latency event
- *         multiple, or the nearest multiple before half of the supervision timeout.
+ * @note  The latency set will be truncated down to the closest slave latency event
+ *        multiple, or the nearest multiple before half of the supervision timeout.
  *
- *  @note  The local connection latency is default off, and needs to be set for new
- *         connections and whenever the connection is updated.
+ * @note  The local connection latency is disabled by default, and needs to be enabled for new
+ *        connections and whenever the connection is updated.
  *
- *  @retval ::NRF_SUCCESS Set successfully.
- *  @retval ::NRF_ERROR_NOT_SUPPORTED Get is not supported.
- *  @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle parameter.
+ * @retval ::NRF_SUCCESS Set successfully.
+ * @retval ::NRF_ERROR_NOT_SUPPORTED Get is not supported.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle parameter.
  */
 typedef struct
 {
@@ -650,16 +813,28 @@
 } ble_gap_opt_passkey_t;
 
 
-/**@brief Custom Privacy Options.
+/**@brief Custom Privacy Option.
+ *
+ *        This structure is used with both @ref sd_ble_opt_set (as input) and with
+ *        @ref sd_ble_opt_get (as output).
+ *
+ *        Structure containing:
+ *        - A pointer to an IRK to set (if input), or a place to store a read IRK (if output).
+ *        - 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 refreshed at any
- * interval, and not at start of advertising. A new address can be generated manually by calling
- * @ref sd_ble_gap_address_set with the same type again. The default interval is
- * @ref BLE_GAP_DEFAULT_PRIVATE_ADDR_CYCLE_INTERVAL_S.
+ * @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 
+ *        refreshed at all. The default interval is @ref BLE_GAP_DEFAULT_PRIVATE_ADDR_CYCLE_INTERVAL_S.
  *
- * @note If cycle mode is @ref BLE_GAP_ADDR_CYCLE_MODE_AUTO, the address will immediately be
- * refreshed when this option is set.
+ * @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. 
+ *
+ * @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.
+ *
+ * @retval ::NRF_SUCCESS Set or read successfully.
+ * @retval ::NRF_ERROR_INVALID_ADDR The pointer to IRK storage is invalid.
  */
 typedef struct
 {
@@ -668,12 +843,50 @@
 } ble_gap_opt_privacy_t;
 
 
+/**@brief Scan request report option.
+ *
+ *        This can be used with @ref sd_ble_opt_set to make the SoftDevice send
+ *        @ref BLE_GAP_EVT_SCAN_REQ_REPORT events.
+ *
+ *  @note   Due to the limited space reserved for scan request report events,
+ *          not all received scan requests will be reported.
+ *
+ *  @note   If whitelisting is used, only whitelisted requests are reported.
+ *
+ *  @retval ::NRF_SUCCESS Set successfully.
+ *  @retval ::NRF_ERROR_INVALID_STATE When advertising is ongoing while the option is set.
+ */
+typedef struct
+{
+   uint8_t enable : 1;                           /**< Enable scan request reports. */
+} ble_gap_opt_scan_req_report_t;
+
+/**@brief Compatibility mode option.
+ *
+ *        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 
+ *         a value of 0 for the WinOffset parameter in the Link Layer CONNECT_REQ packet.
+ *
+ *  @retval ::NRF_SUCCESS Set successfully.
+ *  @retval ::NRF_ERROR_INVALID_STATE When connection creation is ongoing while mode 1 is set.
+ */
+typedef struct
+{
+   uint8_t mode_1_enable : 1;                           /**< Enable compatibility mode 1.*/
+} ble_gap_opt_compat_mode_t;
+
+
 /**@brief Option structure for GAP options. */
 typedef union
 {
-  ble_gap_opt_local_conn_latency_t local_conn_latency;  /**< Local connection latency. */
-  ble_gap_opt_passkey_t            passkey;             /**< Passkey to be used for pairing.*/
-  ble_gap_opt_privacy_t            privacy;             /**< Custom privacy options. */
+  ble_gap_opt_ch_map_t                  ch_map;                    /**< Parameters for the Channel Map option. */
+  ble_gap_opt_local_conn_latency_t      local_conn_latency;        /**< Parameters for the Local connection latency option */
+  ble_gap_opt_passkey_t                 passkey;                   /**< Parameters for the Passkey option.*/
+  ble_gap_opt_privacy_t                 privacy;                   /**< Parameters for the Custom privacy option. */
+  ble_gap_opt_scan_req_report_t         scan_req_report;           /**< Parameters for the scan request report option.*/
+  ble_gap_opt_compat_mode_t             compat_mode;               /**< Parameters for the compatibility mode option.*/
 } ble_gap_opt_t;
 /**@} */
 
@@ -683,28 +896,27 @@
 
 /**@brief Set local Bluetooth address.
  *
- * If the address cycle mode is @ref BLE_GAP_ADDR_CYCLE_MODE_AUTO, the address type is required to
+ * @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 time advertising is
- * (re)started, and every @ref BLE_GAP_DEFAULT_PRIVATE_ADDR_CYCLE_INTERVAL_S seconds. If this API
- * call is used again with the same parameters while advertising, the SoftDevice will immediately
+ * 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.
  *
- * If the application wishes to use a @ref BLE_GAP_ADDR_TYPE_PUBLIC or
+ * @note If the application wishes to use a @ref BLE_GAP_ADDR_TYPE_PUBLIC or
  * @ref BLE_GAP_ADDR_TYPE_RANDOM_STATIC address, the cycle mode must be
  * @ref BLE_GAP_ADDR_CYCLE_MODE_NONE.
  *
- * If this API function is called while advertising, the softdevice will immediately update the
- * advertising address without the need to stop advertising in the following cases:
+ * @note If this API function is called while advertising or scanning, the softdevice will immediately update the
+ * advertising or scanning address without the need to stop the procedure in the following cases:
  *   - If the previously set address is of type @ref BLE_GAP_ADDR_TYPE_PUBLIC and the new address
  *   is also of type @ref BLE_GAP_ADDR_TYPE_PUBLIC
  *   - If the previously set address is not @ref BLE_GAP_ADDR_TYPE_PUBLIC and the new address is
  *   also not @ref BLE_GAP_ADDR_TYPE_PUBLIC.
- *
  * If the address is changed from a @ref BLE_GAP_ADDR_TYPE_PUBLIC address to another type or from
  * another type to a @ref BLE_GAP_ADDR_TYPE_PUBLIC address, the change will take effect the next
- * time advertising is started.
+ * time an advertising or scanning procedure is started.
  *
  * @note If the address cycle mode is @ref BLE_GAP_ADDR_CYCLE_MODE_NONE and the application is
  *       using privacy, the application must take care to generate and set new private addresses
@@ -713,70 +925,78 @@
  * @param[in] addr_cycle_mode Address cycle mode, see @ref BLE_GAP_ADDR_CYCLE_MODES.
  * @param[in] p_addr          Pointer to address structure.
  *
- * @return @ref NRF_SUCCESS Address successfully set.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameters.
- * @return @ref BLE_ERROR_GAP_INVALID_BLE_ADDR Invalid address.
- * @return @ref NRF_ERROR_BUSY The stack is busy, process pending events and retry.
+ * @retval ::NRF_SUCCESS Address successfully set.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameters.
+ * @retval ::BLE_ERROR_GAP_INVALID_BLE_ADDR Invalid address.
+ * @retval ::NRF_ERROR_BUSY The stack is busy, process pending events and retry.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
  */
-SVCALL(SD_BLE_GAP_ADDRESS_SET, uint32_t, sd_ble_gap_address_set(uint8_t addr_cycle_mode, ble_gap_addr_t const * const p_addr));
+SVCALL(SD_BLE_GAP_ADDRESS_SET, uint32_t, sd_ble_gap_address_set(uint8_t addr_cycle_mode, const ble_gap_addr_t *p_addr));
 
 
 /**@brief Get local Bluetooth address.
  *
- * @param[out] p_addr Pointer to address structure.
+ * @param[out] p_addr Pointer to address structure to be filled in.
  *
- * @return @ref NRF_SUCCESS Address successfully retrieved.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_SUCCESS Address successfully retrieved.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  */
-SVCALL(SD_BLE_GAP_ADDRESS_GET, uint32_t, sd_ble_gap_address_get(ble_gap_addr_t * const p_addr));
+SVCALL(SD_BLE_GAP_ADDRESS_GET, uint32_t, sd_ble_gap_address_get(ble_gap_addr_t *p_addr));
 
 
-/**@brief Set, clear or update advertisement and scan response data.
+/**@brief Set, clear or update advertising and scan response data.
  *
- * @note The format of the advertisement data will be checked by this call to ensure interoperability.
+ * @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 advertisement data and scan response data. 
+ *       duplicating the local name in the advertising data and scan response data. 
  *
- * @note: To clear the advertisement 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.
+ * @note The call will fail if p_data and p_sr_data are both NULL since this would have no effect.
  *
- * @param[in] p_data    Raw data to be placed in advertisement packet. If NULL, no changes are made to the current advertisement packet data.
+ * @param[in] p_data    Raw data to be placed in advertising packet. If NULL, no changes are made to the current advertising packet data.
  * @param[in] dlen      Data length for p_data. Max size: @ref BLE_GAP_ADV_MAX_SIZE octets. Should be 0 if p_data is NULL, can be 0 if p_data is not NULL.
  * @param[in] p_sr_data Raw data to be placed in scan response packet. If NULL, no changes are made to the current scan response packet data.
  * @param[in] srdlen    Data length for p_sr_data. Max size: @ref BLE_GAP_ADV_MAX_SIZE octets. Should be 0 if p_sr_data is NULL, can be 0 if p_data is not NULL.
  *
- * @return @ref NRF_SUCCESS Advertisement data successfully updated or cleared.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_INVALID_FLAGS Invalid combination of advertising flags supplied.
- * @return @ref NRF_ERROR_INVALID_DATA Invalid data type(s) supplied, check the advertising data format specification.
- * @return @ref NRF_ERROR_INVALID_LENGTH Invalid data length(s) supplied.
- * @return @ref BLE_ERROR_GAP_UUID_LIST_MISMATCH Invalid UUID list supplied.
- * @return @ref NRF_ERROR_BUSY The stack is busy, process pending events and retry.
+ * @retval ::NRF_SUCCESS Advertising data successfully updated or cleared.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_FLAGS Invalid combination of advertising flags supplied.
+ * @retval ::NRF_ERROR_INVALID_DATA Invalid data type(s) supplied, check the advertising data format specification.
+ * @retval ::NRF_ERROR_INVALID_LENGTH Invalid data length(s) supplied.
+ * @retval ::NRF_ERROR_NOT_SUPPORTED Unsupported data type.
+ * @retval ::BLE_ERROR_GAP_UUID_LIST_MISMATCH Invalid UUID list supplied.
  */
-SVCALL(SD_BLE_GAP_ADV_DATA_SET, uint32_t, sd_ble_gap_adv_data_set(uint8_t const * const p_data, uint8_t dlen, uint8_t const * const p_sr_data, uint8_t srdlen));
+SVCALL(SD_BLE_GAP_ADV_DATA_SET, uint32_t, sd_ble_gap_adv_data_set(uint8_t const *p_data, uint8_t dlen, uint8_t const *p_sr_data, uint8_t srdlen));
 
 
 /**@brief Start advertising (GAP Discoverable, Connectable modes, Broadcast Procedure).
  *
+ * @note An application can start an advertising procedure for broadcasting purposes while a connection
+ *       is active. After a @ref BLE_GAP_EVT_CONNECTED event is received, this function may therefore
+ *       be called to start a broadcast advertising procedure. The advertising procedure
+ *       cannot however be connectable (it must be of type @ref BLE_GAP_ADV_TYPE_ADV_SCAN_IND or
+ *       @ref BLE_GAP_ADV_TYPE_ADV_NONCONN_IND). @note Only one advertiser may be active at any time.
+ *
  * @param[in] p_adv_params Pointer to advertising parameters structure.
  *
- * @return @ref NRF_SUCCESS The BLE stack has started advertising.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, check the accepted ranges and limits.
- * @return @ref BLE_ERROR_GAP_INVALID_BLE_ADDR Invalid Bluetooth address supplied.
- * @return @ref BLE_ERROR_GAP_DISCOVERABLE_WITH_WHITELIST Discoverable mode and whitelist incompatible.
+ * @retval ::NRF_SUCCESS The BLE stack has started advertising.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, check the accepted ranges and limits.
+ * @retval ::BLE_ERROR_GAP_INVALID_BLE_ADDR Invalid Bluetooth address supplied.
+ * @retval ::BLE_ERROR_GAP_DISCOVERABLE_WITH_WHITELIST Discoverable mode and whitelist incompatible.
+ * @retval ::NRF_ERROR_BUSY The stack is busy, process pending events and retry.
  */
-SVCALL(SD_BLE_GAP_ADV_START, uint32_t, sd_ble_gap_adv_start(ble_gap_adv_params_t const * const p_adv_params));
+SVCALL(SD_BLE_GAP_ADV_START, uint32_t, sd_ble_gap_adv_start(ble_gap_adv_params_t const *p_adv_params));
 
 
 /**@brief Stop advertising (GAP Discoverable, Connectable modes, Broadcast Procedure).
  *
- * @return @ref NRF_SUCCESS The BLE stack has stopped advertising.
- * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation (most probably not in advertising state).
+ * @retval ::NRF_SUCCESS The BLE stack has stopped advertising.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation (most probably not in advertising state).
  */
 SVCALL(SD_BLE_GAP_ADV_STOP, uint32_t, sd_ble_gap_adv_stop(void));
 
@@ -788,35 +1008,36 @@
  *          the central to perform the procedure. In both cases, and regardless of success or failure, the application
  *          will be informed of the result with a @ref BLE_GAP_EVT_CONN_PARAM_UPDATE event.
  *
- * @note If both a connection supervision timeout and a maximum connection interval are specified, then the following constraint
- *       applies: (conn_sup_timeout * 8) >= (max_conn_interval * (slave_latency + 1))
+ * @details This function can be used as a central both to reply to a @ref BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST or to start the procedure unrequested.
  *
  * @param[in] conn_handle Connection handle.
  * @param[in] p_conn_params  Pointer to desired connection parameters. If NULL is provided on a peripheral role,
  *                           the parameters in the PPCP characteristic of the GAP service will be used instead.
+ *                           If NULL is provided on a central role and in response to a @ref BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST, the peripheral request will be rejected
  *
- * @return @ref NRF_SUCCESS The Connection Update procedure has been started successfully.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, check parameter limits and constraints.
- * @return @ref NRF_ERROR_BUSY Procedure already in progress or not allowed at this time, process pending events and retry.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
- * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
+ * @retval ::NRF_SUCCESS The Connection Update procedure has been started successfully.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, check parameter limits and constraints.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
+ * @retval ::NRF_ERROR_BUSY Procedure already in progress or not allowed at this time, process pending events and wait for pending procedures to complete and retry.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
+ * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation.
  */
-SVCALL(SD_BLE_GAP_CONN_PARAM_UPDATE, uint32_t, sd_ble_gap_conn_param_update(uint16_t conn_handle, ble_gap_conn_params_t const * const p_conn_params));
+SVCALL(SD_BLE_GAP_CONN_PARAM_UPDATE, uint32_t, sd_ble_gap_conn_param_update(uint16_t conn_handle, ble_gap_conn_params_t const *p_conn_params));
 
 
 /**@brief Disconnect (GAP Link Termination).
  *
  * @details This call initiates the disconnection procedure, and its completion will be communicated to the application
- *          with a BLE_GAP_EVT_DISCONNECTED event.
+ *          with a @ref BLE_GAP_EVT_DISCONNECTED event.
  *
  * @param[in] conn_handle Connection handle.
- * @param[in] hci_status_code HCI status code, see @ref BLE_HCI_STATUS_CODES (accepted values are BTLE_REMOTE_USER_TERMINATED_CONNECTION and BTLE_CONN_INTERVAL_UNACCEPTABLE).
+ * @param[in] hci_status_code HCI status code, see @ref BLE_HCI_STATUS_CODES (accepted values are @ref BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION and @ref BLE_HCI_CONN_INTERVAL_UNACCEPTABLE).
  *
- * @return @ref NRF_SUCCESS The disconnection procedure has been started successfully.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
- * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation (disconnection is already in progress or not connected at all).
+ * @retval ::NRF_SUCCESS The disconnection procedure has been started successfully.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation (disconnection is already in progress).
  */
 SVCALL(SD_BLE_GAP_DISCONNECT, uint32_t, sd_ble_gap_disconnect(uint16_t conn_handle, uint8_t hci_status_code));
 
@@ -827,9 +1048,8 @@
  *
  * @note -40 dBm will not actually give -40 dBm, but will instead be remapped to -30 dBm.
  *
- * @return @ref NRF_SUCCESS Successfully changed the transmit power.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
- * @return @ref NRF_ERROR_BUSY The stack is busy, process pending events and retry.
+ * @retval ::NRF_SUCCESS Successfully changed the transmit power.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
  */
 SVCALL(SD_BLE_GAP_TX_POWER_SET, uint32_t, sd_ble_gap_tx_power_set(int8_t tx_power));
 
@@ -838,60 +1058,60 @@
  *
  * @param[in] appearance Appearance (16-bit), see @ref BLE_APPEARANCES.
  *
- * @return @ref NRF_SUCCESS  Appearance value set successfully.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
+ * @retval ::NRF_SUCCESS  Appearance value set successfully.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
  */
 SVCALL(SD_BLE_GAP_APPEARANCE_SET, uint32_t, sd_ble_gap_appearance_set(uint16_t appearance));
 
 
 /**@brief Get GAP Appearance value.
  *
- * @param[out] p_appearance Appearance (16-bit), see @ref BLE_APPEARANCES.
+ * @param[out] p_appearance Pointer to appearance (16-bit) to be filled in, see @ref BLE_APPEARANCES.
  *
- * @return @ref NRF_SUCCESS Appearance value retrieved successfully.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_SUCCESS Appearance value retrieved successfully.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  */
-SVCALL(SD_BLE_GAP_APPEARANCE_GET, uint32_t, sd_ble_gap_appearance_get(uint16_t * const p_appearance));
+SVCALL(SD_BLE_GAP_APPEARANCE_GET, uint32_t, sd_ble_gap_appearance_get(uint16_t *p_appearance));
 
 
 /**@brief Set GAP Peripheral Preferred Connection Parameters.
  *
  * @param[in] p_conn_params Pointer to a @ref ble_gap_conn_params_t structure with the desired parameters.
  *
- * @return @ref NRF_SUCCESS Peripheral Preferred Connection Parameters set successfully.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
+ * @retval ::NRF_SUCCESS Peripheral Preferred Connection Parameters set successfully.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
  */
-SVCALL(SD_BLE_GAP_PPCP_SET, uint32_t, sd_ble_gap_ppcp_set(ble_gap_conn_params_t const * const p_conn_params));
+SVCALL(SD_BLE_GAP_PPCP_SET, uint32_t, sd_ble_gap_ppcp_set(ble_gap_conn_params_t const *p_conn_params));
 
 
 /**@brief Get GAP Peripheral Preferred Connection Parameters.
  *
  * @param[out] p_conn_params Pointer to a @ref ble_gap_conn_params_t structure where the parameters will be stored.
  *
- * @return @ref NRF_SUCCESS Peripheral Preferred Connection Parameters retrieved successfully.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_SUCCESS Peripheral Preferred Connection Parameters retrieved successfully.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  */
-SVCALL(SD_BLE_GAP_PPCP_GET, uint32_t, sd_ble_gap_ppcp_get(ble_gap_conn_params_t * const p_conn_params));
+SVCALL(SD_BLE_GAP_PPCP_GET, uint32_t, sd_ble_gap_ppcp_get(ble_gap_conn_params_t *p_conn_params));
 
 
 /**@brief Set GAP device name.
  *
- * @param[in] p_write_perm Write permissions for the Device Name characteristic see @ref ble_gap_conn_sec_mode_t.
+ * @param[in] p_write_perm Write permissions for the Device Name characteristic, see @ref ble_gap_conn_sec_mode_t.
  * @param[in] p_dev_name Pointer to a UTF-8 encoded, <b>non NULL-terminated</b> string.
- * @param[in] len   Length of the UTF-8, <b>non NULL-terminated</b> string pointed to by p_dev_name in octets (must be smaller or equal than @ref BLE_GAP_DEVNAME_MAX_LEN).
+ * @param[in] len Length of the UTF-8, <b>non NULL-terminated</b> string pointed to by p_dev_name in octets (must be smaller or equal than @ref BLE_GAP_DEVNAME_MAX_LEN).
  *
- * @return @ref NRF_SUCCESS GAP device name and permissions set successfully.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
- * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
+ * @retval ::NRF_SUCCESS GAP device name and permissions set successfully.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
+ * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
  */
-SVCALL(SD_BLE_GAP_DEVICE_NAME_SET, uint32_t, sd_ble_gap_device_name_set(ble_gap_conn_sec_mode_t const * const p_write_perm, uint8_t const * const p_dev_name, uint16_t len));
+SVCALL(SD_BLE_GAP_DEVICE_NAME_SET, uint32_t, sd_ble_gap_device_name_set(ble_gap_conn_sec_mode_t const *p_write_perm, uint8_t const *p_dev_name, uint16_t len));
 
 
 /**@brief Get GAP device name.
  *
- * @param[in]     p_dev_name Pointer to an empty buffer where the UTF-8 <b>non NULL-terminated</b> string will be placed. Set to NULL to obtain the complete device name length.
+ * @param[out]    p_dev_name Pointer to an empty buffer where the UTF-8 <b>non NULL-terminated</b> string will be placed. Set to NULL to obtain the complete device name length.
  * @param[in,out] p_len      Length of the buffer pointed by p_dev_name, complete device name length on output.
  *
  * @note          If the device name is longer than the size of the supplied buffer,
@@ -899,94 +1119,121 @@
  *                and not the number of bytes actually returned in p_dev_name.
  *                The application may use this information to allocate a suitable buffer size.
  *
- * @return @ref NRF_SUCCESS GAP device name retrieved successfully.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
+ * @retval ::NRF_SUCCESS GAP device name retrieved successfully.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
  */
-SVCALL(SD_BLE_GAP_DEVICE_NAME_GET, uint32_t, sd_ble_gap_device_name_get(uint8_t * const p_dev_name, uint16_t * const p_len));
+SVCALL(SD_BLE_GAP_DEVICE_NAME_GET, uint32_t, sd_ble_gap_device_name_get(uint8_t *p_dev_name, uint16_t *p_len));
 
 
-/**@brief Initiate GAP Authentication procedure.
+/**@brief Initiate the GAP Authentication procedure.
  *
  * @param[in] conn_handle Connection handle.
- * @param[in] p_sec_params Pointer to the @ref ble_gap_sec_params_t structure with the security parameters to be used during the pairing procedure.
- *
- * @details In the central role, this function will send an SMP Pairing Request, otherwise in the peripheral role, an SMP Security Request will be sent.
- *          In the peripheral role, only the timeout, bond and mitm fields of @ref ble_gap_sec_params_t are used.
+ * @param[in] p_sec_params Pointer to the @ref ble_gap_sec_params_t structure with the security parameters to be used during the pairing or bonding procedure.
+ *                         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.
  *
- * @note    The GAP Authentication procedure may be triggered by the central without calling this function when accessing a secure service.
+ * @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,
- *          @ref BLE_GAP_EVT_SEC_INFO_REQUEST, @ref BLE_GAP_EVT_AUTH_KEY_REQUEST, @ref BLE_GAP_EVT_AUTH_STATUS.
- * @note    The timeout parameter in @ref ble_gap_sec_params_t is interpreted here as the Security Request timeout
+ *          @ref BLE_GAP_EVT_SEC_INFO_REQUEST, @ref BLE_GAP_EVT_AUTH_KEY_REQUEST, @ref BLE_GAP_EVT_CONN_SEC_UPDATE, @ref BLE_GAP_EVT_AUTH_STATUS.
  *
  *
- * @return @ref NRF_SUCCESS Successfully initiated authentication procedure.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
- * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
- * @return @ref NRF_ERROR_TIMEOUT A SMP timeout has occured, and further SMP operations on this link is prohibited.
+ * @retval ::NRF_SUCCESS Successfully initiated authentication procedure.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
+ * @retval ::NRF_ERROR_BUSY The stack is busy, process pending events and retry.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
+ * @retval ::NRF_ERROR_TIMEOUT A SMP timout has occured, and further SMP operations on this link is prohibited.
  */
-SVCALL(SD_BLE_GAP_AUTHENTICATE, uint32_t, sd_ble_gap_authenticate(uint16_t conn_handle, ble_gap_sec_params_t const * const p_sec_params));
+SVCALL(SD_BLE_GAP_AUTHENTICATE, uint32_t, sd_ble_gap_authenticate(uint16_t conn_handle, ble_gap_sec_params_t const *p_sec_params));
 
 
 /**@brief Reply with GAP security parameters.
  *
  * @param[in] conn_handle Connection handle.
  * @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.
- *
- * @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 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.
- * @note    The timeout parameter in @ref ble_gap_sec_params_t is interpreted here as the SMP procedure timeout, and must be 30 seconds. The function will fail
- *          if the application supplies a different value.
+ * @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 
+ *                         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. 
  *
- * @return @ref NRF_SUCCESS Successfully accepted security parameter from the application.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
- * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
+ * @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.
+ *
+ * @retval ::NRF_SUCCESS Successfully accepted security parameter from the application.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
  */
-SVCALL(SD_BLE_GAP_SEC_PARAMS_REPLY, uint32_t, sd_ble_gap_sec_params_reply(uint16_t conn_handle, uint8_t sec_status, ble_gap_sec_params_t const * const p_sec_params));
+SVCALL(SD_BLE_GAP_SEC_PARAMS_REPLY, uint32_t, sd_ble_gap_sec_params_reply(uint16_t conn_handle, uint8_t sec_status, ble_gap_sec_params_t const *p_sec_params, ble_gap_sec_keyset_t const *p_sec_keyset));
 
 
 /**@brief Reply with an authentication key.
  *
  * @param[in] conn_handle Connection handle.
  * @param[in] key_type See @ref BLE_GAP_AUTH_KEY_TYPES.
- * @param[in] key If key type is BLE_GAP_AUTH_KEY_TYPE_NONE, then NULL.
- *                If key type is BLE_GAP_AUTH_KEY_TYPE_PASSKEY, then a 6-byte ASCII string (digit 0..9 only, no NULL termination).
- *                If key type is BLE_GAP_AUTH_KEY_TYPE_OOB, then a 16-byte OOB key value in Little Endian format.
+ * @param[in] p_key If key type is @ref BLE_GAP_AUTH_KEY_TYPE_NONE, then NULL.
+ *                If key type is @ref BLE_GAP_AUTH_KEY_TYPE_PASSKEY, then a 6-byte ASCII string (digit 0..9 only, no NULL termination).
+ *                If key type is @ref BLE_GAP_AUTH_KEY_TYPE_OOB, then a 16-byte OOB key value in Little Endian format.
  *
- * @details This function is only used to reply to a @ref BLE_GAP_EVT_AUTH_KEY_REQUEST, calling it at other times will result in an NRF_ERROR_INVALID_STATE.
+ * @details This function is only used to reply to a @ref BLE_GAP_EVT_AUTH_KEY_REQUEST, calling it at other times will result in an @ref NRF_ERROR_INVALID_STATE.
  * @note    If the call returns an error code, the request is still pending, and the reply call may be repeated with corrected parameters.
  *
- * @return @ref NRF_SUCCESS Authentication key successfully set.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
- * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
+ * @retval ::NRF_SUCCESS Authentication key successfully set.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
  */
-SVCALL(SD_BLE_GAP_AUTH_KEY_REPLY, uint32_t, sd_ble_gap_auth_key_reply(uint16_t conn_handle, uint8_t key_type, uint8_t const * const key));
+SVCALL(SD_BLE_GAP_AUTH_KEY_REPLY, uint32_t, sd_ble_gap_auth_key_reply(uint16_t conn_handle, uint8_t key_type, uint8_t const *p_key));
+
+
+/**@brief Initiate GAP Encryption procedure.
+ *
+ * @param[in] conn_handle Connection handle.
+ * @param[in] p_master_id Pointer to a @ref ble_gap_master_id_t master identification structure.
+ * @param[in] p_enc_info  Pointer to a @ref ble_gap_enc_info_t encryption information structure.
+ *
+ * @details In the central role, this function will initiate the encryption procedure using the encryption information provided.
+ *
+ * @note    Calling this function may result in the following event depending on the outcome and parameters: @ref BLE_GAP_EVT_CONN_SEC_UPDATE.
+ *
+ * @retval ::NRF_SUCCESS Successfully initiated authentication procedure.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
+ * @retval ::BLE_ERROR_INVALID_ROLE Operation is not supported in the Peripheral role.
+ * @retval ::NRF_ERROR_BUSY Procedure already in progress or not allowed at this time, wait for pending procedures to complete and retry.
+ */
+SVCALL(SD_BLE_GAP_ENCRYPT, uint32_t, sd_ble_gap_encrypt(uint16_t conn_handle, ble_gap_master_id_t const *p_master_id, ble_gap_enc_info_t const *p_enc_info));
 
 
 /**@brief Reply with GAP security information.
  *
  * @param[in] conn_handle Connection handle.
  * @param[in] p_enc_info Pointer to a @ref ble_gap_enc_info_t encryption information structure. May be NULL to signal none is available.
+ * @param[in] p_id_info Pointer to a @ref ble_gap_irk_t identity information structure. May be NULL to signal none is available.
  * @param[in] p_sign_info Pointer to a @ref ble_gap_sign_info_t signing information structure. May be NULL to signal none is available.
  *
- * @details This function is only used to reply to a @ref BLE_GAP_EVT_SEC_INFO_REQUEST, calling it at other times will result in NRF_ERROR_INVALID_STATE.
+ * @details This function is only used to reply to a @ref BLE_GAP_EVT_SEC_INFO_REQUEST, calling it at other times will result in @ref NRF_ERROR_INVALID_STATE.
  * @note    If the call returns an error code, the request is still pending, and the reply call may be repeated with corrected parameters.
- * @note    Data signing is not implemented yet. p_sign_info must therefore be NULL.
+ * @note    Data signing is not yet supported, and p_sign_info must therefore be NULL.
  *
- * @return @ref NRF_SUCCESS Successfully accepted security information.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
- * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
- * @return @ref NRF_ERROR_BUSY The stack is busy, process pending events and retry.
+ * @retval ::NRF_SUCCESS Successfully accepted security information.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
  */
-SVCALL(SD_BLE_GAP_SEC_INFO_REPLY, uint32_t, sd_ble_gap_sec_info_reply(uint16_t conn_handle, ble_gap_enc_info_t const * const p_enc_info, ble_gap_sign_info_t const * const p_sign_info));
+SVCALL(SD_BLE_GAP_SEC_INFO_REPLY, uint32_t, sd_ble_gap_sec_info_reply(uint16_t conn_handle, ble_gap_enc_info_t const *p_enc_info, ble_gap_irk_t const *p_id_info, ble_gap_sign_info_t const *p_sign_info));
 
 
 /**@brief Get the current connection security.
@@ -994,39 +1241,106 @@
  * @param[in]  conn_handle Connection handle.
  * @param[out] p_conn_sec  Pointer to a @ref ble_gap_conn_sec_t structure to be filled in.
  *
- * @return @ref NRF_SUCCESS Current connection security successfully retrieved.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
+ * @retval ::NRF_SUCCESS Current connection security successfully retrieved.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
  */
-SVCALL(SD_BLE_GAP_CONN_SEC_GET, uint32_t, sd_ble_gap_conn_sec_get(uint16_t conn_handle, ble_gap_conn_sec_t * const p_conn_sec));
+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. 
  *
  * A new event is reported whenever the RSSI value changes, until @ref sd_ble_gap_rssi_stop is called.
  *
- * @param[in] conn_handle Connection handle.
+ * @param[in] conn_handle        Connection handle.
+ * @param[in] threshold_dbm      Minimum change in dBm before triggering the @ref BLE_GAP_EVT_RSSI_CHANGED event. Events are disabled if threshold_dbm equals @ref BLE_GAP_RSSI_THRESHOLD_INVALID.
+ * @param[in] skip_count         Number of RSSI samples with a change of threshold_dbm or more before sending a new @ref BLE_GAP_EVT_RSSI_CHANGED event.
  *
- * @return @ref NRF_SUCCESS Successfully activated RSSI reporting.
- * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
+ * @retval ::NRF_SUCCESS                   Successfully activated RSSI reporting.
+ * @retval ::NRF_ERROR_INVALID_STATE       Disconnection in progress. Invalid state to perform operation.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
  */
-SVCALL(SD_BLE_GAP_RSSI_START, uint32_t, sd_ble_gap_rssi_start(uint16_t conn_handle));
+SVCALL(SD_BLE_GAP_RSSI_START, uint32_t, sd_ble_gap_rssi_start(uint16_t conn_handle, uint8_t threshold_dbm, uint8_t skip_count));
 
 
-/**@brief Stop reporting the received singnal strength. 
+/**@brief Stop reporting the received signal strength.
  *
- * 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.
  *
- * @return @ref NRF_SUCCESS Successfully deactivated RSSI reporting.
- * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
+ * @retval ::NRF_SUCCESS                   Successfully deactivated RSSI reporting.
+ * @retval ::NRF_ERROR_INVALID_STATE       Invalid state to perform operation.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
  */
 SVCALL(SD_BLE_GAP_RSSI_STOP, uint32_t, sd_ble_gap_rssi_stop(uint16_t conn_handle));
-/**@} */
+
+
+/**@brief Get the received signal strength for the last connection event.
+ *
+ * @param[in]  conn_handle Connection handle.
+ * @param[out] p_rssi      Pointer to the location where the RSSI measurement shall be stored.
+ *
+ * @ref sd_ble_gap_rssi_start must be called to start reporting RSSI before using this function. @ref NRF_ERROR_NOT_FOUND
+ * will be returned until RSSI was sampled for the first time after calling @ref sd_ble_gap_rssi_start.
+ *
+ * @retval ::NRF_SUCCESS                   Successfully read the RSSI.
+ * @retval ::NRF_ERROR_NOT_FOUND           No sample is available.
+ * @retval ::NRF_ERROR_INVALID_ADDR        Invalid pointer supplied.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
+ * @retval ::NRF_ERROR_INVALID_STATE       RSSI reporting is not ongoing, or disconnection in progress.
+ */
+SVCALL(SD_BLE_GAP_RSSI_GET, uint32_t, sd_ble_gap_rssi_get(uint16_t conn_handle, int8_t *p_rssi));
+
+
+/**@brief Start scanning (GAP Discovery procedure, Observer Procedure).
+ *
+ * @param[in] p_scan_params Pointer to scan parameters structure.
+ *
+ * @retval ::NRF_SUCCESS Successfully initiated scanning procedure.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
+ * @retval ::NRF_ERROR_BUSY The stack is busy, process pending events and retry.
+ * @retval ::NRF_ERROR_NOT_SUPPORTED A selected feature is not supported (selective scanning).
+ */
+SVCALL(SD_BLE_GAP_SCAN_START, uint32_t, sd_ble_gap_scan_start(ble_gap_scan_params_t const *p_scan_params));
+
+
+/**@brief Stop scanning (GAP Discovery procedure, Observer Procedure).
+ *
+ * @retval ::NRF_SUCCESS Successfully stopped scanning procedure.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation (most probably not in scanning state).
+ */
+SVCALL(SD_BLE_GAP_SCAN_STOP, uint32_t, sd_ble_gap_scan_stop(void));
+
+
+/**@brief Create a connection (GAP Link Establishment).
+ *
+ * @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.
+ * @param[in] p_conn_params Pointer to desired connection parameters.
+ *
+ * @retval ::NRF_SUCCESS Successfully initiated connection procedure.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid parameter(s) pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
+ * @retval ::BLE_ERROR_GAP_INVALID_BLE_ADDR Invalid Peer address.
+ * @retval ::NRF_ERROR_NO_MEM limit of available connections reached.
+ * @retval ::NRF_ERROR_BUSY The stack is busy, process pending events and retry.
+*/
+SVCALL(SD_BLE_GAP_CONNECT, uint32_t, sd_ble_gap_connect(ble_gap_addr_t const *p_peer_addr, ble_gap_scan_params_t const *p_scan_params, ble_gap_conn_params_t const *p_conn_params));
+
+
+/**@brief Cancel a connection establishment.
+ *
+ * @retval ::NRF_SUCCESS Successfully cancelled an ongoing connection procedure.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
+ */
+SVCALL(SD_BLE_GAP_CONNECT_CANCEL, uint32_t, sd_ble_gap_connect_cancel(void));
+
+/** @} */
 
 #endif // BLE_GAP_H__
 
--- a/nordic-sdk/components/softdevice/s110/headers/ble_gatt.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/s110/headers/ble_gatt.h	Thu Apr 30 08:34:37 2015 +0100
@@ -1,11 +1,40 @@
-/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is confidential property of Nordic Semiconductor. The use,
- * copying, transfer or disclosure of such information is prohibited except by express written
- * agreement with Nordic Semiconductor.
- *
+/* 
+ * 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.
+ * 
+ *   4. This software must only be used in a processor manufactured by Nordic
+ *   Semiconductor ASA, or in a processor manufactured by a third party that
+ *   is used in combination with a processor manufactured by Nordic Semiconductor.
+ * 
+ * 
+ * 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.
+ * 
  */
- /**
+
+/**
   @addtogroup BLE_GATT Generic Attribute Profile (GATT) Common
   @{
   @brief  Common definitions and prototypes for the GATT interfaces.
@@ -131,8 +160,8 @@
 /** @defgroup BLE_GATT_CPF_NAMESPACES GATT Bluetooth Namespaces
  * @{
  */
-#define BLE_GATT_CPF_NAMESPACE_BTSIG            0x01
-#define BLE_GATT_CPF_NAMESPACE_DESCRIPTION_UNKNOWN 0x0000
+#define BLE_GATT_CPF_NAMESPACE_BTSIG            0x01 /**< Bluetooth SIG defined Namespace. */
+#define BLE_GATT_CPF_NAMESPACE_DESCRIPTION_UNKNOWN 0x0000 /**< Namespace Description Unknown. */
 /** @} */
 
 /** @} */
@@ -144,21 +173,21 @@
 typedef struct
 {
   /* Standard properties */
-  uint8_t broadcast       :1; /**< Broadcasting of value permitted. */
-  uint8_t read            :1; /**< Reading value permitted. */
-  uint8_t write_wo_resp   :1; /**< Writing value with Write Command permitted. */
-  uint8_t write           :1; /**< Writing value with Write Request permitted. */
-  uint8_t notify          :1; /**< Notications of value permitted. */
-  uint8_t indicate        :1; /**< Indications of value permitted. */
-  uint8_t auth_signed_wr  :1; /**< Writing value with Signed Write Command permitted. */
+  uint8_t broadcast       :1; /**< Broadcasting of the value permitted. */
+  uint8_t read            :1; /**< Reading the value permitted. */
+  uint8_t write_wo_resp   :1; /**< Writing the value with Write Command permitted. */
+  uint8_t write           :1; /**< Writing the value with Write Request permitted. */
+  uint8_t notify          :1; /**< Notications of the value permitted. */
+  uint8_t indicate        :1; /**< Indications of the value permitted. */
+  uint8_t auth_signed_wr  :1; /**< Writing the value with Signed Write Command permitted. */
 } ble_gatt_char_props_t;
 
 /**@brief GATT Characteristic Extended Properties. */
 typedef struct
 {
   /* Extended properties */
-  uint8_t reliable_wr     :1; /**< Writing value with Queued Write Request permitted. */
-  uint8_t wr_aux          :1; /**< Writing the Characteristic User Description permitted. */
+  uint8_t reliable_wr     :1; /**< Writing the value with Queued Write operations permitted. */
+  uint8_t wr_aux          :1; /**< Writing the Characteristic User Description descriptor permitted. */
 } ble_gatt_char_ext_props_t;
 
 #endif // BLE_GATT_H__
--- a/nordic-sdk/components/softdevice/s110/headers/ble_gattc.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/s110/headers/ble_gattc.h	Thu Apr 30 08:34:37 2015 +0100
@@ -1,10 +1,39 @@
-/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is confidential property of Nordic Semiconductor. The use,
- * copying, transfer or disclosure of such information is prohibited except by express written
- * agreement with Nordic Semiconductor.
- *
+/* 
+ * 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.
+ * 
+ *   4. This software must only be used in a processor manufactured by Nordic
+ *   Semiconductor ASA, or in a processor manufactured by a third party that
+ *   is used in combination with a processor manufactured by Nordic Semiconductor.
+ * 
+ * 
+ * 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.
+ * 
  */
+
 /**
   @addtogroup BLE_GATTC Generic Attribute Profile (GATT) Client
   @{
@@ -36,6 +65,23 @@
   SD_BLE_GATTC_HV_CONFIRM                                      /**< Handle Value Confirmation. */
 };
 
+/**
+ * @brief GATT Client Event IDs.
+ */
+enum BLE_GATTC_EVTS
+{
+  BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP = BLE_GATTC_EVT_BASE,  /**< Primary Service Discovery Response event. @ref ble_gattc_evt_prim_srvc_disc_rsp_t */
+  BLE_GATTC_EVT_REL_DISC_RSP,                             /**< Relationship Discovery Response event. @ref ble_gattc_evt_rel_disc_rsp_t */
+  BLE_GATTC_EVT_CHAR_DISC_RSP,                            /**< Characteristic Discovery Response event. @ref ble_gattc_evt_char_disc_rsp_t */
+  BLE_GATTC_EVT_DESC_DISC_RSP,                            /**< Descriptor Discovery Response event. @ref ble_gattc_evt_desc_disc_rsp_t */
+  BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP,                /**< Read By UUID Response event. @ref ble_gattc_evt_char_val_by_uuid_read_rsp_t */
+  BLE_GATTC_EVT_READ_RSP,                                 /**< Read Response event. @ref ble_gattc_evt_read_rsp_t */
+  BLE_GATTC_EVT_CHAR_VALS_READ_RSP,                       /**< Read multiple Response event. @ref ble_gattc_evt_char_vals_read_rsp_t */
+  BLE_GATTC_EVT_WRITE_RSP,                                /**< Write Response event. @ref ble_gattc_evt_write_rsp_t */
+  BLE_GATTC_EVT_HVX,                                      /**< Handle Value Notification or Indication event. @ref ble_gattc_evt_hvx_t */
+  BLE_GATTC_EVT_TIMEOUT                                   /**< Timeout event. @ref ble_gattc_evt_timeout_t */
+};
+
 /** @} */
 
 /** @addtogroup BLE_GATTC_DEFINES Defines
@@ -43,7 +89,7 @@
 
 /** @defgroup BLE_ERRORS_GATTC SVC return values specific to GATTC
  * @{ */
-#define BLE_ERROR_GATTC_PROC_NOT_PERMITTED    (NRF_GATTC_ERR_BASE + 0x000)
+#define BLE_ERROR_GATTC_PROC_NOT_PERMITTED    (NRF_GATTC_ERR_BASE + 0x000) /**< Procedure not Permitted. */
 /** @} */
 
 /**@brief Last Attribute Handle. */
@@ -101,53 +147,35 @@
 typedef struct
 {
   uint8_t    write_op;                 /**< Write Operation to be performed, see @ref BLE_GATT_WRITE_OPS. */
+  uint8_t    flags;                    /**< Flags, see @ref BLE_GATT_EXEC_WRITE_FLAGS. */
   uint16_t   handle;                   /**< Handle to the attribute to be written. */
   uint16_t   offset;                   /**< Offset in bytes. @note For WRITE_CMD and WRITE_REQ, offset must be 0. */
   uint16_t   len;                      /**< Length of data in bytes. */
-  uint8_t*   p_value;                  /**< Pointer to the value data. */
-  uint8_t    flags;                    /**< Flags, see @ref BLE_GATT_EXEC_WRITE_FLAGS. */
+  uint8_t   *p_value;                  /**< Pointer to the value data. */
 } ble_gattc_write_params_t;
 
-
-/**
- * @brief GATT Client Event IDs.
- */
-enum BLE_GATTC_EVTS
-{
-  BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP = BLE_GATTC_EVT_BASE,  /**< Primary Service Discovery Response event.  */
-  BLE_GATTC_EVT_REL_DISC_RSP,                             /**< Relationship Discovery Response event. */
-  BLE_GATTC_EVT_CHAR_DISC_RSP,                            /**< Characteristic Discovery Response event. */
-  BLE_GATTC_EVT_DESC_DISC_RSP,                            /**< Descriptor Discovery Response event. */
-  BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP,                /**< Read By UUID Response event. */
-  BLE_GATTC_EVT_READ_RSP,                                 /**< Read Response event. */
-  BLE_GATTC_EVT_CHAR_VALS_READ_RSP,                       /**< Read multiple Response event. */
-  BLE_GATTC_EVT_WRITE_RSP,                                /**< Write Response event. */
-  BLE_GATTC_EVT_HVX,                                      /**< Handle Value Notification or Indication event. */
-  BLE_GATTC_EVT_TIMEOUT                                   /**< Timeout event. */
-};
-
-/**@brief Event structure for BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP. */
+/**@brief Event structure for @ref BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP. */
 typedef struct
 {
   uint16_t             count;           /**< Service count. */
   ble_gattc_service_t services[1];      /**< Service data, variable length. */
 } ble_gattc_evt_prim_srvc_disc_rsp_t;
 
-/**@brief Event structure for BLE_GATTC_EVT_REL_DISC_RSP. */
+/**@brief Event structure for @ref BLE_GATTC_EVT_REL_DISC_RSP. */
 typedef struct
 {
   uint16_t             count;           /**< Include count. */
   ble_gattc_include_t includes[1];      /**< Include data, variable length. */
 } ble_gattc_evt_rel_disc_rsp_t;
 
-/**@brief Event structure for BLE_GATTC_EVT_CHAR_DISC_RSP. */
+/**@brief Event structure for @ref BLE_GATTC_EVT_CHAR_DISC_RSP. */
 typedef struct
 {
   uint16_t            count;          /**< Characteristic count. */
   ble_gattc_char_t    chars[1];       /**< Characteristic data, variable length. */
 } ble_gattc_evt_char_disc_rsp_t;
 
-/**@brief Event structure for BLE_GATTC_EVT_DESC_DISC_RSP. */
+/**@brief Event structure for @ref BLE_GATTC_EVT_DESC_DISC_RSP. */
 typedef struct
 {
   uint16_t            count;          /**< Descriptor count. */
@@ -158,12 +186,12 @@
 typedef struct 
 {
   uint16_t            handle;          /**< Attribute Handle. */
-  uint8_t             *p_value;        /**< Pointer to value, variable length (length available as value_len in ble_gattc_evt_read_by_uuid_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;
 
-/**@brief Event structure for BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP. */
+/**@brief Event structure for @ref BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP. */
 typedef struct
 {
   uint16_t                  count;            /**< Handle-Value Pair Count. */
@@ -171,7 +199,7 @@
   ble_gattc_handle_value_t  handle_value[1];  /**< Handle-Value(s) list, variable length. */
 } ble_gattc_evt_char_val_by_uuid_read_rsp_t;
 
-/**@brief Event structure for BLE_GATTC_EVT_READ_RSP. */
+/**@brief Event structure for @ref BLE_GATTC_EVT_READ_RSP. */
 typedef struct
 {
   uint16_t            handle;         /**< Attribute Handle. */
@@ -180,24 +208,24 @@
   uint8_t             data[1];        /**< Attribute data, variable length. */
 } ble_gattc_evt_read_rsp_t;
 
-/**@brief Event structure for BLE_GATTC_EVT_CHAR_VALS_READ_RSP. */
+/**@brief Event structure for @ref BLE_GATTC_EVT_CHAR_VALS_READ_RSP. */
 typedef struct
 {
   uint16_t            len;            /**< Concatenated Attribute values length. */
   uint8_t             values[1];      /**< Attribute values, variable length. */
 } ble_gattc_evt_char_vals_read_rsp_t;
 
-/**@brief Event structure for BLE_GATTC_EVT_WRITE_RSP. */
+/**@brief Event structure for @ref BLE_GATTC_EVT_WRITE_RSP. */
 typedef struct
 {
   uint16_t            handle;           /**< Attribute Handle. */
   uint8_t             write_op;         /**< Type of write operation, see @ref BLE_GATT_WRITE_OPS. */
-  uint16_t            offset;           /**< Data Offset. */
+  uint16_t            offset;           /**< Data offset. */
   uint16_t            len;              /**< Data length. */
   uint8_t             data[1];          /**< Data, variable length. */
 } ble_gattc_evt_write_rsp_t;
 
-/**@brief Event structure for BLE_GATTC_EVT_HVX. */
+/**@brief Event structure for @ref BLE_GATTC_EVT_HVX. */
 typedef struct
 {
   uint16_t            handle;         /**< Handle to which the HVx operation applies. */
@@ -206,18 +234,18 @@
   uint8_t             data[1];        /**< Attribute data, variable length. */
 } ble_gattc_evt_hvx_t;
 
-/**@brief Event structure for BLE_GATTC_EVT_TIMEOUT. */
+/**@brief Event structure for @ref BLE_GATTC_EVT_TIMEOUT. */
 typedef struct
 {
   uint8_t          src;                       /**< Timeout source, see @ref BLE_GATT_TIMEOUT_SOURCES. */
 } ble_gattc_evt_timeout_t;
 
-/**@brief GATTC event type. */
+/**@brief GATTC event structure. */
 typedef struct
 {
   uint16_t            conn_handle;                /**< Connection Handle on which event occured. */
   uint16_t            gatt_status;                /**< GATT status code for the operation, see @ref BLE_GATT_STATUS_CODES. */
-  uint16_t            error_handle;               /**< In case of error: The handle causing the error. In all other cases BLE_GATT_HANDLE_INVALID. */
+  uint16_t            error_handle;               /**< In case of error: The handle causing the error. In all other cases @ref BLE_GATT_HANDLE_INVALID. */
   union
   {
     ble_gattc_evt_prim_srvc_disc_rsp_t          prim_srvc_disc_rsp;         /**< Primary Service Discovery Response Event Parameters. */
@@ -230,7 +258,7 @@
     ble_gattc_evt_write_rsp_t                   write_rsp;                  /**< Write Response Event Parameters. */
     ble_gattc_evt_hvx_t                         hvx;                        /**< Handle Value Notification/Indication Event Parameters. */
     ble_gattc_evt_timeout_t                     timeout;                    /**< Timeout Event Parameters. */
-  } params;                                                                 /**< Event Parameters. @note Only valid if @ref gatt_status == BLE_GATT_STATUS_SUCCESS. */
+  } params;                                                                 /**< Event Parameters. @note Only valid if @ref gatt_status == @ref BLE_GATT_STATUS_SUCCESS. */
 } ble_gattc_evt_t;
 /** @} */
 
@@ -239,107 +267,113 @@
 
 /**@brief Initiate or continue a GATT Primary Service Discovery procedure.
  *
- * @details This function initiates a Primary Service discovery, starting from the supplied handle. 
- *          If the last service has not been reached, this must be called again with an updated start handle value to continue the search.
+ * @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
- *       type BLE_UUID_TYPE_UNKNOWN will be received in the corresponding event.
+ *       type @ref BLE_UUID_TYPE_UNKNOWN will be received in the corresponding event.
  *
  * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
  * @param[in] start_handle Handle to start searching from.
  * @param[in] p_srvc_uuid Pointer to the service UUID to be found. If it is NULL, all primary services will be returned.
  *
- * @return @ref NRF_SUCCESS Successfully started or resumed the Primary Service Discovery procedure.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
- * @return @ref NRF_ERROR_BUSY Client procedure already in progress.
+ * @retval ::NRF_SUCCESS Successfully started or resumed the Primary Service Discovery procedure.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
+ * @retval ::NRF_ERROR_BUSY Client procedure already in progress.
  */
-SVCALL(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER, uint32_t, sd_ble_gattc_primary_services_discover(uint16_t conn_handle, uint16_t start_handle, ble_uuid_t const * const p_srvc_uuid));
+SVCALL(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER, uint32_t, sd_ble_gattc_primary_services_discover(uint16_t conn_handle, uint16_t start_handle, ble_uuid_t const *p_srvc_uuid));
 
 
 /**@brief Initiate or continue a GATT Relationship Discovery procedure.
  *
- * @details This function initiates the Find Included Services sub-procedure. If the last included service has not been reached,
+ * @details This function initiates or resumes the Find Included Services sub-procedure. If the last included service has not been reached,
  *          this must be called again with an updated handle range to continue the search.
  *
  * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
  * @param[in] p_handle_range A pointer to the range of handles of the Service to perform this procedure on.
  *
- * @return @ref NRF_SUCCESS Successfully started or resumed the Relationship Discovery procedure.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
- * @return @ref NRF_ERROR_BUSY Client procedure already in progress.
+ * @retval ::NRF_SUCCESS Successfully started or resumed the Relationship Discovery procedure.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
+ * @retval ::NRF_ERROR_BUSY Client procedure already in progress.
  */
-SVCALL(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER, uint32_t, sd_ble_gattc_relationships_discover(uint16_t conn_handle, ble_gattc_handle_range_t const * const p_handle_range));
+SVCALL(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER, uint32_t, sd_ble_gattc_relationships_discover(uint16_t conn_handle, ble_gattc_handle_range_t const *p_handle_range));
 
 
 /**@brief Initiate or continue a GATT Characteristic Discovery procedure.
  *
- * @details This function initiates a Characteristic discovery procedure. If the last Characteristic has not been reached,
+ * @details This function initiates or resumes a Characteristic discovery procedure. If the last Characteristic has not been reached,
  *          this must be called again with an updated handle range to continue the discovery.
  *
  * @note If any of the discovered characteristics have 128-bit UUIDs which are not present in the table provided to ble_vs_uuids_assign, a UUID structure with
- *       type BLE_UUID_TYPE_UNKNOWN will be received in the corresponding event.
+ *       type @ref BLE_UUID_TYPE_UNKNOWN will be received in the corresponding event.
  *
  * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
  * @param[in] p_handle_range A pointer to the range of handles of the Service to perform this procedure on.
  *
- * @return @ref NRF_SUCCESS Successfully started or resumed the Characteristic Discovery procedure.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_BUSY Client procedure already in progress.
+ * @retval ::NRF_SUCCESS Successfully started or resumed the Characteristic Discovery procedure.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_BUSY Client procedure already in progress.
  */
-SVCALL(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER, uint32_t, sd_ble_gattc_characteristics_discover(uint16_t conn_handle, ble_gattc_handle_range_t const * const p_handle_range));
+SVCALL(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER, uint32_t, sd_ble_gattc_characteristics_discover(uint16_t conn_handle, ble_gattc_handle_range_t const *p_handle_range));
 
 
 /**@brief Initiate or continue a GATT Characteristic Descriptor Discovery procedure.
  *
- * @details This function initiates the Characteristic Descriptor discovery procedure. If the last Descriptor has not been reached,
+ * @details This function initiates or resumes a Characteristic Descriptor discovery procedure. If the last Descriptor has not been reached,
  *          this must be called again with an updated handle range to continue the discovery.
  *
  * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
  * @param[in] p_handle_range A pointer to the range of handles of the Characteristic to perform this procedure on.
  *
- * @return @ref NRF_SUCCESS Successfully started or resumed the Descriptor Discovery procedure.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_BUSY Client procedure already in progress.
+ * @retval ::NRF_SUCCESS Successfully started or resumed the Descriptor Discovery procedure.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_BUSY Client procedure already in progress.
  */
-SVCALL(SD_BLE_GATTC_DESCRIPTORS_DISCOVER, uint32_t, sd_ble_gattc_descriptors_discover(uint16_t conn_handle, ble_gattc_handle_range_t const * const p_handle_range));
+SVCALL(SD_BLE_GATTC_DESCRIPTORS_DISCOVER, uint32_t, sd_ble_gattc_descriptors_discover(uint16_t conn_handle, ble_gattc_handle_range_t const *p_handle_range));
 
 
 /**@brief Initiate or continue a GATT Read using Characteristic UUID procedure.
  *
- * @details This function initiates the Read using Characteristic UUID procedure. If the last Characteristic has not been reached,
+ * @details This function initiates or resumes a Read using Characteristic UUID procedure. If the last Characteristic has not been reached,
  *          this must be called again with an updated handle range to continue the discovery.
  *
  * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
  * @param[in] p_uuid Pointer to a Characteristic value UUID to read.
  * @param[in] p_handle_range A pointer to the range of handles to perform this procedure on.
  *
- * @return @ref NRF_SUCCESS Successfully started or resumed the Read using Characteristic UUID procedure.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_BUSY Client procedure already in progress.
+ * @retval ::NRF_SUCCESS Successfully started or resumed the Read using Characteristic UUID procedure.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_BUSY Client procedure already in progress.
  */
-SVCALL(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ, uint32_t, sd_ble_gattc_char_value_by_uuid_read(uint16_t conn_handle, ble_uuid_t const * const p_uuid, ble_gattc_handle_range_t const * const p_handle_range));
+SVCALL(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ, uint32_t, sd_ble_gattc_char_value_by_uuid_read(uint16_t conn_handle, ble_uuid_t const *p_uuid, ble_gattc_handle_range_t const *p_handle_range));
 
 
 /**@brief Initiate or continue a GATT Read (Long) Characteristic or Descriptor procedure.
  *
- * @details This function initiates a GATT Read (Long) Characteristic or Descriptor procedure. If the Characteristic or Descriptor
- *          to be read is longer than GATT_MTU - 1, this function must be called multiple times with appropriate offset to read the 
+ * @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 
  *          complete value.
  *
  * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
  * @param[in] handle The handle of the attribute to be read.
  * @param[in] offset Offset into the attribute value to be read.
  *
- * @return @ref NRF_SUCCESS Successfully started or resumed the Read (Long) procedure.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_BUSY Client procedure already in progress.
+ * @retval ::NRF_SUCCESS Successfully started or resumed the Read (Long) procedure.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_BUSY Client procedure already in progress.
  */
 SVCALL(SD_BLE_GATTC_READ, uint32_t, sd_ble_gattc_read(uint16_t conn_handle, uint16_t handle, uint16_t offset));
 
@@ -352,12 +386,13 @@
  * @param[in] p_handles A pointer to the handle(s) of the attribute(s) to be read.
  * @param[in] handle_count The number of handles in p_handles.
  *
- * @return @ref NRF_SUCCESS Successfully started the Read Multiple Characteristic Values procedure.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_BUSY Client procedure already in progress.
+ * @retval ::NRF_SUCCESS Successfully started the Read Multiple Characteristic Values procedure.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_BUSY Client procedure already in progress.
  */
-SVCALL(SD_BLE_GATTC_CHAR_VALUES_READ, uint32_t, sd_ble_gattc_char_values_read(uint16_t conn_handle, uint16_t const * const p_handles, uint16_t handle_count));
+SVCALL(SD_BLE_GATTC_CHAR_VALUES_READ, uint32_t, sd_ble_gattc_char_values_read(uint16_t conn_handle, uint16_t const *p_handles, uint16_t handle_count));
 
 
 /**@brief Perform a Write (Characteristic Value or Descriptor, with or without response, signed or not, long or reliable) procedure.
@@ -365,22 +400,23 @@
  * @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 on the other hand will use the 
+ *          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.
  * @param[in] p_write_params A pointer to a write parameters structure.
  *
- * @return @ref NRF_SUCCESS Successfully started the Write procedure.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
- * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
- * @return @ref NRF_ERROR_BUSY Procedure already in progress.
- * @return @ref BLE_ERROR_NO_TX_BUFFERS There are no available buffers left.
+ * @retval ::NRF_SUCCESS Successfully started the Write procedure.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
+ * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
+ * @retval ::NRF_ERROR_BUSY Procedure already in progress.
+ * @retval ::BLE_ERROR_NO_TX_BUFFERS There are no available buffers left.
  */
-SVCALL(SD_BLE_GATTC_WRITE, uint32_t, sd_ble_gattc_write(uint16_t conn_handle, ble_gattc_write_params_t const * const p_write_params));
+SVCALL(SD_BLE_GATTC_WRITE, uint32_t, sd_ble_gattc_write(uint16_t conn_handle, ble_gattc_write_params_t const *p_write_params));
 
 
 /**@brief Send a Handle Value Confirmation to the GATT Server.
@@ -388,11 +424,10 @@
  * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
  * @param[in] handle The handle of the attribute in the indication.
  *
- * @return @ref NRF_SUCCESS Successfully queued the Handle Value Confirmation for transmission.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
- * @return @ref NRF_ERROR_INVALID_STATE No Indication pending to be confirmed.
- * @return @ref BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle.
- * @return @ref BLE_ERROR_NO_TX_BUFFERS There are no available buffers left.
+ * @retval ::NRF_SUCCESS Successfully queued the Handle Value Confirmation for transmission.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State or no Indication pending to be confirmed.
+ * @retval ::BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle.
  */
 SVCALL(SD_BLE_GATTC_HV_CONFIRM, uint32_t, sd_ble_gattc_hv_confirm(uint16_t conn_handle, uint16_t handle));
 
--- a/nordic-sdk/components/softdevice/s110/headers/ble_gatts.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/s110/headers/ble_gatts.h	Thu Apr 30 08:34:37 2015 +0100
@@ -1,10 +1,39 @@
-/* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is confidential property of Nordic Semiconductor. The use,
- * copying, transfer or disclosure of such information is prohibited except by express written
- * agreement with Nordic Semiconductor.
- *
+/* 
+ * 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.
+ * 
+ *   4. This software must only be used in a processor manufactured by Nordic
+ *   Semiconductor ASA, or in a processor manufactured by a third party that
+ *   is used in combination with a processor manufactured by Nordic Semiconductor.
+ * 
+ * 
+ * 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.
+ * 
  */
+
 /**
   @addtogroup BLE_GATTS Generic Attribute Profile (GATT) Server
   @{
@@ -39,17 +68,26 @@
   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_SYS_ATTR_GET,                     /**< Get updated persistent system attributes after terminating a connection. */
+  SD_BLE_GATTS_SYS_ATTR_GET,                     /**< Retrieve the persistent system attributes. */
 };
 
+/**
+ * @brief GATT Server Event IDs.
+ */
+enum BLE_GATTS_EVTS
+{
+  BLE_GATTS_EVT_WRITE = BLE_GATTS_EVT_BASE,       /**< Write operation performed. @ref ble_gatts_evt_write_t */
+  BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST,             /**< Read/Write Authorization request.@ref ble_gatts_evt_rw_authorize_request_t */
+  BLE_GATTS_EVT_SYS_ATTR_MISSING,                 /**< A persistent system attribute access is pending, awaiting a sd_ble_gatts_sys_attr_set(). @ref ble_gatts_evt_sys_attr_missing_t */
+  BLE_GATTS_EVT_HVC,                              /**< Handle Value Confirmation. @ref ble_gatts_evt_hvc_t */
+  BLE_GATTS_EVT_SC_CONFIRM,                       /**< Service Changed Confirmation. No additional event structure applies. */
+  BLE_GATTS_EVT_TIMEOUT                           /**< Timeout. @ref ble_gatts_evt_timeout_t */
+};
 /** @} */
 
 /** @addtogroup BLE_GATTS_DEFINES Defines
  * @{ */
 
-/** @brief Only the default MTU size of 23 is currently supported. */
-#define GATT_RX_MTU 23
-
 /** @defgroup BLE_ERRORS_GATTS SVC return values specific to GATTS
  * @{ */
 #define BLE_ERROR_GATTS_INVALID_ATTR_TYPE   (NRF_GATTS_ERR_BASE + 0x000) /**< Invalid attribute type. */
@@ -109,6 +147,18 @@
 #define BLE_GATTS_AUTHORIZE_TYPE_WRITE      0x02  /**< Authorize a Write Request Operation. */
 /** @} */
 
+/** @defgroup BLE_GATTS_SYS_ATTR_FLAGS System Attribute Flags
+ * @{ */
+#define BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS (1 << 0)  /**< Restrict system attributes to system services only. */
+#define BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS (1 << 1)  /**< Restrict system attributes to user services only. */
+/** @} */
+
+/** @defgroup BLE_GATTS_ATTR_TAB_SIZE Attribute Table size
+ * @{
+ */
+#define BLE_GATTS_ATTR_TAB_SIZE_MIN         216    /**< Minimum Attribute Table size */
+#define BLE_GATTS_ATTR_TAB_SIZE_DEFAULT     0x0000 /**< Default Attribute Table size (0x700 bytes for this version of the SoftDevice). */
+/** @} */
 
 /** @} */
 
@@ -120,7 +170,8 @@
  */
 typedef struct
 {
-  uint8_t   service_changed:1;             /**< Include the Service Changed characteristic in the local attributes. */
+  uint8_t   service_changed:1;             /**< Include the Service Changed characteristic in the Attribute Table. */
+  uint32_t  attr_tab_size;                 /**< Attribute Table size in bytes. The size must be a multiple of 4. @ref BLE_GATTS_ATTR_TAB_SIZE_DEFAULT is used to set the default size. */
 } ble_gatts_enable_params_t;
 
 /**@brief Attribute metadata. */
@@ -130,33 +181,43 @@
   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                 wr_auth    :1;   /**< Write Authorization will be requested from the application on every Write Request operation (but not Write Command). */
+  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;
 
 
 /**@brief GATT Attribute. */
 typedef struct
 {
-  ble_uuid_t*          p_uuid;          /**< Pointer to the attribute UUID. */
-  ble_gatts_attr_md_t* p_attr_md;       /**< Pointer to the attribute metadata structure. */
+  ble_uuid_t          *p_uuid;          /**< Pointer to the attribute UUID. */
+  ble_gatts_attr_md_t *p_attr_md;       /**< Pointer to the attribute metadata structure. */
   uint16_t             init_len;        /**< Initial attribute value length in bytes. */
   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. 
-                                             The stack may access that memory directly without the application's knowledge. */
+                                             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;
 
+/**@brief GATT Attribute Value. */
+typedef struct
+{
+  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. 
+                             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;
+
 
 /**@brief GATT Attribute Context. */
 typedef struct
 {
   ble_uuid_t           srvc_uuid;       /**< Service UUID. */
-  ble_uuid_t           char_uuid;       /**< Characteristic UUID if applicable (BLE_UUID_TYPE_UNKNOWN if N/A). */
-  ble_uuid_t           desc_uuid;       /**< Descriptor UUID if applicable (BLE_UUID_TYPE_UNKNOWN if N/A). */
+  ble_uuid_t           char_uuid;       /**< Characteristic UUID if applicable (BLE_UUID_TYPE_UNKNOWN otherwise). */
+  ble_uuid_t           desc_uuid;       /**< Descriptor UUID if applicable (BLE_UUID_TYPE_UNKNOWN otherwise). */
   uint16_t             srvc_handle;     /**< Service Handle. */
-  uint16_t             value_handle;    /**< Characteristic Handle if applicable (BLE_GATT_HANDLE_INVALID if N/A). */
+  uint16_t             value_handle;    /**< Characteristic Value Handle if applicable (BLE_GATT_HANDLE_INVALID otherwise). */
   uint8_t              type;            /**< Attribute Type, see @ref BLE_GATTS_ATTR_TYPES. */
 } ble_gatts_attr_context_t;
 
@@ -166,7 +227,7 @@
 {
   uint8_t          format;      /**< Format of the value, see @ref BLE_GATT_CPF_FORMATS. */
   int8_t           exponent;    /**< Exponent for integer data types. */
-  uint16_t         unit;        /**< UUID from Bluetooth Assigned Numbers. */
+  uint16_t         unit;        /**< Unit from Bluetooth Assigned Numbers. */
   uint8_t          name_space;  /**< Namespace from Bluetooth Assigned Numbers, see @ref BLE_GATT_CPF_NAMESPACES. */
   uint16_t         desc;        /**< Namespace description from Bluetooth Assigned Numbers, see @ref BLE_GATT_CPF_NAMESPACES. */
 } ble_gatts_char_pf_t;
@@ -177,10 +238,10 @@
 {
   ble_gatt_char_props_t       char_props;               /**< Characteristic Properties. */
   ble_gatt_char_ext_props_t   char_ext_props;           /**< Characteristic Extended Properties. */
-  uint8_t*                    p_char_user_desc;         /**< Pointer to a UTF-8, NULL if the descriptor is not required. */
+  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. */ 
-  ble_gatts_char_pf_t*        p_char_pf;                /**< Pointer to a presentation format structure or NULL if the descriptor is not required. */
+  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. */
   ble_gatts_attr_md_t*        p_sccd_md;                /**< Attribute metadata for the Server Characteristic Configuration Descriptor, or NULL for default values. */
@@ -191,9 +252,9 @@
 typedef struct
 {
   uint16_t          value_handle;       /**< Handle to the characteristic value. */
-  uint16_t          user_desc_handle;   /**< Handle to the User Description descriptor, or BLE_GATT_HANDLE_INVALID if not present. */
-  uint16_t          cccd_handle;        /**< Handle to the Client Characteristic Configuration Descriptor, or BLE_GATT_HANDLE_INVALID if not present. */
-  uint16_t          sccd_handle;        /**< Handle to the Server Characteristic Configuration Descriptor, or BLE_GATT_HANDLE_INVALID if not present. */
+  uint16_t          user_desc_handle;   /**< Handle to the User Description descriptor, or @ref BLE_GATT_HANDLE_INVALID if not present. */
+  uint16_t          cccd_handle;        /**< Handle to the Client Characteristic Configuration Descriptor, or @ref BLE_GATT_HANDLE_INVALID if not present. */
+  uint16_t          sccd_handle;        /**< Handle to the Server Characteristic Configuration Descriptor, or @ref BLE_GATT_HANDLE_INVALID if not present. */
 } ble_gatts_char_handles_t;
 
 
@@ -203,8 +264,8 @@
   uint16_t          handle;             /**< Characteristic Value Handle. */
   uint8_t           type;               /**< Indication or Notification, see @ref BLE_GATT_HVX_TYPES. */
   uint16_t          offset;             /**< Offset within the attribute value. */
-  uint16_t*         p_len;              /**< Length in bytes to be written, length in bytes written after successful return. */
-  uint8_t*          p_data;             /**< Actual data content, use NULL to use the current attribute value. */
+  uint16_t         *p_len;              /**< Length in bytes to be written, length in bytes written after successful return. */
+  uint8_t          *p_data;             /**< Actual data content, use NULL to use the current attribute value. */
 } ble_gatts_hvx_params_t;
 
 /**@brief GATT Read Authorization parameters. */
@@ -214,10 +275,10 @@
   uint8_t           update : 1;         /**< If set, data supplied in p_data will be used in the ATT response. */
   uint16_t          offset;             /**< Offset of the attribute value being updated. */
   uint16_t          len;                /**< Length in bytes of the value in p_data pointer, see @ref BLE_GATTS_ATTR_LENS_MAX. */
-  uint8_t*          p_data;             /**< Pointer to new value used to update the attribute value. */
+  uint8_t          *p_data;             /**< Pointer to new value used to update the attribute value. */
 } ble_gatts_read_authorize_params_t;
 
-/**@brief GATT Write Authorisation parameters. */
+/**@brief GATT Write Authorization parameters. */
 typedef struct
 {
   uint16_t          gatt_status;        /**< GATT status code for the operation, see @ref BLE_GATT_STATUS_CODES. */
@@ -230,36 +291,23 @@
   union {
     ble_gatts_read_authorize_params_t   read;   /**< Read authorization parameters. */
     ble_gatts_write_authorize_params_t  write;  /**< Write authorization parameters. */
-  } params;
+  } params;                                     /**< Reply Parameters. */
 } ble_gatts_rw_authorize_reply_params_t;
 
 
-/**
- * @brief GATT Server Event IDs.
- */
-enum BLE_GATTS_EVTS
-{
-  BLE_GATTS_EVT_WRITE = BLE_GATTS_EVT_BASE,       /**< Write operation performed. */
-  BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST,             /**< Read/Write Authorization request. */
-  BLE_GATTS_EVT_SYS_ATTR_MISSING,                 /**< A persistent system attribute access is pending, awaiting a sd_ble_gatts_sys_attr_set(). */
-  BLE_GATTS_EVT_HVC,                              /**< Handle Value Confirmation. */
-  BLE_GATTS_EVT_SC_CONFIRM,                       /**< Service Changed Confirmation. */
-  BLE_GATTS_EVT_TIMEOUT                           /**< Timeout. */
-};
 
-
-/**@brief Event structure for BLE_GATTS_EVT_WRITE. */
+/**@brief Event structure for @ref BLE_GATTS_EVT_WRITE. */
 typedef struct
 {
   uint16_t                    handle;             /**< Attribute Handle. */
   uint8_t                     op;                 /**< Type of write operation, see @ref BLE_GATTS_OPS. */
   ble_gatts_attr_context_t    context;            /**< Attribute Context. */
   uint16_t                    offset;             /**< Offset for the write operation. */
-  uint16_t                    len;                /**< Length of the incoming data. */
-  uint8_t                     data[1];            /**< Incoming data, variable length. */
+  uint16_t                    len;                /**< Length of the received data. */
+  uint8_t                     data[1];            /**< Received data, variable length. */
 } ble_gatts_evt_write_t;
 
-/**@brief Event structure for authorize read request. */
+/**@brief Event substructure for authorized read requests, see @ref ble_gatts_evt_rw_authorize_request_t. */
 typedef struct
 {
   uint16_t                    handle;             /**< Attribute Handle. */
@@ -267,30 +315,30 @@
   uint16_t                    offset;             /**< Offset for the read operation. */
 } ble_gatts_evt_read_t;
 
-/**@brief Event structure for BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST. */
+/**@brief Event structure for @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST. */
 typedef struct
 {
   uint8_t                     type;             /**< Type of authorize operation, see @ref BLE_GATTS_AUTHORIZE_TYPES. */
   union {
     ble_gatts_evt_read_t      read;             /**< Attribute Read Parameters. */
     ble_gatts_evt_write_t     write;            /**< Attribute Write Parameters. */
-  } request;
+  } request;                                    /**< Request Parameters. */
 } ble_gatts_evt_rw_authorize_request_t;
 
-/**@brief Event structure for BLE_GATTS_EVT_SYS_ATTR_MISSING. */
+/**@brief Event structure for @ref BLE_GATTS_EVT_SYS_ATTR_MISSING. */
 typedef struct
 {
-  uint8_t hint;
+  uint8_t hint;                                 /**< Hint (currently unused). */
 } ble_gatts_evt_sys_attr_missing_t;
 
 
-/**@brief Event structure for BLE_GATTS_EVT_HVC. */
+/**@brief Event structure for @ref BLE_GATTS_EVT_HVC. */
 typedef struct
 {
   uint16_t          handle;                       /**< Attribute Handle. */
 } ble_gatts_evt_hvc_t;
 
-/**@brief Event structure for BLE_GATTS_EVT_TIMEOUT. */
+/**@brief Event structure for @ref BLE_GATTS_EVT_TIMEOUT. */
 typedef struct
 {
   uint8_t          src;                       /**< Timeout source, see @ref BLE_GATT_TIMEOUT_SOURCES. */
@@ -300,7 +348,7 @@
 /**@brief GATT Server event callback event structure. */
 typedef struct
 {
-  uint16_t conn_handle;                                       /**< Connection Handle on which event occurred. */
+  uint16_t conn_handle;                                       /**< Connection Handle on which the event occurred. */
   union
   {
     ble_gatts_evt_write_t                 write;              /**< Write Event Parameters. */
@@ -308,7 +356,7 @@
     ble_gatts_evt_sys_attr_missing_t      sys_attr_missing;   /**< System attributes missing. */
     ble_gatts_evt_hvc_t                   hvc;                /**< Handle Value Confirmation Event Parameters. */
     ble_gatts_evt_timeout_t               timeout;            /**< Timeout Event. */
-  } params;
+  } params;                                                   /**< Event Parameters. */
 } ble_gatts_evt_t;
 
 /** @} */
@@ -316,133 +364,141 @@
 /** @addtogroup BLE_GATTS_FUNCTIONS Functions
  * @{ */
 
-/**@brief Add a service declaration to the local server ATT table.
+/**@brief Add a service declaration to the Attribute Table.
  *
  * @param[in] type      Toggles between primary and secondary services, see @ref BLE_GATTS_SRVC_TYPES.
  * @param[in] p_uuid    Pointer to service UUID.
  * @param[out] p_handle Pointer to a 16-bit word where the assigned handle will be stored.
  *
  * @note Secondary Services are only relevant in the context of the entity that references them, it is therefore forbidden to
- *       add a secondary service declaration that is not referenced by another service later in the ATT table.
+ *       add a secondary service declaration that is not referenced by another service later in the Attribute Table.
  *
- * @return @ref NRF_SUCCESS Successfully added a service declaration.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, Vendor Specific UUIDs need to be present in the table.
- * @return @ref NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack.
- * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
+ * @retval ::NRF_SUCCESS Successfully added a service declaration.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, Vendor Specific UUIDs need to be present in the table.
+ * @retval ::NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack.
+ * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation.
  */
-SVCALL(SD_BLE_GATTS_SERVICE_ADD, uint32_t, sd_ble_gatts_service_add(uint8_t type, ble_uuid_t const*const p_uuid, uint16_t *const p_handle));
+SVCALL(SD_BLE_GATTS_SERVICE_ADD, uint32_t, sd_ble_gatts_service_add(uint8_t type, ble_uuid_t const *p_uuid, uint16_t *p_handle));
 
 
-/**@brief Add an include declaration to the local server ATT table.
+/**@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 addition 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 ATT table prior to this call.
+ * @note The included service must already be present in the Attribute Table prior to this call.
  *
- * @param[in] service_handle    Handle of the service where the included service is to be placed, if BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.
+ * @param[in] service_handle    Handle of the service where the included service is to be placed, if @ref BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.
  * @param[in] inc_srvc_handle   Handle of the included service.
  * @param[out] p_include_handle Pointer to a 16-bit word where the assigned handle will be stored.
  *
- * @return @ref NRF_SUCCESS Successfully added an include declaration.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, handle values need to match previously added services.
- * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
- * @return @ref NRF_ERROR_FORBIDDEN Forbidden value supplied, self inclusions are not allowed.
- * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
- * @return @ref NRF_ERROR_NOT_FOUND Attribute not found.
+ * @retval ::NRF_SUCCESS Successfully added an include declaration.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, handle values need to match previously added services.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation.
+ * @retval ::NRF_ERROR_FORBIDDEN Forbidden value supplied, self inclusions are not allowed.
+ * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation.
+ * @retval ::NRF_ERROR_NOT_FOUND Attribute not found.
  */
-SVCALL(SD_BLE_GATTS_INCLUDE_ADD, uint32_t, sd_ble_gatts_include_add(uint16_t service_handle, uint16_t inc_srvc_handle, uint16_t *const p_include_handle));
+SVCALL(SD_BLE_GATTS_INCLUDE_ADD, uint32_t, sd_ble_gatts_include_add(uint16_t service_handle, uint16_t inc_srvc_handle, uint16_t *p_include_handle));
 
 
-/**@brief Add a characteristic declaration, a characteristic value declaration and optional characteristic descriptor declarations to the local server ATT table.
+/**@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 addition 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.
  *
  * @note If no metadata is provided for the optional descriptors, their permissions will be derived from the characteristic permissions.
  *
- * @param[in] service_handle    Handle of the service where the characteristic is to be placed, if BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.
+ * @param[in] service_handle    Handle of the service where the characteristic is to be placed, if @ref BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.
  * @param[in] p_char_md         Characteristic metadata.
  * @param[in] p_attr_char_value Pointer to the attribute structure corresponding to the characteristic value.
  * @param[out] p_handles        Pointer to the structure where the assigned handles will be stored.
  *
- * @return @ref NRF_SUCCESS Successfully added a characteristic.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, service handle, Vendor Specific UUIDs, lengths, and permissions need to adhere to the constraints.
- * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation, a service context is required.
- * @return @ref NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack.
- * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
- * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX.
+ * @retval ::NRF_SUCCESS Successfully added a characteristic.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, service handle, Vendor Specific UUIDs, lengths, and permissions need to adhere to the constraints.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation, a service context is required.
+ * @retval ::NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack.
+ * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation.
+ * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX.
  */
-SVCALL(SD_BLE_GATTS_CHARACTERISTIC_ADD, uint32_t, sd_ble_gatts_characteristic_add(uint16_t service_handle, ble_gatts_char_md_t const*const p_char_md, ble_gatts_attr_t const*const p_attr_char_value, ble_gatts_char_handles_t *const p_handles));
+SVCALL(SD_BLE_GATTS_CHARACTERISTIC_ADD, uint32_t, sd_ble_gatts_characteristic_add(uint16_t service_handle, ble_gatts_char_md_t const *p_char_md, ble_gatts_attr_t const *p_attr_char_value, ble_gatts_char_handles_t *p_handles));
 
 
-/**@brief Add a descriptor to the local server ATT table.
+/**@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 addition 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 BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.
+ * @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.
  * @param[out] p_handle     Pointer to a 16-bit word where the assigned handle will be stored.
  *
- * @return @ref NRF_SUCCESS Successfully added a descriptor.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, characteristic handle, Vendor Specific UUIDs, lengths, and permissions need to adhere to the constraints.
- * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation, a characteristic context is required.
- * @return @ref NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack.
- * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
- * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX.
+ * @retval ::NRF_SUCCESS Successfully added a descriptor.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, characteristic handle, Vendor Specific UUIDs, lengths, and permissions need to adhere to the constraints.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation, a characteristic context is required.
+ * @retval ::NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack.
+ * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation.
+ * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX.
  */
-SVCALL(SD_BLE_GATTS_DESCRIPTOR_ADD, uint32_t, sd_ble_gatts_descriptor_add(uint16_t char_handle, ble_gatts_attr_t const * const p_attr, uint16_t* const p_handle));
+SVCALL(SD_BLE_GATTS_DESCRIPTOR_ADD, uint32_t, sd_ble_gatts_descriptor_add(uint16_t char_handle, ble_gatts_attr_t const *p_attr, uint16_t *p_handle));
 
 /**@brief Set the value of a given attribute.
  *
- * @param[in] handle    Attribute handle.
- * @param[in] offset    Offset in bytes to write from.
- * @param[in,out] p_len Length in bytes to be written, length in bytes written after successful return.
- * @param[in] p_value   Pointer to a buffer (at least len bytes long) containing the desired attribute value. If value is stored in user memory, only the attribute length is updated when p_value == NULL.
+ * @param[in] conn_handle  Connection handle. If the value does not belong to a system attribute then @ref BLE_CONN_HANDLE_INVALID can be used.
+ * @param[in] handle       Attribute handle.
+ * @param[in,out] p_value  Attribute value information.
+ *
+ * @note Values other than system attributes can be set at any time, regardless of wheter any active connections exist.
  *
- * @return @ref NRF_SUCCESS Successfully set the value of the attribute.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
- * @return @ref NRF_ERROR_NOT_FOUND Attribute not found.
- * @return @ref NRF_ERROR_FORBIDDEN Forbidden handle supplied, certain attributes are not modifiable by the application.
- * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX.
+ * @retval ::NRF_SUCCESS Successfully set the value of the attribute.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
+ * @retval ::NRF_ERROR_NOT_FOUND Attribute not found.
+ * @retval ::NRF_ERROR_FORBIDDEN Forbidden handle supplied, certain attributes are not modifiable by the application.
+ * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
+ * @retval ::BLE_ERROR_GATTS_INVALID_ATTR_TYPE @ref BLE_CONN_HANDLE_INVALID supplied on a system attribute.
  */
-SVCALL(SD_BLE_GATTS_VALUE_SET, uint32_t, sd_ble_gatts_value_set(uint16_t handle, uint16_t offset, uint16_t* const p_len, uint8_t const * const p_value));
+SVCALL(SD_BLE_GATTS_VALUE_SET, uint32_t, sd_ble_gatts_value_set(uint16_t conn_handle, uint16_t handle, ble_gatts_value_t *p_value));
 
 /**@brief Get the value of a given attribute.
  *
- * @param[in] handle     Attribute handle.
- * @param[in] offset     Offset in bytes to read from.
- * @param[in,out] p_len  Length in bytes to be read, total length of attribute value (in bytes, starting from offset) after successful return.
- * @param[in,out] p_data Pointer to a buffer (at least len bytes long) where to store the attribute value. Set to NULL to obtain the complete length of attribute value.
+ * @param[in] conn_handle  Connection handle. If the value does not belong to a system attribute then @ref BLE_CONN_HANDLE_INVALID can be used.
+ * @param[in] handle       Attribute handle.
+ * @param[in,out] p_value  Attribute value information.
  *
  * @note                 If the attribute value is longer than the size of the supplied buffer,
  *                       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.
  * 
- * @return @ref NRF_SUCCESS Successfully retrieved the value of the attribute.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_NOT_FOUND Attribute not found.
+ * @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.
+ *
+ * @retval ::NRF_SUCCESS Successfully retrieved the value of the attribute.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_NOT_FOUND Attribute not found.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
+ * @retval ::BLE_ERROR_GATTS_INVALID_ATTR_TYPE @ref BLE_CONN_HANDLE_INVALID supplied on a system attribute.
  */
-SVCALL(SD_BLE_GATTS_VALUE_GET, uint32_t, sd_ble_gatts_value_get(uint16_t handle, uint16_t offset, uint16_t *const p_len, uint8_t* const p_data));
+SVCALL(SD_BLE_GATTS_VALUE_GET, uint32_t, sd_ble_gatts_value_get(uint16_t conn_handle, uint16_t handle, ble_gatts_value_t *p_value));
 
 /**@brief Notify or Indicate an attribute value.
  *
  * @details This function checks for the relevant Client Characteristic Configuration descriptor value to verify that the relevant operation
  *          (notification or indication) has been enabled by the client. It is also able to update the attribute value before issuing the PDU, so that
  *          the application can atomically perform a value update and a server initiated transaction with a single API call.
- *          If the application chooses to indicate an attribute value, a @ref BLE_GATTS_EVT_HVC will be sent up as soon as the confirmation arrives from
+ *          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 
- *          @ref BLE_ERROR_NO_TX_BUFFERS the ATT table has been updated.
+ *          @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 
@@ -454,25 +510,25 @@
  * @param[in] p_hvx_params Pointer to an HVx parameters structure. If the p_data member contains a non-NULL pointer the attribute value will be updated with
  *                         the contents pointed by it before sending the notification or indication.
  *
- * @return @ref NRF_SUCCESS Successfully queued a notification or indication for transmission, and optionally updated the attribute value.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
- * @return @ref BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle(s) supplied. Only attributes added directly by the application are available to notify and indicate.
- * @return @ref BLE_ERROR_GATTS_INVALID_ATTR_TYPE Invalid attribute type(s) supplied, only characteristic values may be notified and indicated.
- * @return @ref NRF_ERROR_NOT_FOUND Attribute not found.
- * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
- * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation, notifications or indications must be enabled in the CCCD.
- * @return @ref NRF_ERROR_BUSY Procedure already in progress.
- * @return @ref BLE_ERROR_GATTS_SYS_ATTR_MISSING System attributes missing, use @ref sd_ble_gatts_sys_attr_set to set them to a known value.
- * @return @ref BLE_ERROR_NO_TX_BUFFERS There are no available buffers to send the data, applies only to notifications.
+ * @retval ::NRF_SUCCESS Successfully queued a notification or indication for transmission, and optionally updated the attribute value.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State or notifications and/or indications not enabled in the CCCD.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
+ * @retval ::BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle(s) supplied. Only attributes added directly by the application are available to notify and indicate.
+ * @retval ::BLE_ERROR_GATTS_INVALID_ATTR_TYPE Invalid attribute type(s) supplied, only characteristic values may be notified and indicated.
+ * @retval ::NRF_ERROR_NOT_FOUND Attribute not found.
+ * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
+ * @retval ::NRF_ERROR_BUSY Procedure already in progress.
+ * @retval ::BLE_ERROR_GATTS_SYS_ATTR_MISSING System attributes missing, use @ref sd_ble_gatts_sys_attr_set to set them to a known value.
+ * @retval ::BLE_ERROR_NO_TX_BUFFERS There are no available buffers to send the data, applies only to notifications.
  */
-SVCALL(SD_BLE_GATTS_HVX, uint32_t, sd_ble_gatts_hvx(uint16_t conn_handle, ble_gatts_hvx_params_t const*const p_hvx_params));
+SVCALL(SD_BLE_GATTS_HVX, uint32_t, sd_ble_gatts_hvx(uint16_t conn_handle, ble_gatts_hvx_params_t const *p_hvx_params));
 
 /**@brief Indicate the Service Changed attribute value.
  *
- * @details This call will send a Handle Value Indication to one or more peers connected to inform them that the attribute
- *          table layout has changed. As soon as the peer has confirmed the indication, a @ref BLE_GATTS_EVT_SC_CONFIRM event will
+ * @details This call will send a Handle Value Indication to one or more peers connected to inform them that the Attribute
+ *          Table layout has changed. As soon as the peer has confirmed the indication, a @ref BLE_GATTS_EVT_SC_CONFIRM event will
  *          be issued.
  *
  * @note    Some of the restrictions and limitations that apply to @ref sd_ble_gatts_hvx also apply here.
@@ -481,13 +537,14 @@
  * @param[in] start_handle Start of affected attribute handle range.
  * @param[in] end_handle   End of affected attribute handle range.
  *
- * @return @ref NRF_SUCCESS Successfully queued the Service Changed indication for transmission.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
- * @return @ref BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle(s) supplied, handles must be in the range populated by the application.
- * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation, notifications or indications must be enabled in the CCCD.
- * @return @ref NRF_ERROR_BUSY Procedure already in progress.
- * @return @ref BLE_ERROR_GATTS_SYS_ATTR_MISSING System attributes missing, use @ref sd_ble_gatts_sys_attr_set to set them to a known value.
+ * @retval ::NRF_SUCCESS Successfully queued the Service Changed indication for transmission.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State or notifications and/or indications not enabled in the CCCD.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
+ * @retval ::BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle(s) supplied, handles must be in the range populated by the application.
+ * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation, notifications or indications must be enabled in the CCCD.
+ * @retval ::NRF_ERROR_BUSY Procedure already in progress.
+ * @retval ::BLE_ERROR_GATTS_SYS_ATTR_MISSING System attributes missing, use @ref sd_ble_gatts_sys_attr_set to set them to a known value.
  */
 SVCALL(SD_BLE_GATTS_SERVICE_CHANGED, uint32_t, sd_ble_gatts_service_changed(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle));
 
@@ -498,64 +555,80 @@
  * @param[in] conn_handle                 Connection handle.
  * @param[in] p_rw_authorize_reply_params Pointer to a structure with the attribute provided by the application.
  *
- * @return @ref NRF_SUCCESS               Successfully queued a response to the peer, and in the case of a write operation, ATT table updated.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
- * @return @ref NRF_ERROR_INVALID_STATE   No authorization request pending.
- * @return @ref NRF_ERROR_INVALID_PARAM   Authorization op invalid,
+ * @retval ::NRF_SUCCESS               Successfully queued a response to the peer, and in the case of a write operation, Attribute Table updated.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
+ * @retval ::NRF_ERROR_INVALID_STATE   Invalid Connection State or no authorization request pending.
+ * @retval ::NRF_ERROR_INVALID_PARAM   Authorization op invalid,
  *                                         or for Read Authorization reply: requested handles not replied with,
  *                                         or for Write Authorization reply: handle supplied does not match requested handle.
+ * @retval ::NRF_ERROR_BUSY The stack is busy. Retry at later time.
  */
-SVCALL(SD_BLE_GATTS_RW_AUTHORIZE_REPLY, uint32_t, sd_ble_gatts_rw_authorize_reply(uint16_t conn_handle, ble_gatts_rw_authorize_reply_params_t const*const p_rw_authorize_reply_params));
+SVCALL(SD_BLE_GATTS_RW_AUTHORIZE_REPLY, uint32_t, sd_ble_gatts_rw_authorize_reply(uint16_t conn_handle, ble_gatts_rw_authorize_reply_params_t const *p_rw_authorize_reply_params));
 
 
 /**@brief Update persistent system attribute information.
  *
- * @details Supply to the stack information about persistent system attributes.
- *          This call is legal in the connected state only, and is usually 
- *          made immediately after a connection is established and the bond identified.
- *          usually as a response to a BLE_GATTS_EVT_SYS_ATTR_MISSING.
+ * @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 
+ *          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 struct.
+ *          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 data for this bond.
+ *          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 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
  *       reset the SoftDevice to return to a known state.
  *
+ * @note When the @ref BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS is used with this function, only the system attributes included in system services will be modified.
+ * @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 modified.
+ *
  * @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]  flags              Optional additional flags, see @ref BLE_GATTS_SYS_ATTR_FLAGS
  *
- * @return @ref NRF_SUCCESS Successfully set the system attribute information.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
- * @return @ref NRF_ERROR_INVALID_DATA Invalid data supplied, the data should be exactly the same as retrieved with @ref sd_ble_gatts_sys_attr_get.
- * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
+ * @retval ::NRF_SUCCESS Successfully set the system attribute information.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
+ * @retval ::NRF_ERROR_INVALID_STATE   Invalid Connection State.
+ * @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*const p_sys_attr_data, uint16_t len)); 
+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
- *          after a connection has been terminated. When a new connection is made to the same bond, the values
- *          should be restored using @ref sd_ble_gatts_sys_attr_set.
- *          The data should be read before any new advertising is started, or any new connection established. The connection handle for
- *          the previous now defunct connection will remain valid until a new one is created to allow this API call to refer to it.
+ *          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.
+ *          Connection handles belonging to active connections can be used as well, but care should be taken since the system attributes
+ *          may be written to at any time by the peer during a connection's lifetime.
+ *
+ * @note When the @ref BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS is used with this function, only the system attributes included in system services will be returned.
+ * @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[in]     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
  *
- * @return @ref NRF_SUCCESS Successfully retrieved the system attribute information.
- * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_DATA_SIZE The system attribute information did not fit into the provided buffer.
+ * @retval ::NRF_SUCCESS Successfully retrieved the system attribute information.
+ * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
+ * @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 * const p_sys_attr_data, uint16_t* const p_len)); 
+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/nordic-sdk/components/softdevice/s110/headers/ble_hci.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/s110/headers/ble_hci.h	Thu Apr 30 08:34:37 2015 +0100
@@ -1,10 +1,39 @@
-/*
-  Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
+/* 
+ * 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.
+ * 
+ *   4. This software must only be used in a processor manufactured by Nordic
+ *   Semiconductor ASA, or in a processor manufactured by a third party that
+ *   is used in combination with a processor manufactured by Nordic Semiconductor.
+ * 
+ * 
+ * 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.
+ * 
+ */
 
-  The information contained herein is confidential property of Nordic Semiconductor. The use,
-  copying, transfer or disclosure of such information is prohibited except by express written
-  agreement with Nordic Semiconductor.
- */
 /**
   @addtogroup BLE_COMMON 
   @{
@@ -17,55 +46,55 @@
 /** @defgroup BLE_HCI_STATUS_CODES Bluetooth status codes
  * @{ */
 
-#define BLE_HCI_STATUS_CODE_SUCCESS                        0x00
-#define BLE_HCI_STATUS_CODE_UNKNOWN_BTLE_COMMAND           0x01
-#define BLE_HCI_STATUS_CODE_UNKNOWN_CONNECTION_IDENTIFIER  0x02 
+#define BLE_HCI_STATUS_CODE_SUCCESS                        0x00   /**< Success. */
+#define BLE_HCI_STATUS_CODE_UNKNOWN_BTLE_COMMAND           0x01   /**< Unknown BLE Command. */
+#define BLE_HCI_STATUS_CODE_UNKNOWN_CONNECTION_IDENTIFIER  0x02   /**< Unknown Connection Identifier. */
 /*0x03 Hardware Failure
 0x04 Page Timeout
 */
-#define BLE_HCI_AUTHENTICATION_FAILURE                     0x05
-#define BLE_HCI_STATUS_CODE_PIN_OR_KEY_MISSING             0x06
-#define BLE_HCI_MEMORY_CAPACITY_EXCEEDED                   0x07
-#define BLE_HCI_CONNECTION_TIMEOUT                         0x08
+#define BLE_HCI_AUTHENTICATION_FAILURE                     0x05   /**< Authentication Failure. */
+#define BLE_HCI_STATUS_CODE_PIN_OR_KEY_MISSING             0x06   /**< Pin or Key missing. */
+#define BLE_HCI_MEMORY_CAPACITY_EXCEEDED                   0x07   /**< Memory Capacity Exceeded. */
+#define BLE_HCI_CONNECTION_TIMEOUT                         0x08   /**< Connection Timeout. */
 /*0x09 Connection Limit Exceeded
 0x0A Synchronous Connection Limit To A Device Exceeded
 0x0B ACL Connection Already Exists*/
-#define BLE_HCI_STATUS_CODE_COMMAND_DISALLOWED             0x0C
+#define BLE_HCI_STATUS_CODE_COMMAND_DISALLOWED             0x0C   /**< Command Disallowed. */
 /*0x0D Connection Rejected due to Limited Resources
 0x0E Connection Rejected Due To Security Reasons
 0x0F Connection Rejected due to Unacceptable BD_ADDR
 0x10 Connection Accept Timeout Exceeded
 0x11 Unsupported Feature or Parameter Value*/
-#define BLE_HCI_STATUS_CODE_INVALID_BTLE_COMMAND_PARAMETERS 0x12
-#define BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION           0x13
-#define BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES 0x14
-#define BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF     0x15
-#define BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION            0x16
+#define BLE_HCI_STATUS_CODE_INVALID_BTLE_COMMAND_PARAMETERS 0x12  /**< Invalid BLE Command Parameters. */
+#define BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION           0x13  /**< Remote User Terminated Connection. */
+#define BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES 0x14  /**< Remote Device Terminated Connection due to low resources.*/
+#define BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF     0x15  /**< Remote Device Terminated Connection due to power off. */
+#define BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION            0x16  /**< Local Host Terminated Connection. */
 /*
 0x17 Repeated Attempts
 0x18 Pairing Not Allowed
 0x19 Unknown LMP PDU
 */
-#define BLE_HCI_UNSUPPORTED_REMOTE_FEATURE 0x1A
+#define BLE_HCI_UNSUPPORTED_REMOTE_FEATURE 0x1A                   /**< Unsupported Remote Feature. */
 /*
 0x1B SCO Offset Rejected
 0x1C SCO Interval Rejected
 0x1D SCO Air Mode Rejected*/
-#define BLE_HCI_STATUS_CODE_INVALID_LMP_PARAMETERS     0x1E
-#define BLE_HCI_STATUS_CODE_UNSPECIFIED_ERROR          0x1F
+#define BLE_HCI_STATUS_CODE_INVALID_LMP_PARAMETERS     0x1E       /**< Invalid LMP Parameters. */
+#define BLE_HCI_STATUS_CODE_UNSPECIFIED_ERROR          0x1F       /**< Unspecified Error. */
 /*0x20 Unsupported LMP Parameter Value
 0x21 Role Change Not Allowed
 */
-#define BLE_HCI_STATUS_CODE_LMP_RESPONSE_TIMEOUT       0x22
+#define BLE_HCI_STATUS_CODE_LMP_RESPONSE_TIMEOUT       0x22       /**< LMP Response Timeout. */
 /*0x23 LMP Error Transaction Collision*/
-#define BLE_HCI_STATUS_CODE_LMP_PDU_NOT_ALLOWED        0x24
+#define BLE_HCI_STATUS_CODE_LMP_PDU_NOT_ALLOWED        0x24       /**< LMP PDU Not Allowed. */
 /*0x25 Encryption Mode Not Acceptable
 0x26 Link Key Can Not be Changed
 0x27 Requested QoS Not Supported
 */
-#define BLE_HCI_INSTANT_PASSED                         0x28
-#define BLE_HCI_PAIRING_WITH_UNIT_KEY_UNSUPPORTED      0x29
-#define BLE_HCI_DIFFERENT_TRANSACTION_COLLISION        0x2A
+#define BLE_HCI_INSTANT_PASSED                         0x28       /**< Instant Passed. */
+#define BLE_HCI_PAIRING_WITH_UNIT_KEY_UNSUPPORTED      0x29       /**< Pairing with Unit Key Unsupported. */
+#define BLE_HCI_DIFFERENT_TRANSACTION_COLLISION        0x2A       /**< Different Transaction Collision. */
 /*
 0x2B Reserved
 0x2C QoS Unacceptable Parameter
@@ -82,11 +111,11 @@
 0x37 Secure Simple Pairing Not Supported By Host.
 0x38 Host Busy - Pairing
 0x39 Connection Rejected due to No Suitable Channel Found*/
-#define BLE_HCI_CONTROLLER_BUSY                        0x3A
-#define BLE_HCI_CONN_INTERVAL_UNACCEPTABLE             0x3B
-#define BLE_HCI_DIRECTED_ADVERTISER_TIMEOUT            0x3C
-#define BLE_HCI_CONN_TERMINATED_DUE_TO_MIC_FAILURE     0x3D
-#define BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED          0x3E
+#define BLE_HCI_CONTROLLER_BUSY                        0x3A       /**< Controller Busy. */
+#define BLE_HCI_CONN_INTERVAL_UNACCEPTABLE             0x3B       /**< Connection Interval Unacceptable. */
+#define BLE_HCI_DIRECTED_ADVERTISER_TIMEOUT            0x3C       /**< Directed Adverisement Timeout. */
+#define BLE_HCI_CONN_TERMINATED_DUE_TO_MIC_FAILURE     0x3D       /**< Connection Terminated due to MIC Failure. */
+#define BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED          0x3E       /**< Connection Failed to be Established. */
 
 /** @} */
 
--- a/nordic-sdk/components/softdevice/s110/headers/ble_l2cap.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/s110/headers/ble_l2cap.h	Thu Apr 30 08:34:37 2015 +0100
@@ -1,10 +1,39 @@
-/* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is confidential property of Nordic Semiconductor. The use,
- * copying, transfer or disclosure of such information is prohibited except by express written
- * agreement with Nordic Semiconductor.
- *
+/* 
+ * 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.
+ * 
+ *   4. This software must only be used in a processor manufactured by Nordic
+ *   Semiconductor ASA, or in a processor manufactured by a third party that
+ *   is used in combination with a processor manufactured by Nordic Semiconductor.
+ * 
+ * 
+ * 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.
+ * 
  */
+
 /**
   @addtogroup BLE_L2CAP Logical Link Control and Adaptation Protocol (L2CAP)
   @{
@@ -30,6 +59,12 @@
   SD_BLE_L2CAP_TX                                  /**< Transmit a packet. */
 };
 
+/**@brief L2CAP Event IDs. */
+enum BLE_L2CAP_EVTS 
+{
+  BLE_L2CAP_EVT_RX  = BLE_L2CAP_EVT_BASE          /**< L2CAP packet received. */
+};
+
 /** @} */
 
 /**@addtogroup BLE_L2CAP_DEFINES Defines
@@ -64,17 +99,11 @@
   uint16_t   cid;                                 /**< Channel ID on which packet is transmitted. */
 } ble_l2cap_header_t;
 
-/**@brief L2CAP Event IDs. */
-enum BLE_L2CAP_EVTS 
-{
-  BLE_L2CAP_EVT_RX  = BLE_L2CAP_EVT_BASE          /**< L2CAP packet received. */
-};
-
 
 /**@brief L2CAP Received packet event report. */
 typedef struct
 {
-  ble_l2cap_header_t header;                      /** L2CAP packet header. */
+  ble_l2cap_header_t header;                      /**< L2CAP packet header. */
   uint8_t    data[1];                             /**< Packet data, variable length. */
 } ble_l2cap_evt_rx_t;
 
@@ -86,9 +115,13 @@
   union
   {
     ble_l2cap_evt_rx_t rx;                        /**< RX Event parameters. */
-  } params;
+  } params;                                       /**< Event Parameters. */
 } ble_l2cap_evt_t;
 
+/** @} */
+
+/**@addtogroup BLE_L2CAP_FUNCTIONS Functions
+ * @{ */
 
 /**@brief Register a CID with L2CAP.
  *
@@ -96,10 +129,10 @@
  *          
  * @param[in] cid L2CAP CID.
  *
- * @return @ref NRF_SUCCESS Successfully registered a CID with the L2CAP layer.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CID must be above @ref BLE_L2CAP_CID_DYN_BASE.
- * @return @ref BLE_ERROR_L2CAP_CID_IN_USE L2CAP CID already in use.
- * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
+ * @retval ::NRF_SUCCESS Successfully registered a CID with the L2CAP layer.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CID must be above @ref BLE_L2CAP_CID_DYN_BASE.
+ * @retval ::BLE_ERROR_L2CAP_CID_IN_USE L2CAP CID already in use.
+ * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation.
  */
 SVCALL(SD_BLE_L2CAP_CID_REGISTER, uint32_t, sd_ble_l2cap_cid_register(uint16_t cid));
 
@@ -109,9 +142,9 @@
  *          
  * @param[in] cid L2CAP CID.
  *
- * @return @ref NRF_SUCCESS Successfully unregistered the CID.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
- * @return @ref NRF_ERROR_NOT_FOUND CID not previously registered.
+ * @retval ::NRF_SUCCESS Successfully unregistered the CID.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
+ * @retval ::NRF_ERROR_NOT_FOUND CID not previously registered.
  */
 SVCALL(SD_BLE_L2CAP_CID_UNREGISTER, uint32_t, sd_ble_l2cap_cid_unregister(uint16_t cid));
 
@@ -125,15 +158,15 @@
  * @param[in] p_header    Pointer to a packet header containing length and CID.
  * @param[in] p_data      Pointer to the data to be transmitted.
  *
- * @return @ref NRF_SUCCESS Successfully queued an L2CAP packet for transmission.
- * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
- * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CIDs must be registered beforehand with @ref sd_ble_l2cap_cid_register.
- * @return @ref NRF_ERROR_NOT_FOUND CID not found.
- * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
- * @return @ref BLE_ERROR_NO_TX_BUFFERS Not enough application buffers available.
- * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, see @ref BLE_L2CAP_MTU_DEF.
+ * @retval ::NRF_SUCCESS Successfully queued an L2CAP packet for transmission.
+ * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
+ * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CIDs must be registered beforehand with @ref sd_ble_l2cap_cid_register.
+ * @retval ::NRF_ERROR_NOT_FOUND CID not found.
+ * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation.
+ * @retval ::BLE_ERROR_NO_TX_BUFFERS Not enough application buffers available.
+ * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, see @ref BLE_L2CAP_MTU_DEF.
  */
-SVCALL(SD_BLE_L2CAP_TX, uint32_t, sd_ble_l2cap_tx(uint16_t conn_handle, ble_l2cap_header_t const * const p_header, uint8_t const * const p_data));
+SVCALL(SD_BLE_L2CAP_TX, uint32_t, sd_ble_l2cap_tx(uint16_t conn_handle, ble_l2cap_header_t const *p_header, uint8_t const *p_data));
 
 /** @} */
 
--- a/nordic-sdk/components/softdevice/s110/headers/ble_ranges.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/s110/headers/ble_ranges.h	Thu Apr 30 08:34:37 2015 +0100
@@ -1,68 +1,98 @@
-/*
-  Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
+/* 
+ * 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.
+ * 
+ *   4. This software must only be used in a processor manufactured by Nordic
+ *   Semiconductor ASA, or in a processor manufactured by a third party that
+ *   is used in combination with a processor manufactured by Nordic Semiconductor.
+ * 
+ * 
+ * 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.
+ * 
+ */
 
-  The information contained herein is confidential property of Nordic Semiconductor. The use,
-  copying, transfer or disclosure of such information is prohibited except by express written
-  agreement with Nordic Semiconductor.
- */
 /**
   @addtogroup BLE_COMMON
   @{
-  @defgroup ble_ranges Module specific SVC and event number subranges
+  @defgroup ble_ranges Module specific SVC, event and option number subranges
   @{
 
-  @brief Definition of SVC and event number subranges for each API module.
+  @brief Definition of SVC, event and option number subranges for each API module.
 
   @note
-  SVCs and event numbers are split into subranges for each API module.
+  SVCs, event and option numbers are split into subranges for each API module.
   Each module receives its entire allocated range of SVC calls, whether implemented or not,
   but return BLE_ERROR_NOT_SUPPORTED for unimplemented or undefined calls in its range.
 
   Note that the symbols BLE_<module>_SVC_LAST is the end of the allocated SVC range,
   rather than the last SVC function call actually defined and implemented.
 
-  Specific SVC and event values are defined in each module's ble_<module>.h file,
+  Specific SVC, event and option values are defined in each module's ble_<module>.h file,
   which defines names of each individual SVC code based on the range start value.
 */
 
 #ifndef BLE_RANGES_H__
 #define BLE_RANGES_H__
 
-#define BLE_SVC_BASE           0x60
-#define BLE_SVC_LAST           0x6B       /* Total: 12. */
+#define BLE_SVC_BASE           0x60       /**< Common BLE SVC base. */
+#define BLE_SVC_LAST           0x6B       /**< Total: 12. */
 
-#define BLE_RESERVED_SVC_BASE  0x6C
-#define BLE_RESERVED_SVC_LAST  0x6F       /* Total: 4. */
+#define BLE_RESERVED_SVC_BASE  0x6C       /**< Reserved BLE SVC base. */
+#define BLE_RESERVED_SVC_LAST  0x6F       /**< Total: 4. */
 
-#define BLE_GAP_SVC_BASE       0x70
-#define BLE_GAP_SVC_LAST       0x8F       /* Total: 32. */
+#define BLE_GAP_SVC_BASE       0x70       /**< GAP BLE SVC base. */
+#define BLE_GAP_SVC_LAST       0x8F       /**< Total: 32. */
 
-#define BLE_GATTC_SVC_BASE     0x90
-#define BLE_GATTC_SVC_LAST     0x9F       /* Total: 16. */
+#define BLE_GATTC_SVC_BASE     0x90       /**< GATTC BLE SVC base. */
+#define BLE_GATTC_SVC_LAST     0x9F       /**< Total: 32. */
 
-#define BLE_GATTS_SVC_BASE     0xA0
-#define BLE_GATTS_SVC_LAST     0xAF       /* Total: 16. */
+#define BLE_GATTS_SVC_BASE     0xA0       /**< GATTS BLE SVC base. */
+#define BLE_GATTS_SVC_LAST     0xAF       /**< Total: 16. */
 
-#define BLE_L2CAP_SVC_BASE     0xB0
-#define BLE_L2CAP_SVC_LAST     0xBF       /* Total: 16. */
+#define BLE_L2CAP_SVC_BASE     0xB0       /**< L2CAP BLE SVC base. */
+#define BLE_L2CAP_SVC_LAST     0xBF       /**< Total: 16. */
 
 
-#define BLE_EVT_INVALID        0x00
+#define BLE_EVT_INVALID        0x00       /**< Invalid BLE Event. */
 
-#define BLE_EVT_BASE           0x01
-#define BLE_EVT_LAST           0x0F       /* Total: 15. */
+#define BLE_EVT_BASE           0x01       /**< Common BLE Event base. */
+#define BLE_EVT_LAST           0x0F       /**< Total: 15. */
 
-#define BLE_GAP_EVT_BASE       0x10
-#define BLE_GAP_EVT_LAST       0x2F       /* Total: 32. */
+#define BLE_GAP_EVT_BASE       0x10       /**< GAP BLE Event base. */
+#define BLE_GAP_EVT_LAST       0x2F       /**< Total: 32. */
 
-#define BLE_GATTC_EVT_BASE     0x30
-#define BLE_GATTC_EVT_LAST     0x4F       /* Total: 32. */
+#define BLE_GATTC_EVT_BASE     0x30       /**< GATTC BLE Event base. */
+#define BLE_GATTC_EVT_LAST     0x4F       /**< Total: 32. */
 
-#define BLE_GATTS_EVT_BASE     0x50
-#define BLE_GATTS_EVT_LAST     0x6F       /* Total: 32. */
+#define BLE_GATTS_EVT_BASE     0x50       /**< GATTS BLE Event base. */
+#define BLE_GATTS_EVT_LAST     0x6F       /**< Total: 32. */
 
-#define BLE_L2CAP_EVT_BASE     0x70
-#define BLE_L2CAP_EVT_LAST     0x8F       /* Total: 32.  */
+#define BLE_L2CAP_EVT_BASE     0x70       /**< L2CAP BLE Event base. */
+#define BLE_L2CAP_EVT_LAST     0x8F       /**< Total: 32.  */
+
 
 #define BLE_OPT_INVALID        0x00       /**< Invalid BLE Option. */
 
--- a/nordic-sdk/components/softdevice/s110/headers/ble_types.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/s110/headers/ble_types.h	Thu Apr 30 08:34:37 2015 +0100
@@ -1,17 +1,46 @@
-/* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is confidential property of Nordic Semiconductor. The use,
- * copying, transfer or disclosure of such information is prohibited except by express written
- * agreement with Nordic Semiconductor.
- *
+/* 
+ * 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.
+ * 
+ *   4. This software must only be used in a processor manufactured by Nordic
+ *   Semiconductor ASA, or in a processor manufactured by a third party that
+ *   is used in combination with a processor manufactured by Nordic Semiconductor.
+ * 
+ * 
+ * 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.
+ * 
  */
+
 /**
   @addtogroup BLE_COMMON
   @{
   @defgroup ble_types Common types and macro definitions
   @{
 
-  @brief Common types and macro definitions for the S110 SoftDevice.
+  @brief Common types and macro definitions for the BLE SoftDevice.
  */
 
 #ifndef BLE_TYPES_H__
@@ -19,7 +48,7 @@
 
 #include <stdint.h>
 
-/** @addtogroup BLE_COMMON_DEFINES Defines
+/** @addtogroup BLE_TYPES_DEFINES Defines
  * @{ */
 
 /** @defgroup BLE_CONN_HANDLES BLE Connection Handles
@@ -149,14 +178,14 @@
 /** @brief 128 bit UUID values. */
 typedef struct
 { 
-    unsigned char uuid128[16];
+    unsigned char uuid128[16]; /**< Little-Endian UUID bytes. */
 } ble_uuid128_t;
 
 /** @brief  Bluetooth Low Energy UUID type, encapsulates both 16-bit and 128-bit UUIDs. */
 typedef struct
 {
     uint16_t    uuid; /**< 16-bit UUID value or octets 12-13 of 128-bit UUID. */
-    uint8_t     type; /**< UUID type, see @ref BLE_UUID_TYPES. If type is BLE_UUID_TYPE_UNKNOWN, the value of uuid is undefined. */
+    uint8_t     type; /**< UUID type, see @ref BLE_UUID_TYPES. If type is @ref BLE_UUID_TYPE_UNKNOWN, the value of uuid is undefined. */
 } ble_uuid_t;
 
 /** @} */
--- a/nordic-sdk/components/softdevice/s110/headers/nrf_error.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/s110/headers/nrf_error.h	Thu Apr 30 08:34:37 2015 +0100
@@ -1,11 +1,38 @@
-/*
- * Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is confidential property of Nordic Semiconductor. The use,
- * copying, transfer or disclosure of such information is prohibited except by express written
- * agreement with Nordic Semiconductor.
- *
- */
+/* 
+ * 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.
+ * 
+ *   4. This software must only be used in a processor manufactured by Nordic
+ *   Semiconductor ASA, or in a processor manufactured by a third party that
+ *   is used in combination with a processor manufactured by Nordic Semiconductor.
+ * 
+ * 
+ * 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.
+ * 
+ */ 
  /**
   @defgroup nrf_error SoftDevice Global Error Codes
   @{
--- a/nordic-sdk/components/softdevice/s110/headers/nrf_error_sdm.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/s110/headers/nrf_error_sdm.h	Thu Apr 30 08:34:37 2015 +0100
@@ -1,10 +1,37 @@
-/*
- * Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is confidential property of Nordic Semiconductor. The use,
- * copying, transfer or disclosure of such information is prohibited except by express written
- * agreement with Nordic Semiconductor.
- *
+/* 
+ * 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.
+ * 
+ *   4. This software must only be used in a processor manufactured by Nordic
+ *   Semiconductor ASA, or in a processor manufactured by a third party that
+ *   is used in combination with a processor manufactured by Nordic Semiconductor.
+ * 
+ * 
+ * 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.
+ * 
  */
  /**
   @addtogroup nrf_sdm_api
@@ -21,9 +48,9 @@
 
 #include "nrf_error.h"
 
-#define NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN              (NRF_ERROR_SDM_BASE_NUM + 0)  ///< Unknown lfclk source
-#define NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION (NRF_ERROR_SDM_BASE_NUM + 1)  ///< Incorrect interrupt configuration (can be caused by using illegal priority levels, or having enabled SoftDevice interrupts)
-#define NRF_ERROR_SDM_INCORRECT_CLENR0                  (NRF_ERROR_SDM_BASE_NUM + 2)  ///< Incorrect CLENR0 (can be caused by erronous SoftDevice flashing)
+#define NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN              (NRF_ERROR_SDM_BASE_NUM + 0)  ///< Unknown lfclk source.
+#define NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION (NRF_ERROR_SDM_BASE_NUM + 1)  ///< Incorrect interrupt configuration (can be caused by using illegal priority levels, or having enabled SoftDevice interrupts).
+#define NRF_ERROR_SDM_INCORRECT_CLENR0                  (NRF_ERROR_SDM_BASE_NUM + 2)  ///< Incorrect CLENR0 (can be caused by erronous SoftDevice flashing).
 
 #endif // NRF_ERROR_SDM_H__
 
--- a/nordic-sdk/components/softdevice/s110/headers/nrf_error_soc.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/s110/headers/nrf_error_soc.h	Thu Apr 30 08:34:37 2015 +0100
@@ -1,12 +1,39 @@
-/*
- * Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is confidential property of Nordic Semiconductor. The use,
- * copying, transfer or disclosure of such information is prohibited except by express written
- * agreement with Nordic Semiconductor.
- *
+/* 
+ * 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.
+ * 
+ *   4. This software must only be used in a processor manufactured by Nordic
+ *   Semiconductor ASA, or in a processor manufactured by a third party that
+ *   is used in combination with a processor manufactured by Nordic Semiconductor.
+ * 
+ * 
+ * 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.
+ * 
  */
- /**
+/**
   @addtogroup nrf_soc_api
   @{
   @defgroup nrf_soc_error SoC Library Error Codes
--- a/nordic-sdk/components/softdevice/s110/headers/nrf_mbr.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/s110/headers/nrf_mbr.h	Thu Apr 30 08:34:37 2015 +0100
@@ -1,17 +1,44 @@
 /*
- * Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
+ * 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.
  *
- * The information contained herein is confidential property of Nordic Semiconductor. The use,
- * copying, transfer or disclosure of such information is prohibited except by express written
- * agreement with Nordic Semiconductor.
+ *   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.
+ *
+ *   4. This software must only be used in a processor manufactured by Nordic
+ *   Semiconductor ASA, or in a processor manufactured by a third party that
+ *   is used in combination with a processor manufactured by Nordic Semiconductor.
+ *
+ *
+ * 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.
  *
  */
 /**
   @defgroup nrf_mbr_api Master Boot Record API
   @{
-     
+
   @brief APIs for updating SoftDevice and BootLoader
- 
+
 */
 
 /* Header guard */
@@ -26,7 +53,8 @@
  * @{ */
 
 /**@brief MBR SVC Base number. */
-#define MBR_SVC_BASE 0x18   
+#define MBR_SVC_BASE        (0x18)
+
 /** @} */
 
 /** @addtogroup NRF_MBR_ENUMS Enumerations
@@ -41,7 +69,7 @@
 /**@brief Possible values for ::sd_mbr_command_t.command */
 enum NRF_MBR_COMMANDS
 {
-  SD_MBR_COMMAND_COPY_BL,               /**< Copy a new a new BootLoader. @see sd_mbr_command_copy_bl_t */
+  SD_MBR_COMMAND_COPY_BL,               /**< Copy a new BootLoader. @see sd_mbr_command_copy_bl_t */
   SD_MBR_COMMAND_COPY_SD,               /**< Copy a new SoftDevice. @see ::sd_mbr_command_copy_sd_t*/
   SD_MBR_COMMAND_INIT_SD,               /**< Init forwarding interrupts to SD, and run reset function in SD*/
   SD_MBR_COMMAND_COMPARE,               /**< This command works like memcmp. @see ::sd_mbr_command_compare_t*/
@@ -54,12 +82,12 @@
  * @{ */
 
 /**@brief This command copies part of a new SoftDevice
- * The destination area is erased before copying. 
+ * The destination area is erased before copying.
  * If dst is in the middle of a flash page, that whole flash page will be erased.
  * If (dst+len) is in the middle of a flash page, that whole flash page will be erased.
- * 
+ *
  * The user of this function is responsible for setting the PROTENSET registers.
- * 
+ *
  * @retval ::NRF_SUCCESS indicates that the contents of the memory blocks where copied correctly.
  * @retval ::NRF_ERROR_INTERNAL indicates that the contents of the memory blocks where not verified correctly after copying.
  */
@@ -67,8 +95,8 @@
 {
   uint32_t *src;  /**< Pointer to the source of data to be copied.*/
   uint32_t *dst;  /**< Pointer to the destination where the content is to be copied.*/
-  uint32_t len;   /**< Number of 32 bit words to copy. Must be a multiple of 256 words*/
-}sd_mbr_command_copy_sd_t;
+  uint32_t len;   /**< Number of 32 bit words to copy. Must be a multiple of PAGE_SIZE_IN_WORDS words.*/
+} sd_mbr_command_copy_sd_t;
 
 
 /**@brief This command works like memcmp, but takes the length in words.
@@ -78,10 +106,10 @@
  */
 typedef struct
 {
-  uint32_t *ptr1; /**< Pointer to block of memory */
-  uint32_t *ptr2; /**< Pointer to block of memory */
-  uint32_t len;   /**< Number of 32 bit words to compare*/
-}sd_mbr_command_compare_t;
+  uint32_t *ptr1; /**< Pointer to block of memory. */
+  uint32_t *ptr2; /**< Pointer to block of memory. */
+  uint32_t len;   /**< Number of 32 bit words to compare.*/
+} sd_mbr_command_compare_t;
 
 
 /**@brief This command copies a new BootLoader.
@@ -91,45 +119,46 @@
  *  If (destination+bl_len) is in the middle of a flash page, that whole flash page will be erased.
  *
  *  This function will use PROTENSET to protect the flash that is not intended to be written.
- * 
+ *
  *  On Success, this function will not return. It will start the new BootLoader from reset-vector as normal.
  *
- * @retval ::NRF_ERROR_INVALID_STATE indicates that something was wrong.
  * @retval ::NRF_ERROR_INTERNAL indicates an internal error that should not happen.
- * @retval ::NRF_ERROR_FORBIDDEN if NRF_UICR->BOOTADDR is not set
- * @retval ::NRF_ERROR_INVALID_LENGTH is invalid.
+ * @retval ::NRF_ERROR_FORBIDDEN if NRF_UICR->BOOTADDR is not set.
+ * @retval ::NRF_ERROR_INVALID_LENGTH if parameters attempts to read or write outside flash area.
  */
 typedef struct
 {
   uint32_t *bl_src;  /**< Pointer to the source of the Bootloader to be be copied.*/
-  uint32_t bl_len;   /**< Number of 32 bit words to copy for BootLoader */
-}sd_mbr_command_copy_bl_t;
+  uint32_t bl_len;   /**< Number of 32 bit words to copy for BootLoader. */
+} sd_mbr_command_copy_bl_t;
 
 /**@brief Sets the base address of the interrupt vector table for interrupts forwarded from the MBR
- * 
+ *
  * Once this function has been called, this address is where the MBR will start to forward interrupts to after a reset.
  *
- * To restore default forwarding thiss function should be called with @param address set to 0.
+ * To restore default forwarding this function should be called with @param address set to 0.
  * The MBR will then start forwarding to interrupts to the adress in NFR_UICR->BOOTADDR or to the SoftDevice if the BOOTADDR is not set.
  *
  * @retval ::NRF_SUCCESS
+ * @retval ::NRF_ERROR_INTERNAL indicates an internal error that should not happen.
+ * @retval ::NRF_ERROR_INVALID_ADDR if parameter address is outside of the flash size.
  */
 typedef struct
-{ 
+{
   uint32_t address; /**< The base address of the interrupt vector table for forwarded interrupts.*/
-}sd_mbr_command_vector_table_base_set_t;
+} sd_mbr_command_vector_table_base_set_t;
 
 typedef struct
 {
   uint32_t command;  /**< type of command to be issued see @ref NRF_MBR_COMMANDS. */
-  union 
+  union
   {
-    sd_mbr_command_copy_sd_t copy_sd;  /**< Parameters for copy*/
-    sd_mbr_command_copy_bl_t copy_bl;  /**< Parameters for copy SoftDevice and BootLoader*/
-    sd_mbr_command_compare_t compare;  /**< Parameters for verify*/
+    sd_mbr_command_copy_sd_t copy_sd;  /**< Parameters for copy SoftDevice.*/
+    sd_mbr_command_copy_bl_t copy_bl;  /**< Parameters for copy BootLoader.*/
+    sd_mbr_command_compare_t compare;  /**< Parameters for verify.*/
     sd_mbr_command_vector_table_base_set_t base_set; /**< Parameters for vector table base set.*/
   } params;
-}sd_mbr_command_t;
+} sd_mbr_command_t;
 
 /** @} */
 
@@ -138,9 +167,9 @@
 
 /**@brief Issue Master Boot Record commands
  *
- * Commands used when updating a SoftDevice and bootloader
+ * Commands used when updating a SoftDevice and bootloader.
  *
- * @param[in]  param Pointer to a struct describing the command
+ * @param[in]  param Pointer to a struct describing the command.
  *
  *@note for retvals see ::sd_mbr_command_copy_sd_t ::sd_mbr_command_copy_bl_t ::sd_mbr_command_compare_t
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nordic-sdk/components/softdevice/s110/headers/nrf_sd_def.h	Thu Apr 30 08:34:37 2015 +0100
@@ -0,0 +1,23 @@
+/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
+ *
+ * The information contained herein is property of Nordic Semiconductor ASA.
+ * Terms and conditions of usage are described in detail in NORDIC
+ * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ */
+
+#ifndef NRF_SD_DEF_H__
+#define NRF_SD_DEF_H__
+
+#include <stdint.h>
+
+#define NRF_PPI_RESTRICTED              0                        /**< 1 if PPI peripheral is restricted, 0 otherwise. */
+#define NRF_PPI_ALL_APP_CHANNELS_MASK   ((uint32_t)0x00003FFFuL) /**< All PPI channels available to the application. */
+#define NRF_PPI_PROG_APP_CHANNELS_MASK  ((uint32_t)0x00003FFFuL) /**< Programmable PPI channels available to the application. */
+#define NRF_PPI_ALL_APP_GROUPS_MASK     ((uint32_t)0x00000003uL) /**< All PPI groups available to the application. */
+
+#endif /* NRF_SD_DEF_H__ */
\ No newline at end of file
--- a/nordic-sdk/components/softdevice/s110/headers/nrf_sdm.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/s110/headers/nrf_sdm.h	Thu Apr 30 08:34:37 2015 +0100
@@ -1,10 +1,37 @@
-/*
- * Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is confidential property of Nordic Semiconductor. The use,
- * copying, transfer or disclosure of such information is prohibited except by express written
- * agreement with Nordic Semiconductor.
- *
+/* 
+ * 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.
+ * 
+ *   4. This software must only be used in a processor manufactured by Nordic
+ *   Semiconductor ASA, or in a processor manufactured by a third party that
+ *   is used in combination with a processor manufactured by Nordic Semiconductor.
+ * 
+ * 
+ * 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.
+ * 
  */
 /**
   @defgroup nrf_sdm_api SoftDevice Manager API
@@ -26,11 +53,37 @@
 /** @addtogroup NRF_SDM_DEFINES Defines
  * @{ */
 
-/**@brief SoftDevice Manager SVC Base number. */
-#define SDM_SVC_BASE  (0x10)
+/** @brief SoftDevice Manager SVC Base number. */
+#define SDM_SVC_BASE 0x10   
 
 /** @} */
 
+/** @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. 
+This is the offset where the first byte of the softdevice hex file is written.*/
+#define MBR_SIZE (0x1000)
+
+/** @brief Defines the absolute Softdevice information structure location (address)*/
+#define SOFTDEVICE_INFO_STRUCT_ADDRESS (SOFTDEVICE_INFO_STRUCT_OFFSET + MBR_SIZE)
+
+/** @brief Defines the offset for Softdevice size value relative to Softdevice base address*/
+#define SD_SIZE_OFFSET (SOFTDEVICE_INFO_STRUCT_OFFSET + 0x08)
+
+/** @brief Defines the offset for FWID value relative to Softdevice base address*/
+#define SD_FWID_OFFSET (SOFTDEVICE_INFO_STRUCT_OFFSET + 0x0C)
+
+/** @brief Defines a macro for retreiving the actual Softdevice size value from a given base address
+           use @ref MBR_SIZE when Softdevice is installed just above the MBR (the usual case)*/
+#define SD_SIZE_GET(baseaddr) (*((uint32_t *) ((baseaddr) + SD_SIZE_OFFSET)))
+
+/** @brief Defines a macro for retreiving the actual FWID value from a given base address
+           use @ref MBR_SIZE when Softdevice is installed just above the MBR (the usual case)*/
+#define SD_FWID_GET(baseaddr) ((*((uint32_t *) ((baseaddr) + SD_FWID_OFFSET))) & 0xFFFF)
+
+
 /** @addtogroup NRF_SDM_ENUMS Enumerations
  * @{ */
 
@@ -108,20 +161,21 @@
  * @note This function has no effect when returning with an error.
  *
  * @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)
- *       - Interrupts will not arrive from protected peripherals or interrupts
+ *       - 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).
+ *       - Interrupts will not arrive from protected peripherals or interrupts.
  *       - nrf_nvic_ functions must be used instead of CMSIS NVIC_ functions for reliable usage of the softdevice.
- *       - Interrupt latency may be affected by the SoftDevice  (see relevant SDS documentation)
- *       - Chosen low frequency clock source will be running
+ *       - Interrupt latency may be affected by the SoftDevice  (see relevant SDS documentation).
+ *       - Chosen low frequency clock source will be running.
  *
  * @param clock_source Low frequency clock source and accuracy. (Note: In the case of XTAL source, the PPM accuracy of the chosen clock source must be greater than or equal to the actual characteristics of your XTAL clock).
  * @param assertion_handler Callback for SoftDevice assertions.
  *
  * @retval ::NRF_SUCCESS
- * @retval ::NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION SoftDeviceinterrupt is already enabled, or an enabled interrupt has an illegal priority level
- * @retval ::NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN Unknown low frequency clock source selected
+ * @retval ::NRF_ERROR_INVALID_STATE SoftDevice is already enabled, and the clock source and assertion handler cannot be updated.
+ * @retval ::NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION SoftDeviceinterrupt is already enabled, or an enabled interrupt has an illegal priority level.
+ * @retval ::NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN Unknown low frequency clock source selected.
  */
 SVCALL(SD_SOFTDEVICE_ENABLE, uint32_t, sd_softdevice_enable(nrf_clock_lfclksrc_t clock_source, softdevice_assertion_handler_t assertion_handler));
 
--- a/nordic-sdk/components/softdevice/s110/headers/nrf_soc.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/s110/headers/nrf_soc.h	Thu Apr 30 08:34:37 2015 +0100
@@ -1,18 +1,45 @@
-/* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is confidential property of Nordic Semiconductor. The use,
- * copying, transfer or disclosure of such information is prohibited except by express written
- * agreement with Nordic Semiconductor.
- *
- */
- 
+/* 
+ * 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.
+ * 
+ *   4. This software must only be used in a processor manufactured by Nordic
+ *   Semiconductor ASA, or in a processor manufactured by a third party that
+ *   is used in combination with a processor manufactured by Nordic Semiconductor.
+ * 
+ * 
+ * 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.
+ * 
+ */ 
 /**
  * @defgroup nrf_soc_api SoC Library API
  * @{
  * 
  * @brief APIs for the SoC library.
  * 
-*/
+ */
 
 #ifndef NRF_SOC_H__
 #define NRF_SOC_H__
@@ -24,12 +51,12 @@
 #include "nrf51_bitfields.h"
 #include "nrf_error_soc.h"
 
-/** @addtogroup NRF_SOC_DEFINES Defines
+/**@addtogroup NRF_SOC_DEFINES Defines
  * @{ */
 
 /**@brief The number of the lowest SVC number reserved for the SoC library. */
 #define SOC_SVC_BASE               (0x20)
-#define SOC_SVC_BASE_NOT_AVAILABLE (0x23)
+#define SOC_SVC_BASE_NOT_AVAILABLE (0x2B)
 
 /**@brief Guranteed time for application to process radio inactive notification. */
 #define NRF_RADIO_NOTIFICATION_INACTIVE_GUARANTEED_TIME_US  (62)
@@ -37,33 +64,41 @@
 /**@brief The minimum allowed timeslot extension time. */
 #define NRF_RADIO_MINIMUM_TIMESLOT_LENGTH_EXTENSION_TIME_US (200)
 
-#define SOC_ECB_KEY_LENGTH            (16)                       /**< ECB key length. */
-#define SOC_ECB_CLEARTEXT_LENGTH      (16)                       /**< ECB cleartext length. */
-#define SOC_ECB_CIPHERTEXT_LENGTH     (SOC_ECB_CLEARTEXT_LENGTH) /**< ECB ciphertext length. */
+#define SOC_ECB_KEY_LENGTH                (16)                       /**< ECB key length. */
+#define SOC_ECB_CLEARTEXT_LENGTH          (16)                       /**< ECB cleartext length. */
+#define SOC_ECB_CIPHERTEXT_LENGTH         (SOC_ECB_CLEARTEXT_LENGTH) /**< ECB ciphertext length. */
 
-#define SD_EVT_IRQn                   (SWI2_IRQn)        /**< SoftDevice Event IRQ number. Used for both protocol events and SoC events. */
-#define SD_EVT_IRQHandler             (SWI2_IRQHandler)  /**< SoftDevice Event IRQ handler. Used for both protocol events and SoC events. */
-#define RADIO_NOTIFICATION_IRQn       (SWI1_IRQn)        /**< The radio notification IRQ number. */
-#define RADIO_NOTIFICATION_IRQHandler (SWI1_IRQHandler)  /**< The radio notification IRQ handler. */
+#define SD_EVT_IRQn                       (SWI2_IRQn)        /**< SoftDevice Event IRQ number. Used for both protocol events and SoC events. */
+#define SD_EVT_IRQHandler                 (SWI2_IRQHandler)  /**< SoftDevice Event IRQ handler. Used for both protocol events and SoC events. */
+#define RADIO_NOTIFICATION_IRQn           (SWI1_IRQn)        /**< The radio notification IRQ number. */
+#define RADIO_NOTIFICATION_IRQHandler     (SWI1_IRQHandler)  /**< The radio notification IRQ handler. */
 
-#define NRF_RADIO_LENGTH_MIN_US       (100)               /**< The shortest allowed radio timeslot, in microseconds. */
-#define NRF_RADIO_LENGTH_MAX_US       (100000)            /**< The longest allowed radio timeslot, in microseconds. */
+#define NRF_RADIO_LENGTH_MIN_US           (100)               /**< The shortest allowed radio timeslot, in microseconds. */
+#define NRF_RADIO_LENGTH_MAX_US           (100000)            /**< The longest allowed radio timeslot, in microseconds. */
 
 #define NRF_RADIO_DISTANCE_MAX_US         (128000000UL - 1UL) /**< The longest timeslot distance, in microseconds, allowed for the distance parameter (see @ref nrf_radio_request_normal_t) in the request. */
 
 #define NRF_RADIO_EARLIEST_TIMEOUT_MAX_US (128000000UL - 1UL) /**< The longest timeout, in microseconds, allowed when requesting the earliest possible timeslot. */
 
-#define NRF_RADIO_START_JITTER_US     (2)                 /**< The maximum jitter in NRF_RADIO_CALLBACK_SIGNAL_TYPE_START relative to the requested start time. */
+#define NRF_RADIO_START_JITTER_US         (2)                 /**< The maximum jitter in @ref NRF_RADIO_CALLBACK_SIGNAL_TYPE_START relative to the requested start time. */
 
-/** @} */
+/**@} */
 
-/** @addtogroup NRF_SOC_TYPES Types
+/**@addtogroup NRF_SOC_TYPES Types
  * @{ */
 
 /**@brief The SVC numbers used by the SVC functions in the SoC library. */
 enum NRF_SOC_SVCS
 {
-  SD_FLASH_PAGE_ERASE = SOC_SVC_BASE,
+  SD_PPI_CHANNEL_ENABLE_GET = SOC_SVC_BASE,
+  SD_PPI_CHANNEL_ENABLE_SET,
+  SD_PPI_CHANNEL_ENABLE_CLR,
+  SD_PPI_CHANNEL_ASSIGN,
+  SD_PPI_GROUP_TASK_ENABLE,
+  SD_PPI_GROUP_TASK_DISABLE,
+  SD_PPI_GROUP_ASSIGN,
+  SD_PPI_GROUP_GET,
+  SD_FLASH_PAGE_ERASE,
   SD_FLASH_WRITE,
   SD_FLASH_PROTECT,
   SD_MUTEX_NEW = SOC_SVC_BASE_NOT_AVAILABLE,
@@ -99,14 +134,6 @@
   SD_CLOCK_HFCLK_REQUEST,
   SD_CLOCK_HFCLK_RELEASE,
   SD_CLOCK_HFCLK_IS_RUNNING,
-  SD_PPI_CHANNEL_ENABLE_GET,
-  SD_PPI_CHANNEL_ENABLE_SET,
-  SD_PPI_CHANNEL_ENABLE_CLR,
-  SD_PPI_CHANNEL_ASSIGN,
-  SD_PPI_GROUP_TASK_ENABLE,
-  SD_PPI_GROUP_TASK_DISABLE,
-  SD_PPI_GROUP_ASSIGN,
-  SD_PPI_GROUP_GET,
   SD_RADIO_NOTIFICATION_CFG_SET,
   SD_ECB_BLOCK_ENCRYPT,
   SD_RADIO_SESSION_OPEN,
@@ -152,9 +179,8 @@
 /**@brief Possible values of ::nrf_power_dcdc_mode_t. */
 enum NRF_POWER_DCDC_MODES
 {
-  NRF_POWER_DCDC_MODE_OFF,          /**< The DCDC is always off. */
-  NRF_POWER_DCDC_MODE_ON,           /**< The DCDC is always on. */
-  NRF_POWER_DCDC_MODE_AUTOMATIC     /**< The DCDC is automatically managed. */
+  NRF_POWER_DCDC_DISABLE,          /**< The DCDC is disabled. */
+  NRF_POWER_DCDC_ENABLE            /**< The DCDC is enabled.  */
 };
 
 /**@brief Possible values of ::nrf_radio_notification_distance_t. */
@@ -194,9 +220,9 @@
   NRF_EVT_NUMBER_OF_EVTS
 };
 
-/** @} */
+/**@} */
 
-/** @addtogroup NRF_SOC_TYPES Types
+/**@addtogroup NRF_SOC_TYPES Types
  * @{ */
 
 /**@brief Represents a mutex for use with the nrf_mutex functions.
@@ -222,17 +248,17 @@
 /**@brief Radio notification types. */
 typedef uint8_t nrf_radio_notification_type_t;
 
-/** @brief The Radio signal callback types. */
+/**@brief The Radio signal callback types. */
 enum NRF_RADIO_CALLBACK_SIGNAL_TYPE
 {
-  NRF_RADIO_CALLBACK_SIGNAL_TYPE_START,            /**< This signal indicates the start of the radio timeslot. */
+  NRF_RADIO_CALLBACK_SIGNAL_TYPE_START,             /**< This signal indicates the start of the radio timeslot. */
   NRF_RADIO_CALLBACK_SIGNAL_TYPE_TIMER0,            /**< This signal indicates the NRF_TIMER0 interrupt. */
   NRF_RADIO_CALLBACK_SIGNAL_TYPE_RADIO,             /**< This signal indicates the NRF_RADIO interrupt. */
   NRF_RADIO_CALLBACK_SIGNAL_TYPE_EXTEND_FAILED,     /**< This signal indicates extend action failed. */
   NRF_RADIO_CALLBACK_SIGNAL_TYPE_EXTEND_SUCCEEDED   /**< This signal indicates extend action succeeded. */
 };
 
-/** @brief The actions requested by the signal callback.
+/**@brief The actions requested by the signal callback.
  *
  *  This code gives the SOC instructions about what action to take when the signal callback has
  *  returned.
@@ -252,21 +278,21 @@
   NRF_RADIO_HFCLK_CFG_FORCE_XTAL,                   /**< Force external crystal to be used as HF clock source during whole the timeslot. */
 };
 
-/** @brief Radio timeslot priorities. */
+/**@brief Radio timeslot priorities. */
 enum NRF_RADIO_PRIORITY
 {
   NRF_RADIO_PRIORITY_HIGH,                          /**< High (equal priority as the normal connection priority of the SoftDevice stack(s)). */
   NRF_RADIO_PRIORITY_NORMAL,                        /**< Normal (equal priority as the priority of secondary activites of the SoftDevice stack(s)). */
 };
 
-/** @brief Radio timeslot request type. */
+/**@brief Radio timeslot request type. */
 enum NRF_RADIO_REQUEST_TYPE
 {
   NRF_RADIO_REQ_TYPE_EARLIEST,                      /**< Request timeslot as early as possible. This should always be used for the first request in a session. */
   NRF_RADIO_REQ_TYPE_NORMAL                         /**< Normal timeslot request. */
 };
 
-/** @brief Parameters for a request for a timeslot as early as possible. */
+/**@brief Parameters for a request for a timeslot as early as possible. */
 typedef struct
 {
   uint8_t       hfclk;                              /**< High frequency clock source, see @ref NRF_RADIO_HFCLK_CFG. */
@@ -275,7 +301,7 @@
   uint32_t      timeout_us;                         /**< Longest acceptable delay until the start of the requested timeslot (up to @ref NRF_RADIO_EARLIEST_TIMEOUT_MAX_US microseconds). */
 } nrf_radio_request_earliest_t;
 
-/** @brief Parameters for a normal radio request. */
+/**@brief Parameters for a normal radio request. */
 typedef struct
 {
   uint8_t       hfclk;                              /**< High frequency clock source, see @ref NRF_RADIO_HFCLK_CFG. */
@@ -284,7 +310,7 @@
   uint32_t      length_us;                          /**< The radio timeslot length (in the range [100..100,000] microseconds). */
 } nrf_radio_request_normal_t;
 
-/** @brief Radio request parameters. */
+/**@brief Radio request parameters. */
 typedef struct
 {
   uint8_t                         request_type;     /**< Type of request, see @ref NRF_RADIO_REQUEST_TYPE. */
@@ -334,9 +360,9 @@
   uint8_t ciphertext[SOC_ECB_CIPHERTEXT_LENGTH];    /**< Cipher Text data. */
 } nrf_ecb_hal_data_t;
 
-/** @} */
+/**@} */
 
-/** @addtogroup NRF_SOC_FUNCTIONS Functions
+/**@addtogroup NRF_SOC_FUNCTIONS Functions
  * @{ */
 
 /**@brief Initialize a mutex.
@@ -367,7 +393,7 @@
 /**@brief Enable External Interrupt.
  * @note Corresponds to NVIC_EnableIRQ in CMSIS.
  *
- * @pre{IRQn is valid and not reserved by the stack}
+ * @pre IRQn is valid and not reserved by the stack.
  *
  * @param[in] IRQn See the NVIC_EnableIRQ documentation in CMSIS.
  *
@@ -380,9 +406,9 @@
 /**@brief  Disable External Interrupt.
  * @note Corresponds to NVIC_DisableIRQ in CMSIS.
  *
- * @pre{IRQn is valid and not reserved by the stack}
+ * @pre IRQn is valid and not reserved by the stack.
  *
- * @param[in] IRQn See the NVIC_DisableIRQ documentation in CMSIS
+ * @param[in] IRQn See the NVIC_DisableIRQ documentation in CMSIS.
  *
  * @retval ::NRF_SUCCESS The interrupt was disabled.
  * @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE The interrupt is not available for the application.
@@ -392,7 +418,7 @@
 /**@brief  Get Pending Interrupt.
  * @note Corresponds to NVIC_GetPendingIRQ in CMSIS.
  *
- * @pre{IRQn is valid and not reserved by the stack}
+ * @pre IRQn is valid and not reserved by the stack.
  *
  * @param[in]   IRQn          See the NVIC_GetPendingIRQ documentation in CMSIS.
  * @param[out]  p_pending_irq Return value from NVIC_GetPendingIRQ.
@@ -405,7 +431,7 @@
 /**@brief  Set Pending Interrupt.
  * @note Corresponds to NVIC_SetPendingIRQ in CMSIS.
  *
- * @pre{IRQn is valid and not reserved by the stack}
+ * @pre IRQn is valid and not reserved by the stack.
  *
  * @param[in] IRQn See the NVIC_SetPendingIRQ documentation in CMSIS.
  *
@@ -417,7 +443,7 @@
 /**@brief  Clear Pending Interrupt.
  * @note Corresponds to NVIC_ClearPendingIRQ in CMSIS.
  *
- * @pre{IRQn is valid and not reserved by the stack}
+ * @pre IRQn is valid and not reserved by the stack.
  *
  * @param[in] IRQn See the NVIC_ClearPendingIRQ documentation in CMSIS.
  *
@@ -429,8 +455,8 @@
 /**@brief Set Interrupt Priority.
  * @note Corresponds to NVIC_SetPriority in CMSIS.
  *
- * @pre{IRQn is valid and not reserved by the stack}
- * @pre{priority is valid and not reserved by the stack}
+ * @pre IRQn is valid and not reserved by the stack.
+ * @pre Priority is valid and not reserved by the stack.
  *
  * @param[in] IRQn      See the NVIC_SetPriority documentation in CMSIS.
  * @param[in] priority  A valid IRQ priority for use by the application.
@@ -444,7 +470,7 @@
 /**@brief Get Interrupt Priority.
  * @note Corresponds to NVIC_GetPriority in CMSIS.
  *
- * @pre{IRQn is valid and not reserved by the stack}
+ * @pre IRQn is valid and not reserved by the stack.
  *
  * @param[in]  IRQn         See the NVIC_GetPriority documentation in CMSIS.
  * @param[out] p_priority   Return value from NVIC_GetPriority.
@@ -569,7 +595,7 @@
  */
 SVCALL(SD_POWER_RAMON_SET, uint32_t, sd_power_ramon_set(uint32_t ramon));
 
-/** @brief Clears bits in the NRF_POWER->RAMON register.
+/**@brief Clears bits in the NRF_POWER->RAMON register.
  *
  * @param ramon Contains the bits needed to be cleared in the NRF_POWER->RAMON register.
  *
@@ -611,9 +637,7 @@
 
 /**@brief Sets the DCDC mode.
  *
- * Depending on the internal state of the SoftDevice, the mode change may not happen immediately.
- * The DCDC mode switch will be blocked when occurring in close proximity to radio transmissions. When
- * the radio transmission is done, the last mode will be used.
+ * This function is to enable or disable the DCDC periperhal.
  *
  * @param[in] dcdc_mode The mode of the DCDC.
  *
@@ -759,6 +783,10 @@
  * @note
  *      - The notification signal latency depends on the interrupt priority settings of SWI used
  *        for notification signal.
+ *      - To ensure that the radio notification signal behaves in a consistent way, always 
+ *        configure radio notifications when there is no protocol stack or other SoftDevice 
+ *        activity in progress. It is recommended that the radio notification signal is 
+ *        configured directly after the SoftDevice has been enabled.
  *      - In the period between the ACTIVE signal and the start of the Radio Event, the SoftDevice
  *        will interrupt the application to do Radio Event preparation.
  *      - Using the Radio Notification feature may limit the bandwidth, as the SoftDevice may have
@@ -815,57 +843,64 @@
 SVCALL(SD_TEMP_GET, uint32_t, sd_temp_get(int32_t * p_temp));
 
 /**@brief Flash Write
- *
- * Commands to write a buffer to flash
- *
- * This call initiates the flash access command, and its completion will be communicated to the
- * application with exactly one of the following events:
- *      - NRF_EVT_FLASH_OPERATION_SUCCESS - The command was successfully completed.
- *      - NRF_EVT_FLASH_OPERATION_ERROR   - The command could not be started.
- *
- * @note
- *      - This call takes control over the radio and the CPU during flash erase and write to make sure that
- *        they will not interfere with the flash access. This means that all interrupts will be blocked
- *        for a predictable time (depending on the NVMC specification in nRF51 Series Reference Manual
- *        and the command parameters).
- *
- *
- * @param[in]  p_dst Pointer to start of flash location to be written.
- * @param[in]  p_src Pointer to buffer with data to be written
- * @param[in]  size  Number of 32-bit words to write. Maximum size is 256 32bit words.
- *
- * @retval ::NRF_ERROR_INVALID_ADDR   Tried to write to a non existing flash address, or p_dst or p_src was unaligned.
- * @retval ::NRF_ERROR_BUSY           The previous command has not yet completed.
- * @retval ::NRF_ERROR_INVALID_LENGTH Size was 0, or more than 256 words.
- * @retval ::NRF_ERROR_FORBIDDEN      Tried to write to or read from protected location.
- * @retval ::NRF_SUCCESS              The command was accepted.
- */
+*
+* Commands to write a buffer to flash
+*
+* If the SoftDevice is enabled:
+*  This call initiates the flash access command, and its completion will be communicated to the
+*  application with exactly one of the following events:
+*      - @ref NRF_EVT_FLASH_OPERATION_SUCCESS - The command was successfully completed.
+*      - @ref NRF_EVT_FLASH_OPERATION_ERROR   - The command could not be started.
+*
+* If the SoftDevice is not enabled no event will be generated, and this call will return @ref NRF_SUCCESS when the 
+ * write has been completed
+*
+* @note
+*      - This call takes control over the radio and the CPU during flash erase and write to make sure that
+*        they will not interfere with the flash access. This means that all interrupts will be blocked
+*        for a predictable time (depending on the NVMC specification in nRF51 Series Reference Manual
+*        and the command parameters).
+*
+*
+* @param[in]  p_dst Pointer to start of flash location to be written.
+* @param[in]  p_src Pointer to buffer with data to be written.
+* @param[in]  size  Number of 32-bit words to write. Maximum size is 256 32bit words.
+*
+* @retval ::NRF_ERROR_INVALID_ADDR   Tried to write to a non existing flash address, or p_dst or p_src was unaligned.
+* @retval ::NRF_ERROR_BUSY           The previous command has not yet completed.
+* @retval ::NRF_ERROR_INVALID_LENGTH Size was 0, or more than 256 words.
+* @retval ::NRF_ERROR_FORBIDDEN      Tried to write to or read from protected location.
+* @retval ::NRF_SUCCESS              The command was accepted.
+*/
 SVCALL(SD_FLASH_WRITE, uint32_t, sd_flash_write(uint32_t * const p_dst, uint32_t const * const p_src, uint32_t size));
 
 
 /**@brief Flash Erase page
- *
- * Commands to erase a flash page
- *
- * This call initiates the flash access command, and its completion will be communicated to the
- * application with exactly one of the following events:
- *      - NRF_EVT_FLASH_OPERATION_SUCCESS - The command was successfully completed.
- *      - NRF_EVT_FLASH_OPERATION_ERROR   - The command could not be started.
- *
- * @note
- *      - This call takes control over the radio and the CPU during flash erase and write to make sure that
- *        they will not interfere with the flash access. This means that all interrupts will be blocked
- *        for a predictable time (depending on the NVMC specification in nRF51 Series Reference Manual
- *        and the command parameters).
- *
- *
- * @param[in]  page_number Pagenumber of the page to erase
- * @retval ::NRF_ERROR_INTERNAL      If a new session could not be opened due to an internal error.
- * @retval ::NRF_ERROR_INVALID_ADDR  Tried to erase to a non existing flash page.
- * @retval ::NRF_ERROR_BUSY          The previous command has not yet completed.
- * @retval ::NRF_ERROR_FORBIDDEN     Tried to erase a protected page.
- * @retval ::NRF_SUCCESS             The command was accepted.
- */
+*
+* Commands to erase a flash page
+* If the SoftDevice is enabled:
+*  This call initiates the flash access command, and its completion will be communicated to the
+*  application with exactly one of the following events:
+*      - @ref NRF_EVT_FLASH_OPERATION_SUCCESS - The command was successfully completed.
+*      - @ref NRF_EVT_FLASH_OPERATION_ERROR   - The command could not be started.
+*
+* If the SoftDevice is not enabled no event will be generated, and this call will return @ref NRF_SUCCESS when the 
+* erase has been completed
+*
+* @note
+*      - This call takes control over the radio and the CPU during flash erase and write to make sure that
+*        they will not interfere with the flash access. This means that all interrupts will be blocked
+*        for a predictable time (depending on the NVMC specification in nRF51 Series Reference Manual
+*        and the command parameters).
+*
+*
+* @param[in]  page_number Pagenumber of the page to erase
+* @retval ::NRF_ERROR_INTERNAL      If a new session could not be opened due to an internal error.
+* @retval ::NRF_ERROR_INVALID_ADDR  Tried to erase to a non existing flash page.
+* @retval ::NRF_ERROR_BUSY          The previous command has not yet completed.
+* @retval ::NRF_ERROR_FORBIDDEN     Tried to erase a protected page.
+* @retval ::NRF_SUCCESS             The command was accepted.
+*/
 SVCALL(SD_FLASH_PAGE_ERASE, uint32_t, sd_flash_page_erase(uint32_t page_number));
 
 
@@ -875,23 +910,23 @@
  *
  * @note To read the values in PROTENSETx you can read them directly. They are only write-protected.
  *
- * @param[in]  protenset0 Value to be written to PROTENSET0
- * @param[in]  protenset1 Value to be written to PROTENSET1
+ * @param[in]  protenset0 Value to be written to PROTENSET0.
+ * @param[in]  protenset1 Value to be written to PROTENSET1.
  *
- * @retval ::NRF_ERROR_FORBIDDEN Tried to protect the SoftDevice
- * @retval ::NRF_SUCCESS Values successfully written to PROTENSETx
+ * @retval ::NRF_ERROR_FORBIDDEN Tried to protect the SoftDevice.
+ * @retval ::NRF_SUCCESS Values successfully written to PROTENSETx.
  */
 SVCALL(SD_FLASH_PROTECT, uint32_t, sd_flash_protect(uint32_t protenset0, uint32_t protenset1));
 
 /**@brief Opens a session for radio requests.
  *
  * @note Only one session can be open at a time.
- * @note p_radio_signal_callback(NRF_RADIO_CALLBACK_SIGNAL_TYPE_START) will be called when the radio timeslot
+ * @note p_radio_signal_callback(@ref NRF_RADIO_CALLBACK_SIGNAL_TYPE_START) will be called when the radio timeslot
  *       starts. From this point the NRF_RADIO and NRF_TIMER0 peripherals can be freely accessed
  *       by the application.
- * @note p_radio_signal_callback(NRF_RADIO_CALLBACK_SIGNAL_TYPE_TIMER0) is called whenever the NRF_TIMER0
+ * @note p_radio_signal_callback(@ref NRF_RADIO_CALLBACK_SIGNAL_TYPE_TIMER0) is called whenever the NRF_TIMER0
  *       interrupt occurs.
- * @note p_radio_signal_callback(NRF_RADIO_CALLBACK_SIGNAL_TYPE_RADIO) is called whenever the NRF_RADIO
+ * @note p_radio_signal_callback(@ref NRF_RADIO_CALLBACK_SIGNAL_TYPE_RADIO) is called whenever the NRF_RADIO
  *       interrupt occurs.
  * @note p_radio_signal_callback() will be called at ARM interrupt priority level 0. This
  *       implies that none of the sd_* API calls can be used from p_radio_signal_callback().
@@ -909,7 +944,7 @@
  *
  * @note Any current radio timeslot will be finished before the session is closed.
  * @note If a radio timeslot is scheduled when the session is closed, it will be canceled.
- * @note The application cannot consider the session closed until the NRF_EVT_RADIO_SESSION_CLOSED
+ * @note The application cannot consider the session closed until the @ref NRF_EVT_RADIO_SESSION_CLOSED
  *       event is received.
  *
  * @retval ::NRF_ERROR_FORBIDDEN If session not opened.
@@ -918,23 +953,23 @@
  */
  SVCALL(SD_RADIO_SESSION_CLOSE, uint32_t, sd_radio_session_close(void));
 
- /**@brief Requests a radio timeslot.
+/**@brief Requests a radio timeslot.
  *
- * @note The timing of the radio timeslot is specified by p_request->distance_us. For the first
- *       request in a session, p_request->distance_us is required to be 0 by convention, and
- *       the timeslot is scheduled at the first possible opportunity. All following radio timeslots are
- *       requested with a distance of p_request->distance_us measured from the start of the
- *       previous radio timeslot.
- * @note A too small p_request->distance_us will lead to a NRF_EVT_RADIO_BLOCKED event.
- * @note Timeslots scheduled too close will lead to a NRF_EVT_RADIO_BLOCKED event.
+ * @note The request type is determined by p_request->request_type, and can be one of @ref NRF_RADIO_REQ_TYPE_EARLIEST
+ *       and @ref NRF_RADIO_REQ_TYPE_NORMAL. The first request in a session must always be of type
+ *       @ref NRF_RADIO_REQ_TYPE_EARLIEST.
+ * @note For a normal request (@ref NRF_RADIO_REQ_TYPE_NORMAL), the start time of a radio timeslot is specified by
+ *       p_request->distance_us and is given relative to the start of the previous timeslot. 
+ * @note A too small p_request->distance_us will lead to a @ref NRF_EVT_RADIO_BLOCKED event.
+ * @note Timeslots scheduled too close will lead to a @ref NRF_EVT_RADIO_BLOCKED event.
  * @note See the SoftDevice Specification for more on radio timeslot scheduling, distances and lengths.
  * @note If an opportunity for the first radio timeslot is not found before 100ms after the call to this
- *       function, it is not scheduled, and instead a NRF_EVT_RADIO_BLOCKED event is sent.
+ *       function, it is not scheduled, and instead a @ref NRF_EVT_RADIO_BLOCKED event is sent.
  *       The application may then try to schedule the first radio timeslot again.
- * @note Successful requests will result in nrf_radio_signal_callback_t(NRF_RADIO_CALLBACK_SIGNAL_TYPE_START).
- *       Unsuccessful requests will result in a NRF_EVT_RADIO_BLOCKED event, see @ref NRF_SOC_EVTS.
- * @note The jitter in the start time of the radio timeslots is +/- NRF_RADIO_START_JITTER_US us.
- * @note The nrf_radio_signal_callback_t(NRF_RADIO_CALLBACK_SIGNAL_TYPE_START) call has a latency relative to the
+ * @note Successful requests will result in nrf_radio_signal_callback_t(@ref NRF_RADIO_CALLBACK_SIGNAL_TYPE_START).
+ *       Unsuccessful requests will result in a @ref NRF_EVT_RADIO_BLOCKED event, see @ref NRF_SOC_EVTS.
+ * @note The jitter in the start time of the radio timeslots is +/- @ref NRF_RADIO_START_JITTER_US us.
+ * @note The nrf_radio_signal_callback_t(@ref NRF_RADIO_CALLBACK_SIGNAL_TYPE_START) call has a latency relative to the
  *       specified radio timeslot start, but this does not affect the actual start time of the timeslot.
  * @note NRF_TIMER0 is reset at the start of the radio timeslot, and is clocked at 1MHz from the high frequency
  *       (16 MHz) clock source. If p_request->hfclk_force_xtal is true, the high frequency clock is 
@@ -951,7 +986,7 @@
  */
  SVCALL(SD_RADIO_REQUEST, uint32_t, sd_radio_request(nrf_radio_request_t * p_request ));
 
-/** @} */
+/**@} */
 
 #endif // NRF_SOC_H__
 
--- a/nordic-sdk/components/softdevice/s110/headers/nrf_svc.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/s110/headers/nrf_svc.h	Thu Apr 30 08:34:37 2015 +0100
@@ -1,3 +1,39 @@
+/* 
+ * 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.
+ * 
+ *   4. This software must only be used in a processor manufactured by Nordic
+ *   Semiconductor ASA, or in a processor manufactured by a third party that
+ *   is used in combination with a processor manufactured by Nordic Semiconductor.
+ * 
+ * 
+ * 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_SVC__
 #define NRF_SVC__
 
@@ -10,15 +46,17 @@
 #define SVCALL(number, return_type, signature) return_type __svc(number) signature
 #elif defined (__GNUC__)
 #define SVCALL(number, return_type, signature) \
+  _Pragma("GCC diagnostic ignored \"-Wunused-function\"") \
+  _Pragma("GCC diagnostic push") \
   _Pragma("GCC diagnostic ignored \"-Wreturn-type\"") \
-  _Pragma("GCC diagnostic ignored \"-Wunused-function\"") \
   __attribute__((naked)) static return_type signature \
   { \
     __asm( \
         "svc %0\n" \
-        "bx r14" : : "I" ((uint32_t)number) : "r0" \
+        "bx r14" : : "I" (number) : "r0" \
     ); \
-  }
+  }    \
+  _Pragma("GCC diagnostic pop")
 #elif defined (__ICCARM__)
 #define PRAGMA(x) _Pragma(#x)
 #define SVCALL(number, return_type, signature) \
--- a/nordic-sdk/components/softdevice/s110/headers/softdevice_assert.h	Wed Apr 15 09:24:27 2015 +0100
+++ b/nordic-sdk/components/softdevice/s110/headers/softdevice_assert.h	Thu Apr 30 08:34:37 2015 +0100
@@ -1,10 +1,37 @@
-/*
- * Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is confidential property of Nordic Semiconductor. The use,
- * copying, transfer or disclosure of such information is prohibited except by express written
- * agreement with Nordic Semiconductor.
- *
+/* 
+ * 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.
+ * 
+ *   4. This software must only be used in a processor manufactured by Nordic
+ *   Semiconductor ASA, or in a processor manufactured by a third party that
+ *   is used in combination with a processor manufactured by Nordic Semiconductor.
+ * 
+ * 
+ * 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.
+ * 
  */
 
 /** @brief Utilities for verifying program logic