Skip to content

Commit bc259c5

Browse files
committed
BLE: cleanup generic sources
1 parent 57b5f71 commit bc259c5

File tree

12 files changed

+232
-244
lines changed

12 files changed

+232
-244
lines changed

connectivity/FEATURE_BLE/source/Gap.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,6 @@ ble_error_t Gap::cancelConnect()
285285
}
286286

287287

288-
ble_error_t Gap::cancelConnect(
289-
peer_address_type_t peerAddressType,
290-
const address_t &peerAddress
291-
)
292-
{
293-
return impl->cancelConnect(peerAddressType, peerAddress);
294-
}
295-
296288
#endif // BLE_ROLE_CENTRAL
297289

298290
#if BLE_FEATURE_CONNECTABLE

connectivity/FEATURE_BLE/source/generic/GapImpl.cpp

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,20 @@
1717
*/
1818

1919
#include <algorithm>
20-
#include <stdint.h>
20+
#include <cstdint>
2121

22-
#include "GapImpl.h"
23-
#include "ble/Gap.h"
24-
#include "source/BLEInstanceBase.h"
2522
#include "ble/Gap.h"
2623
#include "ble/SecurityManager.h"
24+
25+
#include "source/BLEInstanceBase.h"
26+
#include "source/generic/GapImpl.h"
27+
2728
#include "source/pal/PalGap.h"
2829
#include "source/pal/GapEvents.h"
2930
#include "source/pal/GapTypes.h"
3031
#include "source/pal/PalGenericAccessService.h"
3132
#include "source/pal/PalEventQueue.h"
32-
#include "source/pal/PalGap.h"
3333

34-
#include "drivers/Timeout.h"
3534

3635
using namespace std::chrono;
3736

