17
17
*/
18
18
19
19
#include < algorithm>
20
- #include < stdint.h >
20
+ #include < cstdint >
21
21
22
- #include " GapImpl.h"
23
- #include " ble/Gap.h"
24
- #include " source/BLEInstanceBase.h"
25
22
#include " ble/Gap.h"
26
23
#include " ble/SecurityManager.h"
24
+
25
+ #include " source/BLEInstanceBase.h"
26
+ #include " source/generic/GapImpl.h"
27
+
27
28
#include " source/pal/PalGap.h"
28
29
#include " source/pal/GapEvents.h"
29
30
#include " source/pal/GapTypes.h"
30
31
#include " source/pal/PalGenericAccessService.h"
31
32
#include " source/pal/PalEventQueue.h"
32
- #include " source/pal/PalGap.h"
33
33
34
- #include " drivers/Timeout.h"
35
34
36
35
using namespace std ::chrono;
37
36
@@ -44,21 +43,21 @@ namespace impl {
44
43
namespace {
45
44
46
45
// Constants
47
- static const uint16_t scan_interval_min = 0x0004 ;
48
- static const uint16_t scan_interval_max = 0x4000 ;
49
- static const uint16_t connection_interval_min = 0x0006 ;
50
- static const uint16_t connection_interval_max = 0x0C80 ;
51
- static const uint16_t slave_latency_min = 0x0000 ;
52
- static const uint16_t slave_latency_max = 0x01F3 ;
53
- static const uint16_t advertising_interval_min = 0x0020 ;
54
- static const uint16_t advertising_interval_max = 0x4000 ;
55
- static const uint16_t supervision_timeout_min = 0x000A ;
56
- static const uint16_t supervision_timeout_max = 0x0C80 ;
57
-
58
- static const mbed_error_status_t mixed_scan_api_error =
46
+ const uint16_t scan_interval_min = 0x0004 ;
47
+ const uint16_t scan_interval_max = 0x4000 ;
48
+ const uint16_t connection_interval_min = 0x0006 ;
49
+ const uint16_t connection_interval_max = 0x0C80 ;
50
+ const uint16_t slave_latency_min = 0x0000 ;
51
+ const uint16_t slave_latency_max = 0x01F3 ;
52
+ const uint16_t advertising_interval_min = 0x0020 ;
53
+ const uint16_t advertising_interval_max = 0x4000 ;
54
+ const uint16_t supervision_timeout_min = 0x000A ;
55
+ const uint16_t supervision_timeout_max = 0x0C80 ;
56
+
57
+ const mbed_error_status_t mixed_scan_api_error =
59
58
MBED_MAKE_ERROR (MBED_MODULE_BLE, MBED_ERROR_CODE_BLE_USE_INCOMPATIBLE_API);
60
59
61
- static const mbed_error_status_t illegal_state_error =
60
+ const mbed_error_status_t illegal_state_error =
62
61
MBED_MAKE_ERROR (MBED_MODULE_BLE, MBED_ERROR_CODE_BLE_ILLEGAL_STATE);
63
62
64
63
/*
@@ -82,13 +81,13 @@ static bool is_in_range(T value, T lower_bound, T higher_bound)
82
81
* timeout to be equal to 0xFFFF. When it is the case that value can be
83
82
* interpreted as "non specific".
84
83
*/
85
- static bool is_preferred_connection_params_valid (const Gap::PreferredConnectionParams_t *params)
84
+ bool is_preferred_connection_params_valid (const Gap::PreferredConnectionParams_t *params)
86
85
{
87
86
if (params == nullptr ) {
88
87
return false ;
89
88
}
90
89
91
- if (is_in_range (params->slaveLatency , slave_latency_min, slave_latency_max) == false ) {
90
+ if (! is_in_range (params->slaveLatency , slave_latency_min, slave_latency_max) == false ) {
92
91
return false ;
93
92
}
94
93
@@ -132,7 +131,7 @@ static bool is_preferred_connection_params_valid(const Gap::PreferredConnectionP
132
131
/* *
133
132
* Check if random bytes of an address are valid.
134
133
*/
135
- static bool is_prand_valid (const uint8_t *bytes, size_t len)
134
+ bool is_prand_valid (const uint8_t *bytes, size_t len)
136
135
{
137
136
// at least one bit of the random part of the static address shall be
138
137
// equal to 0 and at least one bit of the random part of the static
@@ -163,7 +162,7 @@ static bool is_prand_valid(const uint8_t *bytes, size_t len)
163
162
* or not.
164
163
* Return true if it is the case and false otherwise.
165
164
*/
166
- static bool is_prand_48_bits_valid (const address_t &address)
165
+ bool is_prand_48_bits_valid (const address_t &address)
167
166
{
168
167
return is_prand_valid (address.data (), 6 );
169
168
}
@@ -173,15 +172,15 @@ static bool is_prand_48_bits_valid(const address_t &address)
173
172
* or not.
174
173
* Return true if it is the case and false otherwise.
175
174
*/
176
- static bool is_prand_24_bits_valid (const address_t &address)
175
+ bool is_prand_24_bits_valid (const address_t &address)
177
176
{
178
177
return is_prand_valid (address.data () + 3 , 3 );
179
178
}
180
179
181
180
/*
182
181
* Return true if address is a random static address.
183
182
*/
184
- static bool is_random_static_address (const address_t &address)
183
+ bool is_random_static_address (const address_t &address)
185
184
{
186
185
// top two msb bits shall be equal to 0b11.
187
186
if ((address[5 ] & 0xC0 ) != 0xC0 ) {
@@ -194,7 +193,7 @@ static bool is_random_static_address(const address_t &address)
194
193
/*
195
194
* Return true if address is a random private non resolvable address.
196
195
*/
197
- static bool is_random_private_non_resolvable_address (
196
+ bool is_random_private_non_resolvable_address (
198
197
const address_t &address
199
198
)
200
199
{
@@ -209,7 +208,7 @@ static bool is_random_private_non_resolvable_address(
209
208
/*
210
209
* Return true if address is a random private resolvable address.
211
210
*/
212
- static bool is_random_private_resolvable_address (
211
+ bool is_random_private_resolvable_address (
213
212
const address_t &address
214
213
)
215
214
{
@@ -224,7 +223,7 @@ static bool is_random_private_resolvable_address(
224
223
/*
225
224
* Return true if the address is a random address.
226
225
*/
227
- static bool is_random_address (const address_t &address)
226
+ bool is_random_address (const address_t &address)
228
227
{
229
228
return is_random_private_resolvable_address (address) ||
230
229
is_random_private_non_resolvable_address (address) ||
@@ -234,7 +233,7 @@ static bool is_random_address(const address_t &address)
234
233
/*
235
234
* Return true if the whitelist in input is valid or false otherwise.
236
235
*/
237
- static bool is_whitelist_valid (const ::ble::whitelist_t &whitelist)
236
+ bool is_whitelist_valid (const ::ble::whitelist_t &whitelist)
238
237
{
239
238
if (whitelist.size > whitelist.capacity ) {
240
239
return false ;
@@ -266,7 +265,7 @@ static bool is_whitelist_valid(const ::ble::whitelist_t &whitelist)
266
265
/*
267
266
* Return true if device is present in the whitelist.
268
267
*/
269
- static bool is_in_whitelist (
268
+ bool is_in_whitelist (
270
269
const whitelist_t ::entry_t &device, const whitelist_t &whitelist
271
270
)
272
271
{
@@ -283,7 +282,7 @@ static bool is_in_whitelist(
283
282
/*
284
283
* Convert a peer_address_type_t into a whitelist_address_type_t.
285
284
*/
286
- static whitelist_address_type_t to_whitelist_address_type (
285
+ whitelist_address_type_t to_whitelist_address_type (
287
286
peer_address_type_t address_type
288
287
)
289
288
{
@@ -354,9 +353,7 @@ Gap::Gap(
354
353
}
355
354
356
355
357
- Gap::~Gap ()
358
- {
359
- }
356
+ Gap::~Gap () = default ;
360
357
361
358
362
359
bool Gap::isFeatureSupported (controller_supported_features_t feature)
@@ -907,7 +904,7 @@ ble_error_t Gap::getCentralPrivacyConfiguration(
907
904
}
908
905
909
906
910
- ble_error_t Gap::reset (void )
907
+ ble_error_t Gap::reset ()
911
908
{
912
909
/* Notify that the instance is about to shut down */
913
910
// shutdownCallChain.call(this);
@@ -973,6 +970,16 @@ ble_error_t Gap::reset(void)
973
970
return BLE_ERROR_NONE;
974
971
}
975
972
973
+ void Gap::onShutdown (const GapShutdownCallback_t &callback)
974
+ {
975
+ shutdownCallChain.add (callback);
976
+ }
977
+
978
+ Gap::GapShutdownCallbackChain_t &Gap::onShutdown ()
979
+ {
980
+ return shutdownCallChain;
981
+ }
982
+
976
983
977
984
void Gap::on_scan_timeout ()
978
985
{
0 commit comments