fork BLE_API to add update adv payload API

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Jun 19 15:51:59 2015 +0100
Revision:
469:c95e603d60dd
Parent:
468:bbf2a395bb8d
Child:
470:150c2363f776
Synchronized with git rev b4ccb331
Author: Rohit Grover
introduce ReadResponse_t to DiscoveredCharacteristic

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 431:1c8c592430ec 1 /* mbed Microcontroller Library
rgrover1 431:1c8c592430ec 2 * Copyright (c) 2006-2013 ARM Limited
rgrover1 431:1c8c592430ec 3 *
rgrover1 431:1c8c592430ec 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 431:1c8c592430ec 5 * you may not use this file except in compliance with the License.
rgrover1 431:1c8c592430ec 6 * You may obtain a copy of the License at
rgrover1 431:1c8c592430ec 7 *
rgrover1 431:1c8c592430ec 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 431:1c8c592430ec 9 *
rgrover1 431:1c8c592430ec 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 431:1c8c592430ec 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 431:1c8c592430ec 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 431:1c8c592430ec 13 * See the License for the specific language governing permissions and
rgrover1 431:1c8c592430ec 14 * limitations under the License.
rgrover1 431:1c8c592430ec 15 */
rgrover1 431:1c8c592430ec 16
rgrover1 431:1c8c592430ec 17 #ifndef __SERVICE_DISOVERY_H__
rgrover1 431:1c8c592430ec 18 #define __SERVICE_DISOVERY_H__
rgrover1 431:1c8c592430ec 19
rgrover1 431:1c8c592430ec 20 #include "UUID.h"
rgrover1 431:1c8c592430ec 21 #include "Gap.h"
rgrover1 438:b55ce5f5715d 22 #include "GattAttribute.h"
rgrover1 431:1c8c592430ec 23
rgrover1 431:1c8c592430ec 24 class ServiceDiscovery {
rgrover1 431:1c8c592430ec 25 public:
rgrover1 439:c57413bf88a9 26 /**@brief Type for holding information about the service and the characteristics found during
rgrover1 431:1c8c592430ec 27 * the discovery process.
rgrover1 431:1c8c592430ec 28 */
rgrover1 439:c57413bf88a9 29 class DiscoveredService {
rgrover1 439:c57413bf88a9 30 public:
rgrover1 459:a83b41d87755 31 void setup(UUID uuidIn, GattAttribute::Handle_t startHandleIn, GattAttribute::Handle_t endHandleIn) {
rgrover1 431:1c8c592430ec 32 uuid = uuidIn;
rgrover1 439:c57413bf88a9 33 startHandle = startHandleIn;
rgrover1 439:c57413bf88a9 34 endHandle = endHandleIn;
rgrover1 439:c57413bf88a9 35 }
rgrover1 439:c57413bf88a9 36
rgrover1 465:8c4c61279f82 37 void setup(GattAttribute::Handle_t startHandleIn, GattAttribute::Handle_t endHandleIn) {
rgrover1 465:8c4c61279f82 38 startHandle = startHandleIn;
rgrover1 465:8c4c61279f82 39 endHandle = endHandleIn;
rgrover1 465:8c4c61279f82 40 }
rgrover1 465:8c4c61279f82 41
rgrover1 465:8c4c61279f82 42 void setupLongUUID(UUID::LongUUIDBytes_t longUUID) {
rgrover1 465:8c4c61279f82 43 uuid.setupLong(longUUID);
rgrover1 465:8c4c61279f82 44 }
rgrover1 465:8c4c61279f82 45
rgrover1 439:c57413bf88a9 46 public:
rgrover1 466:5c2cb68e7c3b 47 const UUID &getUUID(void) const {
rgrover1 466:5c2cb68e7c3b 48 return uuid;
rgrover1 431:1c8c592430ec 49 }
rgrover1 431:1c8c592430ec 50
rgrover1 439:c57413bf88a9 51 const GattAttribute::Handle_t& getStartHandle(void) const {
rgrover1 439:c57413bf88a9 52 return startHandle;
rgrover1 439:c57413bf88a9 53 }
rgrover1 439:c57413bf88a9 54 const GattAttribute::Handle_t& getEndHandle(void) const {
rgrover1 439:c57413bf88a9 55 return endHandle;
rgrover1 439:c57413bf88a9 56 }
rgrover1 439:c57413bf88a9 57
rgrover1 439:c57413bf88a9 58 public:
rgrover1 461:a636b8ee72f1 59 DiscoveredService() : uuid(UUID::ShortUUIDBytes_t(0)),
rgrover1 461:a636b8ee72f1 60 startHandle(GattAttribute::INVALID_HANDLE),
rgrover1 461:a636b8ee72f1 61 endHandle(GattAttribute::INVALID_HANDLE) {
rgrover1 439:c57413bf88a9 62 /* empty */
rgrover1 439:c57413bf88a9 63 }
rgrover1 439:c57413bf88a9 64
rgrover1 439:c57413bf88a9 65 private:
rgrover1 439:c57413bf88a9 66 DiscoveredService(const DiscoveredService &);
rgrover1 439:c57413bf88a9 67
rgrover1 439:c57413bf88a9 68 private:
rgrover1 459:a83b41d87755 69 UUID uuid; /**< UUID of the service. */
rgrover1 438:b55ce5f5715d 70 GattAttribute::Handle_t startHandle; /**< Service Handle Range. */
rgrover1 438:b55ce5f5715d 71 GattAttribute::Handle_t endHandle; /**< Service Handle Range. */
rgrover1 431:1c8c592430ec 72 };
rgrover1 431:1c8c592430ec 73
rgrover1 431:1c8c592430ec 74 /**@brief Structure for holding information about the service and the characteristics found during
rgrover1 431:1c8c592430ec 75 * the discovery process.
rgrover1 431:1c8c592430ec 76 */
rgrover1 440:21c83c010895 77 class DiscoveredCharacteristic {
rgrover1 440:21c83c010895 78 public:
rgrover1 431:1c8c592430ec 79 struct Properties_t {
rgrover1 431:1c8c592430ec 80 static const uint8_t BROADCAST_PROPERTY_MASK = 0x01;
rgrover1 431:1c8c592430ec 81 static const uint8_t READ_PROPERTY_MASK = 0x02;
rgrover1 431:1c8c592430ec 82 static const uint8_t WRITE_WO_RESPONSE_PROPERTY_MASK = 0x04;
rgrover1 431:1c8c592430ec 83 static const uint8_t WRITE_PROPERTY_MASK = 0x08;
rgrover1 431:1c8c592430ec 84 static const uint8_t NOTIFY_PROPERTY_MASK = 0x10;
rgrover1 431:1c8c592430ec 85 static const uint8_t INDICATE_PROPERTY_MASK = 0x20;
rgrover1 431:1c8c592430ec 86 static const uint8_t AUTH_SIGNED_PROPERTY_MASK = 0x40;
rgrover1 431:1c8c592430ec 87
rgrover1 431:1c8c592430ec 88 Properties_t() : broadcast(0), read(0), write_wo_resp(0), write(0), notify(0), indicate(0), auth_signed_wr(0) {
rgrover1 431:1c8c592430ec 89 /* empty */
rgrover1 431:1c8c592430ec 90 }
rgrover1 431:1c8c592430ec 91
rgrover1 431:1c8c592430ec 92 Properties_t(uint8_t props) :
rgrover1 431:1c8c592430ec 93 broadcast(props & BROADCAST_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 94 read(props & READ_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 95 write_wo_resp(props & WRITE_WO_RESPONSE_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 96 write(props & WRITE_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 97 notify(props & NOTIFY_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 98 indicate(props & INDICATE_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 99 auth_signed_wr(props & AUTH_SIGNED_PROPERTY_MASK) {
rgrover1 431:1c8c592430ec 100 /* empty*/
rgrover1 431:1c8c592430ec 101 }
rgrover1 431:1c8c592430ec 102
rgrover1 431:1c8c592430ec 103 uint8_t broadcast :1; /**< Broadcasting of the value permitted. */
rgrover1 431:1c8c592430ec 104 uint8_t read :1; /**< Reading the value permitted. */
rgrover1 431:1c8c592430ec 105 uint8_t write_wo_resp :1; /**< Writing the value with Write Command permitted. */
rgrover1 431:1c8c592430ec 106 uint8_t write :1; /**< Writing the value with Write Request permitted. */
rgrover1 431:1c8c592430ec 107 uint8_t notify :1; /**< Notications of the value permitted. */
rgrover1 431:1c8c592430ec 108 uint8_t indicate :1; /**< Indications of the value permitted. */
rgrover1 431:1c8c592430ec 109 uint8_t auth_signed_wr :1; /**< Writing the value with Signed Write Command permitted. */
rgrover1 431:1c8c592430ec 110 };
rgrover1 431:1c8c592430ec 111
rgrover1 469:c95e603d60dd 112 struct ReadResponse_t {
rgrover1 469:c95e603d60dd 113 GattAttribute::Handle_t handle; /**< Attribute Handle. */
rgrover1 469:c95e603d60dd 114 uint16_t offset; /**< Offset of the attribute data. */
rgrover1 469:c95e603d60dd 115 uint16_t len; /**< Attribute data length. */
rgrover1 469:c95e603d60dd 116 const uint8_t *data; /**< Attribute data, variable length. */
rgrover1 469:c95e603d60dd 117 };
rgrover1 469:c95e603d60dd 118 typedef void (*ReadCallback_t)(const ReadResponse_t *params);
rgrover1 469:c95e603d60dd 119
rgrover1 469:c95e603d60dd 120 static void setupOnDataRead(ReadCallback_t callback) {
rgrover1 469:c95e603d60dd 121 onDataReadCallback = callback;
rgrover1 469:c95e603d60dd 122 }
rgrover1 469:c95e603d60dd 123
rgrover1 468:bbf2a395bb8d 124 public:
rgrover1 467:143ca3152ffa 125 void setup(Properties_t propsIn,
rgrover1 467:143ca3152ffa 126 GattAttribute::Handle_t declHandleIn,
rgrover1 467:143ca3152ffa 127 GattAttribute::Handle_t valueHandleIn) {
rgrover1 467:143ca3152ffa 128 props = propsIn;
rgrover1 467:143ca3152ffa 129 declHandle = declHandleIn;
rgrover1 467:143ca3152ffa 130 valueHandle = valueHandleIn;
rgrover1 467:143ca3152ffa 131 }
rgrover1 467:143ca3152ffa 132
rgrover1 461:a636b8ee72f1 133 void setup(UUID::ShortUUIDBytes_t uuidIn,
rgrover1 461:a636b8ee72f1 134 Properties_t propsIn,
rgrover1 461:a636b8ee72f1 135 GattAttribute::Handle_t declHandleIn,
rgrover1 461:a636b8ee72f1 136 GattAttribute::Handle_t valueHandleIn) {
rgrover1 431:1c8c592430ec 137 uuid = uuidIn;
rgrover1 431:1c8c592430ec 138 props = propsIn;
rgrover1 431:1c8c592430ec 139 declHandle = declHandleIn;
rgrover1 431:1c8c592430ec 140 valueHandle = valueHandleIn;
rgrover1 431:1c8c592430ec 141 }
rgrover1 431:1c8c592430ec 142
rgrover1 467:143ca3152ffa 143 void setupLongUUID(UUID::LongUUIDBytes_t longUUID) {
rgrover1 467:143ca3152ffa 144 uuid.setupLong(longUUID);
rgrover1 467:143ca3152ffa 145 }
rgrover1 467:143ca3152ffa 146
rgrover1 440:21c83c010895 147 public:
rgrover1 460:f5468aee162d 148 UUID::ShortUUIDBytes_t getShortUUID(void) const {
rgrover1 460:f5468aee162d 149 return uuid.getShortUUID();
rgrover1 440:21c83c010895 150 }
rgrover1 440:21c83c010895 151
rgrover1 440:21c83c010895 152 const Properties_t& getProperties(void) const {
rgrover1 440:21c83c010895 153 return props;
rgrover1 440:21c83c010895 154 }
rgrover1 440:21c83c010895 155
rgrover1 440:21c83c010895 156 const GattAttribute::Handle_t& getDeclHandle(void) const {
rgrover1 440:21c83c010895 157 return declHandle;
rgrover1 440:21c83c010895 158 }
rgrover1 440:21c83c010895 159 const GattAttribute::Handle_t& getValueHandle(void) const {
rgrover1 440:21c83c010895 160 return valueHandle;
rgrover1 440:21c83c010895 161 }
rgrover1 440:21c83c010895 162
rgrover1 440:21c83c010895 163 public:
rgrover1 461:a636b8ee72f1 164 DiscoveredCharacteristic() : uuid(UUID::ShortUUIDBytes_t(0)),
rgrover1 461:a636b8ee72f1 165 props(),
rgrover1 461:a636b8ee72f1 166 declHandle(GattAttribute::INVALID_HANDLE),
rgrover1 461:a636b8ee72f1 167 valueHandle(GattAttribute::INVALID_HANDLE) {
rgrover1 440:21c83c010895 168 /* empty */
rgrover1 440:21c83c010895 169 }
rgrover1 440:21c83c010895 170
rgrover1 440:21c83c010895 171 private:
rgrover1 460:f5468aee162d 172 UUID uuid;
rgrover1 438:b55ce5f5715d 173 Properties_t props;
rgrover1 438:b55ce5f5715d 174 GattAttribute::Handle_t declHandle;
rgrover1 438:b55ce5f5715d 175 GattAttribute::Handle_t valueHandle;
rgrover1 469:c95e603d60dd 176
rgrover1 469:c95e603d60dd 177 static ReadCallback_t onDataReadCallback;
rgrover1 431:1c8c592430ec 178 };
rgrover1 431:1c8c592430ec 179
rgrover1 431:1c8c592430ec 180 public:
rgrover1 431:1c8c592430ec 181 typedef void (*ServiceCallback_t)(const DiscoveredService &);
rgrover1 431:1c8c592430ec 182 typedef void (*CharacteristicCallback_t)(const DiscoveredCharacteristic &);
rgrover1 457:6ebc9bbde90b 183 typedef void (*TerminationCallback_t)(Gap::Handle_t connectionHandle);
rgrover1 431:1c8c592430ec 184
rgrover1 431:1c8c592430ec 185 public:
rgrover1 456:ff4ffb69e19f 186 static ble_error_t launch(Gap::Handle_t connectionHandle,
rgrover1 456:ff4ffb69e19f 187 ServiceCallback_t sc = NULL,
rgrover1 456:ff4ffb69e19f 188 CharacteristicCallback_t cc = NULL,
rgrover1 458:5546ebd25359 189 const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
rgrover1 458:5546ebd25359 190 const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN));
rgrover1 431:1c8c592430ec 191
rgrover1 431:1c8c592430ec 192 static void terminate(void);
rgrover1 431:1c8c592430ec 193
rgrover1 457:6ebc9bbde90b 194 static bool isActive(void);
rgrover1 457:6ebc9bbde90b 195 static void onTermination(TerminationCallback_t callback);
rgrover1 457:6ebc9bbde90b 196
rgrover1 431:1c8c592430ec 197 protected:
rgrover1 431:1c8c592430ec 198 Gap::Handle_t connHandle; /**< Connection handle as provided by the SoftDevice. */
rgrover1 431:1c8c592430ec 199 UUID matchingServiceUUID;
rgrover1 431:1c8c592430ec 200 ServiceCallback_t serviceCallback;
rgrover1 431:1c8c592430ec 201 UUID matchingCharacteristicUUID;
rgrover1 431:1c8c592430ec 202 CharacteristicCallback_t characteristicCallback;
rgrover1 431:1c8c592430ec 203 };
rgrover1 431:1c8c592430ec 204
rgrover1 431:1c8c592430ec 205 #endif // ifndef __SERVICE_DISOVERY_H__