Skip to content

Commit daaa5b1

Browse files
committed
BLE: Introduce GenericGattClient and platform abstraction over ATT/GATT.
This changes introduce a platform adaptation over ATT/GATT that can be implemented by porter. Unlike the GattClient interface, the ATT/GATT adaptation is simple, follow closely the Bluetooth specification and won't change over time. Implementation of the GattClient interface is realized by the class GenericGattClient which accept in input a pal::GattClient. This change will also free design space once adopted by partners, addition to the GattClient interface won't require partner support.
1 parent 38bb6b4 commit daaa5b1

File tree

7 files changed

+4126
-0
lines changed

7 files changed

+4126
-0
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017-2017 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 MBED_BLE_GENERIC_GATT_CLIENT
18+
#define MBED_BLE_GENERIC_GATT_CLIENT
19+
20+
#include <algorithm>
21+
#include "ble/GattClient.h"
22+
#include "ble/pal/PalGattClient.h"
23+
24+
// IMPORTANT: private header. Not part of the public interface.
25+
26+
namespace ble {
27+
namespace generic {
28+
29+
// forward declarations
30+
struct procedure_control_block_t;
31+
struct discovery_control_block_t;
32+
struct read_control_block_t;
33+
struct write_control_block_t;
34+
struct descriptor_discovery_control_block_t;
35+
36+
/**
37+
* Generic implementation of the GattClient.
38+
* It requires a pal::GattClient injected at construction site.
39+
* @important: Not part of the public interface of BLE API.
40+
*/
41+
class GenericGattClient : public GattClient {
42+
43+
// give access to control block classes
44+
friend struct procedure_control_block_t;
45+
friend struct discovery_control_block_t;
46+
friend struct read_control_block_t;
47+
friend struct write_control_block_t;
48+
friend struct descriptor_discovery_control_block_t;
49+
50+
public:
51+
/**
52+
* Create a GenericGattClient from a pal::GattClient
53+
*/
54+
GenericGattClient(pal::GattClient* pal_client);
55+
56+
/**
57+
* @see GattClient::launchServiceDiscovery
58+
*/
59+
virtual ble_error_t launchServiceDiscovery(
60+
Gap::Handle_t connection_handle,
61+
ServiceDiscovery::ServiceCallback_t service_callback,
62+
ServiceDiscovery::CharacteristicCallback_t characteristic_callback,
63+
const UUID& matching_service_uuid,
64+
const UUID& matching_characteristic_uuid
65+
);
66+
67+
/**
68+
* @see GattClient::isServiceDiscoveryActive
69+
*/
70+
virtual bool isServiceDiscoveryActive() const;
71+
72+
/**
73+
* @see GattClient::terminateServiceDiscovery
74+
*/
75+
virtual void terminateServiceDiscovery();
76+
77+
/**
78+
* @see GattClient::read
79+
*/
80+
virtual ble_error_t read(
81+
Gap::Handle_t connection_handle,
82+
GattAttribute::Handle_t attribute_handle,
83+
uint16_t offset
84+
) const;
85+
86+
/**
87+
* @see GattClient::write
88+
*/
89+
virtual ble_error_t write(
90+
GattClient::WriteOp_t cmd,
91+
Gap::Handle_t connection_handle,
92+
GattAttribute::Handle_t attribute_handle,
93+
size_t length,
94+
const uint8_t* value
95+
) const;
96+
97+
/**
98+
* @see GattClient::onServiceDiscoveryTermination
99+
*/
100+
virtual void onServiceDiscoveryTermination(
101+
ServiceDiscovery::TerminationCallback_t callback
102+
);
103+
104+
/**
105+
* @see GattClient::discoverCharacteristicDescriptors
106+
*/
107+
virtual ble_error_t discoverCharacteristicDescriptors(
108+
const DiscoveredCharacteristic& characteristic,
109+
const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
110+
const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback
111+
);
112+
113+
/**
114+
* @see GattClient::isCharacteristicDescriptorDiscoveryActive
115+
*/
116+
virtual bool isCharacteristicDescriptorDiscoveryActive(
117+
const DiscoveredCharacteristic& characteristic
118+
) const;
119+
120+
/**
121+
* @see GattClient::terminateCharacteristicDescriptorDiscovery
122+
*/
123+
virtual void terminateCharacteristicDescriptorDiscovery(
124+
const DiscoveredCharacteristic& characteristic
125+
);
126+
127+
/**
128+
* @see GattClient::reset
129+
*/
130+
virtual ble_error_t reset(void);
131+
132+
private:
133+
procedure_control_block_t* get_control_block(Gap::Handle_t connection);
134+
const procedure_control_block_t* get_control_block(Gap::Handle_t connection) const;
135+
void insert_control_block(procedure_control_block_t* cb) const;
136+
void remove_control_block(procedure_control_block_t* cb) const;
137+
138+
void on_termination(Gap::Handle_t connection_handle);
139+
void on_server_message_received(connection_handle_t, const pal::AttServerMessage&);
140+
void on_server_response(connection_handle_t, const pal::AttServerMessage&);
141+
void on_server_event(connection_handle_t, const pal::AttServerMessage&);
142+
void on_transaction_timeout(connection_handle_t);
143+
144+
uint16_t get_mtu(Gap::Handle_t connection) const;
145+
146+
pal::GattClient* const _pal_client;
147+
ServiceDiscovery::TerminationCallback_t _termination_callback;
148+
mutable procedure_control_block_t* control_blocks;
149+
};
150+
151+
}
152+
}
153+
154+
#endif /* MBED_BLE_GENERIC_GATT_CLIENT */

0 commit comments

Comments
 (0)