test

Dependencies:   nrf51-sdk

Dependents:   microbit-dal

Fork of nRF51822 by Lancaster University

Committer:
vcoubard
Date:
Mon Jan 11 10:19:36 2016 +0000
Revision:
599:3e66e1eb264d
Parent:
598:814c1ce92947
Child:
613:cbc548e9df98
Synchronized with git rev 2ebbcb08
Author: Andres Amaya Garcia
Add documentation and fix style of SecurityManager

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 598:814c1ce92947 22 #include "nRF5xGap.h"
vcoubard 558:c4b56f9d6f3b 23 #include "ble/SecurityManager.h"
vcoubard 558:c4b56f9d6f3b 24 #include "btle_security.h"
vcoubard 558:c4b56f9d6f3b 25
vcoubard 558:c4b56f9d6f3b 26 class nRF5xSecurityManager : public SecurityManager
vcoubard 558:c4b56f9d6f3b 27 {
vcoubard 558:c4b56f9d6f3b 28 public:
vcoubard 558:c4b56f9d6f3b 29 /* Functions that must be implemented from SecurityManager */
vcoubard 558:c4b56f9d6f3b 30 virtual ble_error_t init(bool enableBonding,
vcoubard 558:c4b56f9d6f3b 31 bool requireMITM,
vcoubard 558:c4b56f9d6f3b 32 SecurityIOCapabilities_t iocaps,
vcoubard 558:c4b56f9d6f3b 33 const Passkey_t passkey) {
vcoubard 558:c4b56f9d6f3b 34 return btle_initializeSecurity(enableBonding, requireMITM, iocaps, passkey);
vcoubard 558:c4b56f9d6f3b 35 }
vcoubard 558:c4b56f9d6f3b 36
vcoubard 558:c4b56f9d6f3b 37 virtual ble_error_t getLinkSecurity(Gap::Handle_t connectionHandle, LinkSecurityStatus_t *securityStatusP) {
vcoubard 558:c4b56f9d6f3b 38 return btle_getLinkSecurity(connectionHandle, securityStatusP);
vcoubard 558:c4b56f9d6f3b 39 }
vcoubard 558:c4b56f9d6f3b 40
vcoubard 558:c4b56f9d6f3b 41 virtual ble_error_t setLinkSecurity(Gap::Handle_t connectionHandle, SecurityMode_t securityMode) {
vcoubard 558:c4b56f9d6f3b 42 return btle_setLinkSecurity(connectionHandle, securityMode);
vcoubard 558:c4b56f9d6f3b 43 }
vcoubard 558:c4b56f9d6f3b 44
vcoubard 558:c4b56f9d6f3b 45 virtual ble_error_t purgeAllBondingState(void) {
vcoubard 558:c4b56f9d6f3b 46 return btle_purgeAllBondingState();
vcoubard 558:c4b56f9d6f3b 47 }
vcoubard 558:c4b56f9d6f3b 48
vcoubard 575:7023a8204a1b 49 /**
vcoubard 575:7023a8204a1b 50 * @brief Clear nRF5xSecurityManager's state.
vcoubard 575:7023a8204a1b 51 *
vcoubard 575:7023a8204a1b 52 * @return
vcoubard 575:7023a8204a1b 53 * BLE_ERROR_NONE if successful.
vcoubard 575:7023a8204a1b 54 */
vcoubard 575:7023a8204a1b 55 virtual ble_error_t reset(void)
vcoubard 575:7023a8204a1b 56 {
vcoubard 575:7023a8204a1b 57 if (SecurityManager::reset() != BLE_ERROR_NONE) {
vcoubard 575:7023a8204a1b 58 return BLE_ERROR_INVALID_STATE;
vcoubard 575:7023a8204a1b 59 }
vcoubard 575:7023a8204a1b 60
vcoubard 575:7023a8204a1b 61 return BLE_ERROR_NONE;
vcoubard 575:7023a8204a1b 62 }
vcoubard 575:7023a8204a1b 63
vcoubard 598:814c1ce92947 64 bool hasInitialized(void) const {
vcoubard 598:814c1ce92947 65 return btle_hasInitializedSecurity();
vcoubard 598:814c1ce92947 66 }
vcoubard 598:814c1ce92947 67
vcoubard 558:c4b56f9d6f3b 68 public:
vcoubard 575:7023a8204a1b 69 /*
vcoubard 575:7023a8204a1b 70 * Allow instantiation from nRF5xn when required.
vcoubard 575:7023a8204a1b 71 */
vcoubard 575:7023a8204a1b 72 friend class nRF5xn;
vcoubard 575:7023a8204a1b 73
vcoubard 558:c4b56f9d6f3b 74 nRF5xSecurityManager() {
vcoubard 558:c4b56f9d6f3b 75 /* empty */
vcoubard 558:c4b56f9d6f3b 76 }
vcoubard 558:c4b56f9d6f3b 77
vcoubard 558:c4b56f9d6f3b 78 private:
vcoubard 558:c4b56f9d6f3b 79 nRF5xSecurityManager(const nRF5xSecurityManager &);
vcoubard 558:c4b56f9d6f3b 80 const nRF5xSecurityManager& operator=(const nRF5xSecurityManager &);
vcoubard 598:814c1ce92947 81
vcoubard 599:3e66e1eb264d 82 /*
vcoubard 599:3e66e1eb264d 83 * Expose an interface that allows us to query the SoftDevice bond table
vcoubard 599:3e66e1eb264d 84 * and extract a whitelist.
vcoubard 599:3e66e1eb264d 85 */
vcoubard 598:814c1ce92947 86 ble_error_t createWhitelistFromBondTable(ble_gap_whitelist_t &whitelistFromBondTable) const {
vcoubard 598:814c1ce92947 87 return btle_createWhitelistFromBondTable(&whitelistFromBondTable);
vcoubard 598:814c1ce92947 88 }
vcoubard 598:814c1ce92947 89
vcoubard 599:3e66e1eb264d 90 /*
vcoubard 599:3e66e1eb264d 91 * Given a BLE address and a IRK this function check whether the address
vcoubard 599:3e66e1eb264d 92 * can be generated from the IRK. To do so, this function uses the hash
vcoubard 599:3e66e1eb264d 93 * function and algorithm described in the Bluetooth low Energy
vcoubard 599:3e66e1eb264d 94 * Specification. Internally, Nordic SDK functions are used.
vcoubard 599:3e66e1eb264d 95 */
vcoubard 598:814c1ce92947 96 bool matchAddressAndIrk(ble_gap_addr_t *address, ble_gap_irk_t *irk) const {
vcoubard 598:814c1ce92947 97 return btle_matchAddressAndIrk(address, irk);
vcoubard 598:814c1ce92947 98 }
vcoubard 599:3e66e1eb264d 99
vcoubard 599:3e66e1eb264d 100 /*
vcoubard 599:3e66e1eb264d 101 * Give nRF5xGap access to createWhitelistFromBondTable() and
vcoubard 599:3e66e1eb264d 102 * matchAddressAndIrk()
vcoubard 599:3e66e1eb264d 103 */
vcoubard 598:814c1ce92947 104 friend class nRF5xGap;
vcoubard 558:c4b56f9d6f3b 105 };
vcoubard 558:c4b56f9d6f3b 106
rgrover1 388:db85a09c27ef 107 #endif // ifndef __NRF51822_SECURITY_MANAGER_H__