No changes

Fork of nRF51822 by Nordic Semiconductor

Committer:
vcoubard
Date:
Mon Jan 11 10:19:15 2016 +0000
Revision:
561:613dbbdeed27
Parent:
558:c4b56f9d6f3b
Child:
563:9c4b96f7be8d
Synchronized with git rev 7bf81e7e
Author: Andres Amaya Garcia
Improve shutdown to clear BLE API and not just SD

Improve the shutdown functionality, such that a call to ble.shutdown() from
the user application clears the API and nRF5x state and NOT only the
SoftDevice. To achieve this the following changes are introduced:

* Add a protected member cleanup() to nRF5xGap, nRF5xGattClient,
nRF5xGattServer, nRF5xSecurityManager and nRF5xServiceDiscovery.
* Modify the shutdown() implementation in nRF5xn such that it also calls the
static member shutdown() exposed by the BLE API in Gap.h, SecurityManager.h,
GattClient.h and GattServer.h.
* Modify nRF5xGattClient, nRF5xGattServer and nRF5xSecurityManager
classes so that they dynamically create their respective objects only if
needed. Previously the GattClient, GattServer and SecurityManager objects were
declared as static, which means that they were always present even though they
were not always needed. This increases memory consumption unnecessarily.
Furthermore, pointers to the object instances are stored in static members of
the classes as specified by the BLE API base classes. This ensures that
calls to shutdown do not require calls to getInstance() functions that would
otherwise result in undesired memory allocations.
* nRF5xGap object is always needed, so this remains allocated statically. But
the reference in Gap is pointed to this object.

The shutdown procedure is as follows:

1. The user calls ble.shutdown() which executes the code in nRF5xn::shutdown()
1. The SoftDevice is shutdown
1. The static members of Gap.h, SecurityManager.h, GattClient.h and
GattServer.h are called to clean up their own state.