@@ -44,21 +43,21 @@ namespace impl {
4443
namespace {
4544

4645
// 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 =
5958
MBED_MAKE_ERROR(MBED_MODULE_BLE, MBED_ERROR_CODE_BLE_USE_INCOMPATIBLE_API);
6059

61-
static const mbed_error_status_t illegal_state_error =
60+
const mbed_error_status_t illegal_state_error =
6261
MBED_MAKE_ERROR(MBED_MODULE_BLE, MBED_ERROR_CODE_BLE_ILLEGAL_STATE);
6362

6463
/*
@@ -82,13 +81,13 @@ static bool is_in_range(T value, T lower_bound, T higher_bound)
8281
* timeout to be equal to 0xFFFF. When it is the case that value can be
8382
* interpreted as "non specific".
8483
*/
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)
8685
{
8786
if (params == nullptr) {
8887
return false;
8988
}
9089

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) {
9291
return false;
9392
}
9493

@@ -132,7 +131,7 @@ static bool is_preferred_connection_params_valid(const Gap::PreferredConnectionP
132131
/**
133132
* Check if random bytes of an address are valid.
134133
*/
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)
136135
{
137136
// at least one bit of the random part of the static address shall be
138137
// 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)
163162
* or not.
164163
* Return true if it is the case and false otherwise.
165164
*/
166-
static bool is_prand_48_bits_valid(const address_t &address)
165+
bool is_prand_48_bits_valid(const address_t &address)
167166
{
168167
return is_prand_valid(address.data(), 6);
169168
}
@@ -173,15 +172,15 @@ static bool is_prand_48_bits_valid(const address_t &address)
173172
* or not.
174173
* Return true if it is the case and false otherwise.
175174
*/
176-
static bool is_prand_24_bits_valid(const address_t &address)
175+
bool is_prand_24_bits_valid(const address_t &address)
177176
{
178177
return is_prand_valid(address.data() + 3, 3);
179178
}
180179

181180
/*
182181
* Return true if address is a random static address.
183182
*/
184-
static bool is_random_static_address(const address_t &address)
183+
bool is_random_static_address(const address_t &address)
185184
{
186185
// top two msb bits shall be equal to 0b11.
187186
if ((address[5] & 0xC0) != 0xC0) {
@@ -194,7 +193,7 @@ static bool is_random_static_address(const address_t &address)
194193
/*
195194
* Return true if address is a random private non resolvable address.
196195
*/
197-
static bool is_random_private_non_resolvable_address(
196+
bool is_random_private_non_resolvable_address(
198197
const address_t &address
199198
)
200199
{
@@ -209,7 +208,7 @@ static bool is_random_private_non_resolvable_address(
209208
/*
210209
* Return true if address is a random private resolvable address.
211210
*/
212-
static bool is_random_private_resolvable_address(
211+
bool is_random_private_resolvable_address(
213212
const address_t &address
214213
)
215214
{
@@ -224,7 +223,7 @@ static bool is_random_private_resolvable_address(
224223
/*
225224
* Return true if the address is a random address.
226225
*/
227-
static bool is_random_address(const address_t &address)
226+
bool is_random_address(const address_t &address)
228227
{
229228
return is_random_private_resolvable_address(address) ||
230229
is_random_private_non_resolvable_address(address) ||
@@ -234,7 +233,7 @@ static bool is_random_address(const address_t &address)
234233
/*
235234
* Return true if the whitelist in input is valid or false otherwise.
236235
*/
237-
static bool is_whitelist_valid(const ::ble::whitelist_t &whitelist)
236+
bool is_whitelist_valid(const ::ble::whitelist_t &whitelist)
238237
{
239238
if (whitelist.size > whitelist.capacity) {
240239
return false;
@@ -266,7 +265,7 @@ static bool is_whitelist_valid(const ::ble::whitelist_t &whitelist)
266265
/*
267266
* Return true if device is present in the whitelist.
268267
*/
269-
static bool is_in_whitelist(
268+
bool is_in_whitelist(
270269
const whitelist_t::entry_t &device, const whitelist_t &whitelist
271270
)
272271
{
@@ -283,7 +282,7 @@ static bool is_in_whitelist(
283282
/*
284283
* Convert a peer_address_type_t into a whitelist_address_type_t.
285284
*/
286-
static whitelist_address_type_t to_whitelist_address_type(
285+
whitelist_address_type_t to_whitelist_address_type(
287286
peer_address_type_t address_type
288287
)
289288
{
@@ -354,9 +353,7 @@ Gap::Gap(
354353
}
355354

356355

357-
Gap::~Gap()
358-
{
359-
}
356+
Gap::~Gap() = default;
360357

361358

362359
bool Gap::isFeatureSupported(controller_supported_features_t feature)
@@ -907,7 +904,7 @@ ble_error_t Gap::getCentralPrivacyConfiguration(
907904
}
908905

909906

910-
ble_error_t Gap::reset(void)
907+
ble_error_t Gap::reset()
911908
{
912909
/* Notify that the instance is about to shut down */
913910
// shutdownCallChain.call(this);
@@ -973,6 +970,16 @@ ble_error_t Gap::reset(void)
973970
return BLE_ERROR_NONE;
974971
}
975972

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+
976983

977984
void Gap::on_scan_timeout()
978985
{

connectivity/FEATURE_BLE/source/generic/GapImpl.h

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ class Gap :
312312

313313
#if BLE_FEATURE_WHITELIST
314314

315-
uint8_t getMaxWhitelistSize(void) const;
315+
uint8_t getMaxWhitelistSize() const;
316316

317317
ble_error_t getWhitelist(whitelist_t &whitelist) const;
318318

@@ -326,17 +326,14 @@ class Gap :
326326
);
327327

328328
static ble_error_t getRandomAddressType(
329-
const ble::address_t address,
329+
ble::address_t address,
330330
ble::random_address_type_t *addressType
331331
);
332332

333-
ble_error_t reset(void);
333+
ble_error_t reset();
334334

335335
void onShutdown(const GapShutdownCallback_t &callback);
336336

337-
template<typename T>
338-
void onShutdown(T *objPtr, void (T::*memberPtr)(const Gap *));
339-
340337
GapShutdownCallbackChain_t &onShutdown();
341338

342339
#if !defined(DOXYGEN_ONLY)
@@ -432,20 +429,20 @@ class Gap :
432429
connection_handle_t connection_handle,
433430
phy_t tx_phy,
434431
phy_t rx_phy
435-
);
432+
) override;
436433

437434
void on_data_length_change(
438435
connection_handle_t connection_handle,
439436
uint16_t tx_size,
440437
uint16_t rx_size
441-
);
438+
) override;
442439

443440
void on_phy_update_complete(
444441
hci_error_code_t hci_status,
445442
connection_handle_t connection_handle,
446443
phy_t tx_phy,
447444
phy_t rx_phy
448-
);
445+
) override;
449446

450447
void on_enhanced_connection_complete(
451448
hci_error_code_t status,
@@ -459,7 +456,7 @@ class Gap :
459456
uint16_t connection_latency,
460457
uint16_t supervision_timeout,
461458
clock_accuracy_t master_clock_accuracy
462-
);
459+
) override;
463460

464461
void on_extended_advertising_report(
465462
advertising_event_t event_type,
@@ -475,7 +472,7 @@ class Gap :
475472
const ble::address_t &direct_address,
476473
uint8_t data_length,
477474
const uint8_t *data
478-
);
475+
) override;
479476

480477
void on_periodic_advertising_sync_established(
481478
hci_error_code_t error,
@@ -486,7 +483,7 @@ class Gap :
486483
phy_t advertiser_phy,
487484
uint16_t periodic_advertising_interval,
488485
clock_accuracy_t clock_accuracy
489-
);
486+
) override;
490487

491488
void on_periodic_advertising_report(
492489
sync_handle_t sync_handle,
@@ -495,40 +492,40 @@ class Gap :
495492
advertising_data_status_t data_status,
496493
uint8_t data_length,
497494
const uint8_t *data
498-
);
495+
) override;
499496

500-
void on_periodic_advertising_sync_loss(sync_handle_t sync_handle);
497+
void on_periodic_advertising_sync_loss(sync_handle_t sync_handle) override;
501498

502499
void on_advertising_set_terminated(
503500
hci_error_code_t status,
504501
advertising_handle_t advertising_handle,
505502
connection_handle_t connection_handle,
506503
uint8_t number_of_completed_extended_advertising_events
507-
);
504+
) override;
508505

509506
void on_scan_request_received(
510507
advertising_handle_t advertising_handle,
511508
connection_peer_address_type_t scanner_address_type,
512509
const ble::address_t &address
513-
);
510+
) override;
514511

515512
void on_connection_update_complete(
516513
hci_error_code_t status,
517514
connection_handle_t connection_handle,
518515
uint16_t connection_interval,
519516
uint16_t connection_latency,
520517
uint16_t supervision_timeout
521-
);
518+
) override;
522519

523520
void on_remote_connection_parameter(
524521
connection_handle_t connection_handle,
525522
uint16_t connection_interval_min,
526523
uint16_t connection_interval_max,
527524
uint16_t connection_latency,
528525
uint16_t supervision_timeout
529-
);
526+
) override;
530527

531-
void on_scan_timeout();
528+
void on_scan_timeout() override;
532529

533530
void process_legacy_scan_timeout();
534531

0 commit comments

Comments
 (0)