Skip to content

Commit d80fec8

Browse files
author
Rohit Grover
committed
Release 0.4.0
============= This is a major release which introduces the GATT Client functionality. It also aligns BLE_API with builds using our new package manager: yotta (https://github.com/armmbed/yotta). Many APIs have seen some redesign. We encourage our users to pay attention to the changes and migrate appropriately over time. We've also taken care to ensure that existing code continues to work the same way. There's more documentation in the form of comment headers for APIs to explain proper usage; in many cases comment headers suggest alternative use of APIs. Enhancements ~~~~~~~~~~~~ * Introduce GattClient. This includes functionality for service-discovery, connections, and attribute-reads and writes. You'll find a demo program for LEDBlinker on the mbed.org Bluetooth team page to use the new APIs. Some of the GATT client functionality hasn't been implemented yet, but the APIs have been added. * Most APIs in the abstract base classes like Gap and GattServer return BLE_ERROR_NOT_IMPLEMENTED. Previously many APIs were pure-virtual, which did not permit partial ports to compile. * We've added a new abstract base class for SecurityManager. All security related APIs have been moved into that. * BLEDevice has been renamed as BLE. A deprecated alias for BLEDevice is available to support existing code. * There has been a major cleanup of APIs under BLE. APIs have now been categorized as belonging to Gap, GattServer, GattClient, or SecurityManager. There are accessors to get references for Gap, GattServer, GattClient, and SecurityManager. A former call to ble.setAddress(...) is now expected to be achieved with ble.gap().setAddress(...). * We've cleaned up our APIs, and this has resulted in dropping some APIs like BLE::reset(). * We've also dropped GattServer::initializeGattDatabase(). THis was added at some point to support controllers where a commit point was needed to indicate when the application had finished constructing the GATT database. This API would get called internally before Gap::startAdvertising(). We now expect the underlying port to do the equivalent of initializeGattDatabase() implicitly upon Gap::startAdvertising(). * The callback for BLE.onTimeout() now receives a TimeoutSource_t to indicate the cause of the timeout. This is perhaps the only breaking API change. We expect it to have very little disruptive effect. * We've added a version of Gap::disconnect() which takes a connection handle. The previous API (which did not take a connection handle) has been deprecated; it will still work for situations where there's only a single active connection. We hold on to that API to allow existing code to migrate to the new API. Bugfixes ~~~~~~~~ * None.
2 parents 6972654 + 75beb80 commit d80fec8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3853
-1989
lines changed

ble/BLE.h

Lines changed: 1342 additions & 0 deletions
Large diffs are not rendered by default.

common/BLEDeviceInstanceBase.h renamed to ble/BLEInstanceBase.h

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,40 @@
1717
#ifndef __BLE_DEVICE_INSTANCE_BASE__
1818
#define __BLE_DEVICE_INSTANCE_BASE__
1919

20+
#include "Gap.h"
21+
22+
/* forward declarations */
23+
class GattServer;
24+
class GattClient;
25+
2026
/**
2127
* The interface for the transport object to be created by the target library's
22-
* createBLEDeviceInstance().
28+
* createBLEInstance().
2329
*/
24-
class BLEDeviceInstanceBase
30+
class BLEInstanceBase
2531
{
2632
public:
27-
virtual const char *getVersion(void) = 0;
28-
virtual Gap& getGap() = 0;
29-
virtual GattServer& getGattServer() = 0;
30-
virtual ble_error_t init(void) = 0;
31-
virtual ble_error_t shutdown(void) = 0;
32-
virtual ble_error_t reset(void) = 0;
33-
virtual ble_error_t initializeSecurity(bool enableBonding = true,
34-
bool requireMITM = true,
35-
Gap::SecurityIOCapabilities_t iocaps = Gap::IO_CAPS_NONE,
36-
const Gap::Passkey_t passkey = NULL) = 0;
37-
virtual ble_error_t setTxPower(int8_t txPower) = 0;
38-
virtual void getPermittedTxPowerValues(const int8_t **, size_t *) = 0;
33+
virtual ble_error_t init(void) = 0;
34+
virtual ble_error_t shutdown(void) = 0;
35+
virtual const char *getVersion(void) = 0;
36+
virtual Gap& getGap() = 0;
37+
virtual const Gap& getGap() const = 0;
38+
virtual GattServer& getGattServer() = 0;
39+
virtual const GattServer& getGattServer() const = 0;
40+
virtual GattClient& getGattClient() = 0;
41+
virtual SecurityManager& getSecurityManager() = 0;
42+
virtual const SecurityManager& getSecurityManager() const = 0;
3943
virtual void waitForEvent(void) = 0;
4044
};
4145

4246
/**
43-
* BLEDevice uses composition to hide an interface object encapsulating the
47+
* BLE uses composition to hide an interface object encapsulating the
4448
* backend transport.
4549
*
4650
* The following API is used to create the singleton interface object. An
4751
* implementation for this function must be provided by the device-specific
4852
* library, otherwise there will be a linker error.
4953
*/
50-
extern BLEDeviceInstanceBase *createBLEDeviceInstance(void);
54+
extern BLEInstanceBase *createBLEInstance(void);
5155

5256
#endif // ifndef __BLE_DEVICE_INSTANCE_BASE__

ble/DiscoveredCharacteristic.h

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2006-2013 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef __DISCOVERED_CHARACTERISTIC_H__
18+
#define __DISCOVERED_CHARACTERISTIC_H__
19+
20+
#include "UUID.h"
21+
#include "Gap.h"
22+
#include "GattAttribute.h"
23+
#include "GattClient.h"
24+
25+
/**
26+
* Structure for holding information about the service and the characteristics
27+
* found during the discovery process.
28+
*/
29+
class DiscoveredCharacteristic {
30+
public:
31+
struct Properties_t {
32+
uint8_t _broadcast :1; /**< Broadcasting of the value permitted. */
33+
uint8_t _read :1; /**< Reading the value permitted. */
34+
uint8_t _writeWoResp :1; /**< Writing the value with Write Command permitted. */
35+
uint8_t _write :1; /**< Writing the value with Write Request permitted. */
36+
uint8_t _notify :1; /**< Notications of the value permitted. */
37+
uint8_t _indicate :1; /**< Indications of the value permitted. */
38+
uint8_t _authSignedWrite :1; /**< Writing the value with Signed Write Command permitted. */
39+
40+
public:
41+
bool broadcast(void) const {return _broadcast; }
42+
bool read(void) const {return _read; }
43+
bool writeWoResp(void) const {return _writeWoResp; }
44+
bool write(void) const {return _write; }
45+
bool notify(void) const {return _notify; }
46+
bool indicate(void) const {return _indicate; }
47+
bool authSignedWrite(void) const {return _authSignedWrite;}
48+
49+
private:
50+
operator uint8_t() const; /* disallow implicit conversion into an integer */
51+
operator unsigned() const; /* disallow implicit conversion into an integer */
52+
};
53+
54+
/**
55+
* Structure for holding information about the service and the characteristics
56+
* found during the discovery process.
57+
*/
58+
struct DiscoveredDescriptor {
59+
GattAttribute::Handle_t handle; /**< Descriptor Handle. */
60+
UUID uuid; /**< Descriptor UUID. */
61+
};
62+
63+
/**
64+
* Callback type for when a characteristic descriptor is found during descriptor-
65+
* discovery. The receiving function is passed in a pointer to a
66+
* DiscoveredDescriptor object which will remain valid for the lifetime
67+
* of the callback. Memory for this object is owned by the BLE_API eventing
68+
* framework. The application can safely make a persistent shallow-copy of
69+
* this object in order to work with the characteristic beyond the callback.
70+
*/
71+
typedef void (*DescriptorCallback_t)(const DiscoveredDescriptor *);
72+
73+
/**
74+
* Initiate (or continue) a read for the value attribute, optionally at a
75+
* given offset. If the Characteristic or Descriptor to be read is longer
76+
* than ATT_MTU - 1, this function must be called multiple times with
77+
* appropriate offset to read the complete value.
78+
*
79+
* @return BLE_ERROR_NONE if a read has been initiated, else
80+
* BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
81+
* BLE_STACK_BUSY if some client procedure already in progress, or
82+
* BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties.
83+
*/
84+
ble_error_t read(uint16_t offset = 0) const;
85+
86+
/**
87+
* Perform a write without response procedure.
88+
*
89+
* @param length
90+
* The amount of data being written.
91+
* @param value
92+
* The bytes being written.
93+
*
94+
* @note It is important to note that a write without response will generate
95+
* an onDataSent() callback when the packet has been transmitted. There
96+
* will be a BLE-stack specific limit to the number of pending
97+
* writeWoResponse operations; the user may want to use the onDataSent()
98+
* callback for flow-control.
99+
*
100+
* @retval BLE_ERROR_NONE Successfully started the Write procedure, else
101+
* BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
102+
* BLE_STACK_BUSY if some client procedure already in progress, or
103+
* BLE_ERROR_NO_MEM if there are no available buffers left to process the request, or
104+
* BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties.
105+
*/
106+
ble_error_t writeWoResponse(uint16_t length, const uint8_t *value) const;
107+
108+
/**
109+
* Initiate a GATT Characteristic Descriptor Discovery procedure for descriptors within this characteristic.
110+
*
111+
* @param callback
112+
* @param matchingUUID
113+
* filter for descriptors. Defaults to wildcard which will discover all descriptors.
114+
*
115+
* @return BLE_ERROR_NONE if descriptor discovery is launched successfully; else an appropriate error.
116+
*/
117+
ble_error_t discoverDescriptors(DescriptorCallback_t callback, const UUID &matchingUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) const;
118+
119+
/**
120+
* Perform a write procedure.
121+
*
122+
* @param length
123+
* The amount of data being written.
124+
* @param value
125+
* The bytes being written.
126+
*
127+
* @note It is important to note that a write will generate
128+
* an onDataWritten() callback when the peer acknowledges the request.
129+
*
130+
* @retval BLE_ERROR_NONE Successfully started the Write procedure, else
131+
* BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
132+
* BLE_STACK_BUSY if some client procedure already in progress, or
133+
* BLE_ERROR_NO_MEM if there are no available buffers left to process the request, or
134+
* BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties.
135+
*/
136+
ble_error_t write(uint16_t length, const uint8_t *value) const;
137+
138+
static void setupOnDataRead(GattClient::ReadCallback_t callback) {
139+
onDataReadCallback = callback;
140+
}
141+
142+
static void setupOnDataWrite(GattClient::WriteCallback_t callback) {
143+
onDataWriteCallback = callback;
144+
}
145+
146+
void setupLongUUID(UUID::LongUUIDBytes_t longUUID) {
147+
uuid.setupLong(longUUID);
148+
}
149+
150+
public:
151+
UUID::ShortUUIDBytes_t getShortUUID(void) const {
152+
return uuid.getShortUUID();
153+
}
154+
155+
const Properties_t& getProperties(void) const {
156+
return props;
157+
}
158+
159+
const GattAttribute::Handle_t& getDeclHandle(void) const {
160+
return declHandle;
161+
}
162+
const GattAttribute::Handle_t& getValueHandle(void) const {
163+
return valueHandle;
164+
}
165+
166+
public:
167+
DiscoveredCharacteristic() : gattc(NULL),
168+
uuid(UUID::ShortUUIDBytes_t(0)),
169+
props(),
170+
declHandle(GattAttribute::INVALID_HANDLE),
171+
valueHandle(GattAttribute::INVALID_HANDLE) {
172+
/* empty */
173+
}
174+
175+
protected:
176+
GattClient *gattc;
177+
178+
protected:
179+
UUID uuid;
180+
Properties_t props;
181+
GattAttribute::Handle_t declHandle;
182+
GattAttribute::Handle_t valueHandle;
183+
184+
Gap::Handle_t connHandle;
185+
186+
public:
187+
static GattClient::ReadCallback_t onDataReadCallback;
188+
static GattClient::WriteCallback_t onDataWriteCallback;
189+
};
190+
191+
#endif /*__DISCOVERED_CHARACTERISTIC_H__*/

ble/DiscoveredService.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2006-2013 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef __DISCOVERED_SERVICE_H__
18+
#define __DISCOVERED_SERVICE_H__
19+
20+
#include "UUID.h"
21+
#include "GattAttribute.h"
22+
23+
/**@brief Type for holding information about the service and the characteristics found during
24+
* the discovery process.
25+
*/
26+
class DiscoveredService {
27+
public:
28+
void setup(UUID uuidIn, GattAttribute::Handle_t startHandleIn, GattAttribute::Handle_t endHandleIn) {
29+
uuid = uuidIn;
30+
startHandle = startHandleIn;
31+
endHandle = endHandleIn;
32+
}
33+
34+
void setup(GattAttribute::Handle_t startHandleIn, GattAttribute::Handle_t endHandleIn) {
35+
startHandle = startHandleIn;
36+
endHandle = endHandleIn;
37+
}
38+
39+
void setupLongUUID(UUID::LongUUIDBytes_t longUUID) {
40+
uuid.setupLong(longUUID);
41+
}
42+
43+
public:
44+
const UUID &getUUID(void) const {
45+
return uuid;
46+
}
47+
48+
const GattAttribute::Handle_t& getStartHandle(void) const {
49+
return startHandle;
50+
}
51+
const GattAttribute::Handle_t& getEndHandle(void) const {
52+
return endHandle;
53+
}
54+
55+
public:
56+
DiscoveredService() : uuid(UUID::ShortUUIDBytes_t(0)),
57+
startHandle(GattAttribute::INVALID_HANDLE),
58+
endHandle(GattAttribute::INVALID_HANDLE) {
59+
/* empty */
60+
}
61+
62+
private:
63+
DiscoveredService(const DiscoveredService &);
64+
65+
private:
66+
UUID uuid; /**< UUID of the service. */
67+
GattAttribute::Handle_t startHandle; /**< Service Handle Range. */
68+
GattAttribute::Handle_t endHandle; /**< Service Handle Range. */
69+
};
70+
71+
#endif /*__DISCOVERED_SERVICE_H__*/

0 commit comments

Comments
 (0)