add "LE Device Address" 0x1B to advertising data types

Fork of BLE_API by Bluetooth Low Energy

Committer:
vcoubard
Date:
Mon Jan 11 08:51:29 2016 +0000
Revision:
1050:37101a458dfb
Parent:
1048:efb29faf12fc
Child:
1052:b55e1ad3e1b3
Synchronized with git rev 15c69957
Author: Vincent Coubard
Add operator!= for DiscoveredCharacteristic::Properties_t

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 716:11b41f651697 1 /* mbed Microcontroller Library
rgrover1 716:11b41f651697 2 * Copyright (c) 2006-2013 ARM Limited
rgrover1 716:11b41f651697 3 *
rgrover1 716:11b41f651697 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 716:11b41f651697 5 * you may not use this file except in compliance with the License.
rgrover1 716:11b41f651697 6 * You may obtain a copy of the License at
rgrover1 716:11b41f651697 7 *
rgrover1 716:11b41f651697 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 716:11b41f651697 9 *
rgrover1 716:11b41f651697 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 716:11b41f651697 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 716:11b41f651697 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 716:11b41f651697 13 * See the License for the specific language governing permissions and
rgrover1 716:11b41f651697 14 * limitations under the License.
rgrover1 716:11b41f651697 15 */
rgrover1 716:11b41f651697 16
rgrover1 716:11b41f651697 17 #ifndef __DISCOVERED_CHARACTERISTIC_H__
rgrover1 716:11b41f651697 18 #define __DISCOVERED_CHARACTERISTIC_H__
rgrover1 716:11b41f651697 19
rgrover1 716:11b41f651697 20 #include "UUID.h"
rgrover1 716:11b41f651697 21 #include "Gap.h"
rgrover1 716:11b41f651697 22 #include "GattAttribute.h"
rgrover1 716:11b41f651697 23 #include "GattClient.h"
vcoubard 1045:b9d15970040f 24 #include "CharacteristicDescriptorDiscovery.h"
vcoubard 1045:b9d15970040f 25 #include "ble/DiscoveredCharacteristicDescriptor.h"
vcoubard 1045:b9d15970040f 26
rgrover1 716:11b41f651697 27
rgrover1 716:11b41f651697 28 /**
rgrover1 716:11b41f651697 29 * Structure for holding information about the service and the characteristics
rgrover1 716:11b41f651697 30 * found during the discovery process.
rgrover1 716:11b41f651697 31 */
rgrover1 716:11b41f651697 32 class DiscoveredCharacteristic {
rgrover1 716:11b41f651697 33 public:
rgrover1 716:11b41f651697 34 struct Properties_t {
vcoubard 1048:efb29faf12fc 35 uint8_t _broadcast :1; /**< Broadcasting the value permitted. */
rgrover1 716:11b41f651697 36 uint8_t _read :1; /**< Reading the value permitted. */
rgrover1 716:11b41f651697 37 uint8_t _writeWoResp :1; /**< Writing the value with Write Command permitted. */
rgrover1 716:11b41f651697 38 uint8_t _write :1; /**< Writing the value with Write Request permitted. */
rgrover1 716:11b41f651697 39 uint8_t _notify :1; /**< Notications of the value permitted. */
rgrover1 716:11b41f651697 40 uint8_t _indicate :1; /**< Indications of the value permitted. */
rgrover1 716:11b41f651697 41 uint8_t _authSignedWrite :1; /**< Writing the value with Signed Write Command permitted. */
rgrover1 716:11b41f651697 42
rgrover1 716:11b41f651697 43 public:
rgrover1 716:11b41f651697 44 bool broadcast(void) const {return _broadcast; }
rgrover1 716:11b41f651697 45 bool read(void) const {return _read; }
rgrover1 716:11b41f651697 46 bool writeWoResp(void) const {return _writeWoResp; }
rgrover1 716:11b41f651697 47 bool write(void) const {return _write; }
rgrover1 716:11b41f651697 48 bool notify(void) const {return _notify; }
rgrover1 716:11b41f651697 49 bool indicate(void) const {return _indicate; }
rgrover1 716:11b41f651697 50 bool authSignedWrite(void) const {return _authSignedWrite;}
rgrover1 716:11b41f651697 51
vcoubard 1045:b9d15970040f 52 friend bool operator==(Properties_t rhs, Properties_t lhs) {
vcoubard 1045:b9d15970040f 53 return rhs._broadcast == lhs._broadcast &&
vcoubard 1045:b9d15970040f 54 rhs._read == lhs._read &&
vcoubard 1045:b9d15970040f 55 rhs._writeWoResp == lhs._writeWoResp &&
vcoubard 1045:b9d15970040f 56 rhs._write == lhs._write &&
vcoubard 1045:b9d15970040f 57 rhs._notify == lhs._notify &&
vcoubard 1045:b9d15970040f 58 rhs._indicate == lhs._indicate &&
vcoubard 1045:b9d15970040f 59 rhs._authSignedWrite == lhs._authSignedWrite;
vcoubard 1045:b9d15970040f 60 }
vcoubard 1045:b9d15970040f 61
vcoubard 1050:37101a458dfb 62 friend bool operator!=(Properties_t rhs, Properties_t lhs) {
vcoubard 1050:37101a458dfb 63 return !(rhs == lhs);
vcoubard 1050:37101a458dfb 64 }
vcoubard 1050:37101a458dfb 65
rgrover1 716:11b41f651697 66 private:
vcoubard 1048:efb29faf12fc 67 operator uint8_t() const; /* Disallow implicit conversion into an integer. */
vcoubard 1048:efb29faf12fc 68 operator unsigned() const; /* Disallow implicit conversion into an integer. */
rgrover1 716:11b41f651697 69 };
rgrover1 716:11b41f651697 70
rgrover1 716:11b41f651697 71 /**
rgrover1 716:11b41f651697 72 * Initiate (or continue) a read for the value attribute, optionally at a
vcoubard 1048:efb29faf12fc 73 * given offset. If the characteristic or descriptor to be read is longer
rgrover1 716:11b41f651697 74 * than ATT_MTU - 1, this function must be called multiple times with
rgrover1 716:11b41f651697 75 * appropriate offset to read the complete value.
rgrover1 716:11b41f651697 76 *
vcoubard 1048:efb29faf12fc 77 * @return BLE_ERROR_NONE if a read has been initiated, or
rgrover1 716:11b41f651697 78 * BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
vcoubard 1048:efb29faf12fc 79 * BLE_STACK_BUSY if some client procedure is already in progress, or
rgrover1 716:11b41f651697 80 * BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties.
rgrover1 716:11b41f651697 81 */
rgrover1 716:11b41f651697 82 ble_error_t read(uint16_t offset = 0) const;
rgrover1 716:11b41f651697 83
rgrover1 716:11b41f651697 84 /**
rgrover1 716:11b41f651697 85 * Perform a write without response procedure.
rgrover1 716:11b41f651697 86 *
rgrover1 716:11b41f651697 87 * @param length
rgrover1 716:11b41f651697 88 * The amount of data being written.
rgrover1 716:11b41f651697 89 * @param value
rgrover1 716:11b41f651697 90 * The bytes being written.
rgrover1 716:11b41f651697 91 *
rgrover1 716:11b41f651697 92 * @note It is important to note that a write without response will generate
rgrover1 716:11b41f651697 93 * an onDataSent() callback when the packet has been transmitted. There
rgrover1 716:11b41f651697 94 * will be a BLE-stack specific limit to the number of pending
rgrover1 716:11b41f651697 95 * writeWoResponse operations; the user may want to use the onDataSent()
rgrover1 716:11b41f651697 96 * callback for flow-control.
rgrover1 716:11b41f651697 97 *
vcoubard 1048:efb29faf12fc 98 * @retval BLE_ERROR_NONE Successfully started the Write procedure, or
rgrover1 716:11b41f651697 99 * BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
vcoubard 1048:efb29faf12fc 100 * BLE_STACK_BUSY if some client procedure is already in progress, or
rgrover1 716:11b41f651697 101 * BLE_ERROR_NO_MEM if there are no available buffers left to process the request, or
rgrover1 716:11b41f651697 102 * BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties.
rgrover1 716:11b41f651697 103 */
rgrover1 716:11b41f651697 104 ble_error_t writeWoResponse(uint16_t length, const uint8_t *value) const;
rgrover1 716:11b41f651697 105
rgrover1 716:11b41f651697 106 /**
rgrover1 716:11b41f651697 107 * Initiate a GATT Characteristic Descriptor Discovery procedure for descriptors within this characteristic.
rgrover1 716:11b41f651697 108 *
vcoubard 1045:b9d15970040f 109 * @param onCharacteristicDiscovered This callback will be called every time a descriptor is discovered
vcoubard 1045:b9d15970040f 110 * @param onTermination This callback will be called when the discovery process is over.
rgrover1 716:11b41f651697 111 *
rgrover1 716:11b41f651697 112 * @return BLE_ERROR_NONE if descriptor discovery is launched successfully; else an appropriate error.
rgrover1 716:11b41f651697 113 */
vcoubard 1047:2d66d38d9ac9 114 ble_error_t discoverDescriptors(const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& onCharacteristicDiscovered,
vcoubard 1047:2d66d38d9ac9 115 const CharacteristicDescriptorDiscovery::TerminationCallback_t& onTermination) const;
rgrover1 716:11b41f651697 116
rgrover1 716:11b41f651697 117 /**
rgrover1 716:11b41f651697 118 * Perform a write procedure.
rgrover1 716:11b41f651697 119 *
rgrover1 716:11b41f651697 120 * @param length
rgrover1 716:11b41f651697 121 * The amount of data being written.
rgrover1 716:11b41f651697 122 * @param value
rgrover1 716:11b41f651697 123 * The bytes being written.
rgrover1 716:11b41f651697 124 *
rgrover1 716:11b41f651697 125 * @note It is important to note that a write will generate
rgrover1 716:11b41f651697 126 * an onDataWritten() callback when the peer acknowledges the request.
rgrover1 716:11b41f651697 127 *
vcoubard 1048:efb29faf12fc 128 * @retval BLE_ERROR_NONE Successfully started the Write procedure, or
rgrover1 716:11b41f651697 129 * BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
vcoubard 1048:efb29faf12fc 130 * BLE_STACK_BUSY if some client procedure is already in progress, or
rgrover1 716:11b41f651697 131 * BLE_ERROR_NO_MEM if there are no available buffers left to process the request, or
rgrover1 716:11b41f651697 132 * BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties.
rgrover1 716:11b41f651697 133 */
rgrover1 716:11b41f651697 134 ble_error_t write(uint16_t length, const uint8_t *value) const;
rgrover1 716:11b41f651697 135
vcoubard 1042:21a86ac7f5b1 136 void setupLongUUID(UUID::LongUUIDBytes_t longUUID) {
vcoubard 1042:21a86ac7f5b1 137 uuid.setupLong(longUUID);
rgrover1 716:11b41f651697 138 }
rgrover1 716:11b41f651697 139
rgrover1 716:11b41f651697 140 public:
rgrover1 741:d6dceefb844e 141 const UUID& getUUID(void) const {
rgrover1 741:d6dceefb844e 142 return uuid;
rgrover1 716:11b41f651697 143 }
rgrover1 716:11b41f651697 144
rgrover1 716:11b41f651697 145 const Properties_t& getProperties(void) const {
rgrover1 716:11b41f651697 146 return props;
rgrover1 716:11b41f651697 147 }
rgrover1 716:11b41f651697 148
vcoubard 1045:b9d15970040f 149 GattAttribute::Handle_t getDeclHandle(void) const {
rgrover1 716:11b41f651697 150 return declHandle;
rgrover1 716:11b41f651697 151 }
vcoubard 1045:b9d15970040f 152
vcoubard 1045:b9d15970040f 153 GattAttribute::Handle_t getValueHandle(void) const {
rgrover1 716:11b41f651697 154 return valueHandle;
rgrover1 716:11b41f651697 155 }
rgrover1 716:11b41f651697 156
vcoubard 1045:b9d15970040f 157 GattAttribute::Handle_t getLastHandle(void) const {
vcoubard 1045:b9d15970040f 158 return lastHandle;
vcoubard 1045:b9d15970040f 159 }
vcoubard 1045:b9d15970040f 160
vcoubard 1046:87a2ebe45470 161 void setLastHandle(GattAttribute::Handle_t last) {
vcoubard 1046:87a2ebe45470 162 lastHandle = last;
vcoubard 1046:87a2ebe45470 163 }
vcoubard 1046:87a2ebe45470 164
vcoubard 1045:b9d15970040f 165 GattClient* getGattClient() {
vcoubard 1045:b9d15970040f 166 return gattc;
vcoubard 1045:b9d15970040f 167 }
vcoubard 1045:b9d15970040f 168
vcoubard 1045:b9d15970040f 169 const GattClient* getGattClient() const {
vcoubard 1045:b9d15970040f 170 return gattc;
vcoubard 1045:b9d15970040f 171 }
vcoubard 1045:b9d15970040f 172
vcoubard 1045:b9d15970040f 173 Gap::Handle_t getConnectionHandle() const {
vcoubard 1045:b9d15970040f 174 return connHandle;
vcoubard 1045:b9d15970040f 175 }
vcoubard 1045:b9d15970040f 176
vcoubard 1045:b9d15970040f 177 friend bool operator==(const DiscoveredCharacteristic& rhs, const DiscoveredCharacteristic& lhs) {
vcoubard 1046:87a2ebe45470 178 return rhs.gattc == lhs.gattc &&
vcoubard 1045:b9d15970040f 179 rhs.uuid == lhs.uuid &&
vcoubard 1046:87a2ebe45470 180 rhs.props == lhs.props &&
vcoubard 1045:b9d15970040f 181 rhs.declHandle == lhs.declHandle &&
vcoubard 1045:b9d15970040f 182 rhs.valueHandle == lhs.valueHandle &&
vcoubard 1045:b9d15970040f 183 rhs.lastHandle == lhs.lastHandle &&
vcoubard 1045:b9d15970040f 184 rhs.connHandle == lhs.connHandle;
vcoubard 1045:b9d15970040f 185 }
vcoubard 1045:b9d15970040f 186
vcoubard 1046:87a2ebe45470 187 friend bool operator !=(const DiscoveredCharacteristic& rhs, const DiscoveredCharacteristic& lhs) {
vcoubard 1046:87a2ebe45470 188 return !(rhs == lhs);
vcoubard 1046:87a2ebe45470 189 }
vcoubard 1046:87a2ebe45470 190
rgrover1 716:11b41f651697 191 public:
rgrover1 716:11b41f651697 192 DiscoveredCharacteristic() : gattc(NULL),
rgrover1 716:11b41f651697 193 uuid(UUID::ShortUUIDBytes_t(0)),
rgrover1 716:11b41f651697 194 props(),
rgrover1 716:11b41f651697 195 declHandle(GattAttribute::INVALID_HANDLE),
vcoubard 1045:b9d15970040f 196 valueHandle(GattAttribute::INVALID_HANDLE),
vcoubard 1046:87a2ebe45470 197 lastHandle(GattAttribute::INVALID_HANDLE),
vcoubard 1046:87a2ebe45470 198 connHandle() {
rgrover1 716:11b41f651697 199 /* empty */
rgrover1 716:11b41f651697 200 }
rgrover1 716:11b41f651697 201
rgrover1 716:11b41f651697 202 protected:
rgrover1 716:11b41f651697 203 GattClient *gattc;
rgrover1 716:11b41f651697 204
rgrover1 716:11b41f651697 205 protected:
rgrover1 716:11b41f651697 206 UUID uuid;
rgrover1 716:11b41f651697 207 Properties_t props;
rgrover1 716:11b41f651697 208 GattAttribute::Handle_t declHandle;
rgrover1 716:11b41f651697 209 GattAttribute::Handle_t valueHandle;
vcoubard 1045:b9d15970040f 210 GattAttribute::Handle_t lastHandle;
rgrover1 716:11b41f651697 211
rgrover1 716:11b41f651697 212 Gap::Handle_t connHandle;
rgrover1 716:11b41f651697 213 };
rgrover1 716:11b41f651697 214
rgrover1 716:11b41f651697 215 #endif /*__DISCOVERED_CHARACTERISTIC_H__*/