If at any point an error occur during the last step, BLE_ERROR_INVALID_STATE is
returned.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vcoubard 558:c4b56f9d6f3b 1 /* mbed Microcontroller Library
vcoubard 558:c4b56f9d6f3b 2 * Copyright (c) 2006-2013 ARM Limited
vcoubard 558:c4b56f9d6f3b 3 *
vcoubard 558:c4b56f9d6f3b 4 * Licensed under the Apache License, Version 2.0 (the "License");
vcoubard 558:c4b56f9d6f3b 5 * you may not use this file except in compliance with the License.
vcoubard 558:c4b56f9d6f3b 6 * You may obtain a copy of the License at
vcoubard 558:c4b56f9d6f3b 7 *
vcoubard 558:c4b56f9d6f3b 8 * http://www.apache.org/licenses/LICENSE-2.0
vcoubard 558:c4b56f9d6f3b 9 *
vcoubard 558:c4b56f9d6f3b 10 * Unless required by applicable law or agreed to in writing, software
vcoubard 558:c4b56f9d6f3b 11 * distributed under the License is distributed on an "AS IS" BASIS,
vcoubard 558:c4b56f9d6f3b 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
vcoubard 558:c4b56f9d6f3b 13 * See the License for the specific language governing permissions and
vcoubard 558:c4b56f9d6f3b 14 * limitations under the License.
vcoubard 558:c4b56f9d6f3b 15 */
vcoubard 558:c4b56f9d6f3b 16
vcoubard 558:c4b56f9d6f3b 17 #ifndef __NRF51822_SECURITY_MANAGER_H__
vcoubard 558:c4b56f9d6f3b 18 #define __NRF51822_SECURITY_MANAGER_H__
vcoubard 558:c4b56f9d6f3b 19
vcoubard 558:c4b56f9d6f3b 20 #include <stddef.h>
vcoubard 558:c4b56f9d6f3b 21
vcoubard 558:c4b56f9d6f3b 22 #include "ble/SecurityManager.h"
vcoubard 558:c4b56f9d6f3b 23 #include "btle_security.h"
vcoubard 558:c4b56f9d6f3b 24
vcoubard 558:c4b56f9d6f3b 25 class nRF5xSecurityManager : public SecurityManager
vcoubard 558:c4b56f9d6f3b 26 {
vcoubard 558:c4b56f9d6f3b 27 public:
vcoubard 558:c4b56f9d6f3b 28 static nRF5xSecurityManager &getInstance();
vcoubard 558:c4b56f9d6f3b 29
vcoubard 558:c4b56f9d6f3b 30 /* Functions that must be implemented from SecurityManager */
vcoubard 558:c4b56f9d6f3b 31 virtual ble_error_t init(bool enableBonding,
vcoubard 558:c4b56f9d6f3b 32 bool requireMITM,
vcoubard 558:c4b56f9d6f3b 33 SecurityIOCapabilities_t iocaps,
vcoubard 558:c4b56f9d6f3b 34 const Passkey_t passkey) {
vcoubard 558:c4b56f9d6f3b 35 return btle_initializeSecurity(enableBonding, requireMITM, iocaps, passkey);
vcoubard 558:c4b56f9d6f3b 36 }
vcoubard 558:c4b56f9d6f3b 37
vcoubard 558:c4b56f9d6f3b 38 virtual ble_error_t getLinkSecurity(Gap::Handle_t connectionHandle, LinkSecurityStatus_t *securityStatusP) {
vcoubard 558:c4b56f9d6f3b 39 return btle_getLinkSecurity(connectionHandle, securityStatusP);
vcoubard 558:c4b56f9d6f3b 40 }
vcoubard 558:c4b56f9d6f3b 41
vcoubard 558:c4b56f9d6f3b 42 virtual ble_error_t setLinkSecurity(Gap::Handle_t connectionHandle, SecurityMode_t securityMode) {
vcoubard 558:c4b56f9d6f3b 43 return btle_setLinkSecurity(connectionHandle, securityMode);
vcoubard 558:c4b56f9d6f3b 44 }
vcoubard 558:c4b56f9d6f3b 45
vcoubard 558:c4b56f9d6f3b 46 virtual ble_error_t purgeAllBondingState(void) {
vcoubard 558:c4b56f9d6f3b 47 return btle_purgeAllBondingState();
vcoubard 558:c4b56f9d6f3b 48 }
vcoubard 558:c4b56f9d6f3b 49
vcoubard 561:613dbbdeed27 50 /**
vcoubard 561:613dbbdeed27 51 * @brief Clear nRF5xSecurityManager's state.
vcoubard 561:613dbbdeed27 52 *
vcoubard 561:613dbbdeed27 53 * @return
vcoubard 561:613dbbdeed27 54 * BLE_ERROR_NONE if successful.
vcoubard 561:613dbbdeed27 55 */
vcoubard 561:613dbbdeed27 56 virtual ble_error_t cleanup(void)
vcoubard 561:613dbbdeed27 57 {
vcoubard 561:613dbbdeed27 58 if (SecurityManager::cleanup() != BLE_ERROR_NONE) {
vcoubard 561:613dbbdeed27 59 return BLE_ERROR_INVALID_STATE;
vcoubard 561:613dbbdeed27 60 }
vcoubard 561:613dbbdeed27 61
vcoubard 561:613dbbdeed27 62 return BLE_ERROR_NONE;
vcoubard 561:613dbbdeed27 63 }
vcoubard 561:613dbbdeed27 64
vcoubard 558:c4b56f9d6f3b 65 public:
vcoubard 558:c4b56f9d6f3b 66 nRF5xSecurityManager() {
vcoubard 558:c4b56f9d6f3b 67 /* empty */
vcoubard 558:c4b56f9d6f3b 68 }
vcoubard 558:c4b56f9d6f3b 69
vcoubard 558:c4b56f9d6f3b 70 private:
vcoubard 558:c4b56f9d6f3b 71 nRF5xSecurityManager(const nRF5xSecurityManager &);
vcoubard 558:c4b56f9d6f3b 72 const nRF5xSecurityManager& operator=(const nRF5xSecurityManager &);
vcoubard 558:c4b56f9d6f3b 73 };
vcoubard 558:c4b56f9d6f3b 74
rgrover1 388:db85a09c27ef 75 #endif // ifndef __NRF51822_SECURITY_MANAGER_H__