add "LE Device Address" 0x1B to advertising data types
Fork of BLE_API by
Revision 1075:0d0dafb54bc9, committed 2016-01-11
- Comitter:
- vcoubard
- Date:
- Mon Jan 11 08:51:43 2016 +0000
- Parent:
- 1074:1fedc77d9add
- Child:
- 1076:5f938eb2bd6a
- Commit message:
- Synchronized with git rev 17d6e5fe
Author: Rohit Grover
Extract Adress related types from Gap.h into BLEProtocol.h
Changed in this revision
--- a/ble/BLE.h Mon Jan 11 08:51:42 2016 +0000 +++ b/ble/BLE.h Mon Jan 11 08:51:43 2016 +0000 @@ -196,7 +196,7 @@ * directly, as it returns references to singletons. * * @param[in] id - * Instance-ID. This should be less than NUM_INSTANCES + * Instance-ID. This should be less than NUM_INSTANCES * for the returned BLE singleton to be useful. * * @return a reference to a single object. @@ -239,7 +239,7 @@ * ble.setAddress(...) should be replaced with * ble.gap().setAddress(...). */ - ble_error_t setAddress(Gap::AddressType_t type, const Gap::Address_t address) { + ble_error_t setAddress(BLEProtocol::AddressType::Type type, const Gap::Address_t address) { return gap().setAddress(type, address); } @@ -252,7 +252,7 @@ * ble.getAddress(...) should be replaced with * ble.gap().getAddress(...). */ - ble_error_t getAddress(Gap::AddressType_t *typeP, Gap::Address_t address) { + ble_error_t getAddress(BLEProtocol::AddressType::Type *typeP, Gap::Address_t address) { return gap().getAddress(typeP, address); } @@ -753,7 +753,7 @@ * ble.gap().connect(...). */ ble_error_t connect(const Gap::Address_t peerAddr, - Gap::AddressType_t peerAddrType = Gap::ADDR_TYPE_RANDOM_STATIC, + BLEProtocol::AddressType::Type peerAddrType = BLEProtocol::AddressType::RANDOM_STATIC, const Gap::ConnectionParams_t *connectionParams = NULL, const GapScanningParams *scanParams = NULL) { return gap().connect(peerAddr, peerAddrType, connectionParams, scanParams); @@ -773,7 +773,7 @@ } /** - * This call initiates the disconnection procedure, and its completion + * This call initiates the disconnection procedure, and its completion * is communicated to the application with an invocation of the * onDisconnection callback. * @@ -1407,7 +1407,7 @@ /** * Set up a callback for when the passkey needs to be displayed on a * peripheral with DISPLAY capability. This happens when security is - * configured to prevent Man-In-The-Middle attacks, and the peers need to exchange + * configured to prevent Man-In-The-Middle attacks, and the peers need to exchange * a passkey (or PIN) to authenticate the connection * attempt. *
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ble/BLEProtocol.h Mon Jan 11 08:51:43 2016 +0000 @@ -0,0 +1,49 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __BLE_PROTOCOL_H__ +#define __BLE_PROTOCOL_H__ + +#include <stddef.h> +#include <stdint.h> + +/** + * A common container for types and constants used everywhere in BLE API. + */ +struct BLEProtocol { + /**< Address-type for Protocol addresses. */ + struct AddressType { /* Adding a struct to encapsulate the contained enumeration + * prevents polluting the BLEProtocol namespace with the + * enumerated values. It also allows type-aliases for the + * enumeration while retaining the enumerated values. i.e. + * + * doing: + * typedef AddressType_t AliasedType_t; + * would allow the use of AliasedType_t::PUBLIC in code. + */ + enum Type { + PUBLIC = 0, + RANDOM_STATIC, + RANDOM_PRIVATE_RESOLVABLE, + RANDOM_PRIVATE_NON_RESOLVABLE + }; + }; + + static const size_t ADDR_LEN = 6; /**< Length (in octets) of the BLE MAC address. */ + typedef uint8_t Address_t[ADDR_LEN]; /**< 48-bit address, in LSB format. */ +}; + +#endif /* __BLE_PROTOCOL_H__ */ \ No newline at end of file
--- a/ble/Gap.h Mon Jan 11 08:51:42 2016 +0000 +++ b/ble/Gap.h Mon Jan 11 08:51:43 2016 +0000 @@ -17,6 +17,7 @@ #ifndef __GAP_H__ #define __GAP_H__ +#include "ble/BLEProtocol.h" #include "GapAdvertisingData.h" #include "GapAdvertisingParams.h" #include "GapScanningParams.h" @@ -30,19 +31,28 @@ class GapAdvertisingData; class Gap { + /* + * DEPRECATION ALERT: all of the APIs in this `public` block are deprecated. + * They have been relocated to the class BLEProtocol. + */ public: - enum AddressType_t { - ADDR_TYPE_PUBLIC = 0, - ADDR_TYPE_RANDOM_STATIC, - ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE, - ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE - }; - typedef enum AddressType_t addr_type_t; /* @Note: Deprecated. Use AddressType_t instead. */ + /** + * Address-type for BLEProtocol addresses. + * @note: deprecated. Use BLEProtocol::AddressType::Type instead. + */ + typedef BLEProtocol::AddressType::Type AddressType_t; - static const unsigned ADDR_LEN = 6; - typedef uint8_t Address_t[ADDR_LEN]; /* 48-bit address, LSB format. */ - typedef Address_t address_t; /* @Note: Deprecated. Use Address_t instead. */ + /** + * Address-type for BLEProtocol addresses. + * @note: deprecated. Use BLEProtocol::AddressType::Type instead. + */ + typedef BLEProtocol::AddressType::Type addr_type_t; + static const unsigned ADDR_LEN = BLEProtocol::ADDR_LEN; /**< Length (in octets) of the BLE MAC address. */ + typedef BLEProtocol::Address_t Address_t; /**< 48-bit address, LSB format. @Note: Deprecated. Use BLEProtocol::Address_t instead. */ + typedef BLEProtocol::Address_t address_t; /**< 48-bit address, LSB format. @Note: Deprecated. Use BLEProtocol::Address_t instead. */ + +public: enum TimeoutSource_t { TIMEOUT_SRC_ADVERTISING = 0x00, /**< Advertising timeout. */ TIMEOUT_SRC_SECURITY_REQUEST = 0x01, /**< Security request timeout. */ @@ -97,21 +107,21 @@ typedef FunctionPointerWithContext<const AdvertisementCallbackParams_t *> AdvertisementReportCallback_t; struct ConnectionCallbackParams_t { - Handle_t handle; - Role_t role; - AddressType_t peerAddrType; - Address_t peerAddr; - AddressType_t ownAddrType; - Address_t ownAddr; - const ConnectionParams_t *connectionParams; + Handle_t handle; + Role_t role; + BLEProtocol::AddressType::Type peerAddrType; + Address_t peerAddr; + BLEProtocol::AddressType::Type ownAddrType; + Address_t ownAddr; + const ConnectionParams_t *connectionParams; - ConnectionCallbackParams_t(Handle_t handleIn, - Role_t roleIn, - AddressType_t peerAddrTypeIn, - const uint8_t *peerAddrIn, - AddressType_t ownAddrTypeIn, - const uint8_t *ownAddrIn, - const ConnectionParams_t *connectionParamsIn) : + ConnectionCallbackParams_t(Handle_t handleIn, + Role_t roleIn, + BLEProtocol::AddressType::Type peerAddrTypeIn, + const uint8_t *peerAddrIn, + BLEProtocol::AddressType::Type ownAddrTypeIn, + const uint8_t *ownAddrIn, + const ConnectionParams_t *connectionParamsIn) : handle(handleIn), role(roleIn), peerAddrType(peerAddrTypeIn), @@ -161,7 +171,7 @@ * * @return BLE_ERROR_NONE on success. */ - virtual ble_error_t setAddress(AddressType_t type, const Address_t address) { + virtual ble_error_t setAddress(BLEProtocol::AddressType::Type type, const Address_t address) { /* avoid compiler warnings about unused variables */ (void)type; (void)address; @@ -174,7 +184,7 @@ * * @return BLE_ERROR_NONE on success. */ - virtual ble_error_t getAddress(AddressType_t *typeP, Address_t address) { + virtual ble_error_t getAddress(BLEProtocol::AddressType::Type *typeP, Address_t address) { /* Avoid compiler warnings about unused variables. */ (void)typeP; (void)address; @@ -233,10 +243,10 @@ * successfully. The connectionCallChain (if set) will be invoked upon * a connection event. */ - virtual ble_error_t connect(const Address_t peerAddr, - Gap::AddressType_t peerAddrType, - const ConnectionParams_t *connectionParams, - const GapScanningParams *scanParams) { + virtual ble_error_t connect(const Address_t peerAddr, + BLEProtocol::AddressType::Type peerAddrType, + const ConnectionParams_t *connectionParams, + const GapScanningParams *scanParams) { /* Avoid compiler warnings about unused variables. */ (void)peerAddr; (void)peerAddrType; @@ -983,42 +993,6 @@ radioNotificationCallback.attach(tptr, mptr); } -public: - /** - * Clear all Gap state of the associated object. - * - * This function is meant to be overridden in the platform-specific - * sub-class. Nevertheless, the sub-class is only expected to reset its - * state and not the data held in Gap members. This shall be achieved by a - * call to Gap::reset() from the sub-class' reset() implementation. - * - * @return BLE_ERROR_NONE on success. - * - * @note: Currently a call to reset() does not reset the advertising and - * scan parameters to default values. - */ - virtual ble_error_t reset(void) { - /* Clear Gap state */ - state.advertising = 0; - state.connected = 0; - - /* Clear scanning state */ - scanningActive = false; - - /* Clear advertising and scanning data */ - _advPayload.clear(); - _scanResponse.clear(); - - /* Clear callbacks */ - timeoutCallbackChain.clear(); - connectionCallChain.clear(); - disconnectionCallChain.clear(); - radioNotificationCallback = NULL; - onAdvertisementReport = NULL; - - return BLE_ERROR_NONE; - } - protected: Gap() : _advParams(), @@ -1038,13 +1012,13 @@ /* Entry points for the underlying stack to report events back to the user. */ public: - void processConnectionEvent(Handle_t handle, - Role_t role, - AddressType_t peerAddrType, - const Address_t peerAddr, - AddressType_t ownAddrType, - const Address_t ownAddr, - const ConnectionParams_t *connectionParams) { + void processConnectionEvent(Handle_t handle, + Role_t role, + BLEProtocol::AddressType::Type peerAddrType, + const Address_t peerAddr, + BLEProtocol::AddressType::Type ownAddrType, + const Address_t ownAddr, + const ConnectionParams_t *connectionParams) { state.connected = 1; ConnectionCallbackParams_t callbackParams(handle, role, peerAddrType, peerAddr, ownAddrType, ownAddr, connectionParams); connectionCallChain.call(&callbackParams);
--- a/ble/GattClient.h Mon Jan 11 08:51:42 2016 +0000 +++ b/ble/GattClient.h Mon Jan 11 08:51:43 2016 +0000 @@ -325,26 +325,6 @@ return onHVXCallbackChain; } -public: - /** - * Clear all GattClient state of the associated object. - * - * This function is meant to be overridden in the platform-specific - * sub-class. Nevertheless, the sub-class is only expected to reset its - * state and not the data held in GattClient members. This shall be achieved - * by a call to GattClient::reset() from the sub-class' reset() - * implementation. - * - * @return BLE_ERROR_NONE on success. - */ - virtual ble_error_t reset(void) { - onDataReadCallbackChain.clear(); - onDataWriteCallbackChain.clear(); - onHVXCallbackChain.clear(); - - return BLE_ERROR_NONE; - } - protected: GattClient() { /* Empty */
--- a/ble/GattServer.h Mon Jan 11 08:51:42 2016 +0000 +++ b/ble/GattServer.h Mon Jan 11 08:51:43 2016 +0000 @@ -396,32 +396,6 @@ dataSentCallChain.call(count); } -public: - /** - * Clear all GattServer state of the associated object. - * - * This function is meant to be overridden in the platform-specific - * sub-class. Nevertheless, the sub-class is only expected to reset its - * state and not the data held in GattServer members. This shall be achieved - * by a call to GattServer::reset() from the sub-class' reset() - * implementation. - * - * @return BLE_ERROR_NONE on success. - */ - virtual ble_error_t reset(void) { - serviceCount = 0; - characteristicCount = 0; - - dataSentCallChain.clear(); - dataWrittenCallChain.clear(); - dataReadCallChain.clear(); - updatesEnabledCallback = NULL; - updatesDisabledCallback = NULL; - confirmationReceivedCallback = NULL; - - return BLE_ERROR_NONE; - } - protected: uint8_t serviceCount; uint8_t characteristicCount;
--- a/ble/SecurityManager.h Mon Jan 11 08:51:42 2016 +0000 +++ b/ble/SecurityManager.h Mon Jan 11 08:51:43 2016 +0000 @@ -231,28 +231,6 @@ /* empty */ } -public: - /** - * Clear all SecurityManager state of the associated object. - * - * This function is meant to be overridden in the platform-specific - * sub-class. Nevertheless, the sub-class is only expected to reset its - * state and not the data held in SecurityManager members. This shall be - * achieved by a call to SecurityManager::reset() from the sub-class' - * reset() implementation. - * - * @return BLE_ERROR_NONE on success. - */ - virtual ble_error_t reset(void) { - securitySetupInitiatedCallback = NULL; - securitySetupCompletedCallback = NULL; - linkSecuredCallback = NULL; - securityContextStoredCallback = NULL; - passkeyDisplayCallback = NULL; - - return BLE_ERROR_NONE; - } - protected: SecuritySetupInitiatedCallback_t securitySetupInitiatedCallback; SecuritySetupCompletedCallback_t securitySetupCompletedCallback;
--- a/ble/ServiceDiscovery.h Mon Jan 11 08:51:42 2016 +0000 +++ b/ble/ServiceDiscovery.h Mon Jan 11 08:51:43 2016 +0000 @@ -132,27 +132,6 @@ */ virtual void onTermination(TerminationCallback_t callback) = 0; - /** - * Clear all ServiceDiscovery state of the associated object. - * - * This function is meant to be overridden in the platform-specific - * sub-class. Nevertheless, the sub-class is only expected to reset its - * state and not the data held in ServiceDiscovery members. This shall be - * achieved by a call to ServiceDiscovery::reset() from the sub-class' - * reset() implementation. - * - * @return BLE_ERROR_NONE on success. - */ - virtual ble_error_t reset(void) { - connHandle = 0; - matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN); - serviceCallback = NULL; - matchingCharacteristicUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN); - characteristicCallback = NULL; - - return BLE_ERROR_NONE; - } - protected: Gap::Handle_t connHandle; /**< Connection handle as provided by the SoftDevice. */ UUID matchingServiceUUID;
--- a/source/BLE.cpp Mon Jan 11 08:51:42 2016 +0000 +++ b/source/BLE.cpp Mon Jan 11 08:51:43 2016 +0000 @@ -131,6 +131,7 @@ ble_error_t BLE::shutdown(void) { + clearAdvertisingPayload(); if (!transport) { error("bad handle to underlying transport"); }