Skip to content

Commit c17cf0f

Browse files
committed
Add to Gap/GenericGap non-deprecated APIs originally in LegacyGap
1 parent 2989466 commit c17cf0f

File tree

4 files changed

+284
-374
lines changed

4 files changed

+284
-374
lines changed

features/FEATURE_BLE/ble/gap/Gap.h

Lines changed: 172 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "BLERoles.h"
2121
#include "ble/common/StaticInterface.h"
2222
#include "ble/BLETypes.h"
23+
#include "ble/CallChainOfFunctionPointersWithContext.h"
2324
#include "ble/gap/AdvertisingDataBuilder.h"
2425
#include "ble/gap/AdvertisingDataSimpleBuilder.h"
2526
#include "ble/gap/ConnectionParameters.h"
@@ -278,6 +279,21 @@ class Gap : public StaticInterface<Impl, Gap> {
278279
#endif
279280
using StaticInterface<Impl, ::ble::interface::Gap>::impl;
280281

282+
/**
283+
* Gap shutdown event handler.
284+
*
285+
* @see Gap::onShutdown().
286+
*/
287+
typedef FunctionPointerWithContext<const Gap *> GapShutdownCallback_t;
288+
289+
/**
290+
* Callchain of gap shutdown event handler.
291+
*
292+
* @see Gap::onShutdown().
293+
*/
294+
typedef CallChainOfFunctionPointersWithContext<const Gap *>
295+
GapShutdownCallbackChain_t;
296+
281297
public:
282298

283299
/**
@@ -531,6 +547,53 @@ class Gap : public StaticInterface<Impl, Gap> {
531547
}
532548
};
533549

550+
/**
551+
* Parameters of a BLE connection.
552+
*/
553+
typedef struct {
554+
/**
555+
* Minimum interval between two connection events allowed for a
556+
* connection.
557+
*
558+
* It shall be less than or equal to maxConnectionInterval. This value,
559+
* in units of 1.25ms, is included in the range [0x0006 : 0x0C80].
560+
*/
561+
uint16_t minConnectionInterval;
562+
563+
/**
564+
* Maximum interval between two connection events allowed for a
565+
* connection.
566+
*
567+
* It shall be greater than or equal to minConnectionInterval. This
568+
* value is in unit of 1.25ms and is in the range [0x0006 : 0x0C80].
569+
*/
570+
uint16_t maxConnectionInterval;
571+
572+
/**
573+
* Number of connection events the slave can drop if it has nothing to
574+
* communicate to the master.
575+
*
576+
* This value shall be in the range [0x0000 : 0x01F3].
577+
*/
578+
uint16_t slaveLatency;
579+
580+
/**
581+
* Link supervision timeout for the connection.
582+
*
583+
* Time after which the connection is considered lost if the device
584+
* didn't receive a packet from its peer.
585+
*
586+
* It is larger than:
587+
* (1 + slaveLatency) * maxConnectionInterval * 2
588+
*
589+
* This value is in the range [0x000A : 0x0C80] and is in unit of
590+
* 10 ms.
591+
*
592+
* @note maxConnectionInterval is in ms in the formulae above.
593+
*/
594+
uint16_t connectionSupervisionTimeout;
595+
} ConnectionParams_t;
596+
534597
/**
535598
* Assign the event handler implementation that will be used by the gap
536599
* module to signal events back to the application.
@@ -1164,7 +1227,7 @@ class Gap : public StaticInterface<Impl, Gap> {
11641227
/**
11651228
* Default peripheral privacy configuration.
11661229
*/
1167-
static const central_privay_configuration_t
1230+
static const central_privacy_configuration_t
11681231
default_central_privacy_configuration;
11691232

11701233

@@ -1238,7 +1301,7 @@ class Gap : public StaticInterface<Impl, Gap> {
12381301
* @return BLE_ERROR_NONE in case of success or an appropriate error code.
12391302
*/
12401303
ble_error_t setCentralPrivacyConfiguration(
1241-
const central_privay_configuration_t *configuration
1304+
const central_privacy_configuration_t *configuration
12421305
);
12431306

12441307
/**
@@ -1250,7 +1313,7 @@ class Gap : public StaticInterface<Impl, Gap> {
12501313
* @return BLE_ERROR_NONE in case of success or an appropriate error code.
12511314
*/
12521315
ble_error_t getCentralPrivacyConfiguration(
1253-
central_privay_configuration_t *configuration
1316+
central_privacy_configuration_t *configuration
12541317
);
12551318
#endif // BLE_ROLE_OBSERVER
12561319
#endif // BLE_FEATURE_PRIVACY
@@ -1297,6 +1360,94 @@ class Gap : public StaticInterface<Impl, Gap> {
12971360

12981361
#endif // BLE_FEATURE_WHITELIST
12991362

1363+
/**
1364+
* Fetch the current address and its type.
1365+
*
1366+
* @param[out] typeP Type of the current address set.
1367+
* @param[out] address Value of the current address.
1368+
*
1369+
* @note If privacy is enabled the device address may be unavailable to
1370+
* application code.
1371+
*
1372+
* @return BLE_ERROR_NONE on success.
1373+
*/
1374+
ble_error_t getAddress(
1375+
BLEProtocol::AddressType_t *typeP,
1376+
BLEProtocol::AddressBytes_t address
1377+
);
1378+
1379+
/**
1380+
* Return the type of a random address.
1381+
*
1382+
* @param[in] address The random address to retrieve the type from. The
1383+
* address must be ordered in little endian.
1384+
*
1385+
* @param[out] addressType Type of the address to fill.
1386+
*
1387+
* @return BLE_ERROR_NONE in case of success or BLE_ERROR_INVALID_PARAM if
1388+
* the address in input was not identifiable as a random address.
1389+
*/
1390+
static ble_error_t getRandomAddressType(
1391+
const BLEProtocol::AddressBytes_t address,
1392+
ble::random_address_type_t *addressType
1393+
);
1394+
1395+
/**
1396+
* Reset the Gap instance.
1397+
*
1398+
* Reset process starts by notifying all registered shutdown event handlers
1399+
* that the Gap instance is about to be shut down. Then, it clears all Gap state
1400+
* of the associated object and then cleans the state present in the vendor
1401+
* implementation.
1402+
*
1403+
* This function is meant to be overridden in the platform-specific
1404+
* subclass. Nevertheless, the subclass only resets its
1405+
* state and not the data held in Gap members. This is achieved by a
1406+
* call to Gap::reset() from the subclass' reset() implementation.
1407+
*
1408+
* @return BLE_ERROR_NONE on success.
1409+
*
1410+
* @note Currently, a call to reset() does not reset the advertising and
1411+
* scan parameters to default values.
1412+
*/
1413+
ble_error_t reset(void);
1414+
1415+
/**
1416+
* Register a Gap shutdown event handler.
1417+
*
1418+
* The handler is called when the Gap instance is about to shut down.
1419+
* It is usually issued after a call to BLE::shutdown().
1420+
*
1421+
* @param[in] callback Shutdown event handler to register.
1422+
*
1423+
* @note To unregister a shutdown event handler, use
1424+
* onShutdown().detach(callback).
1425+
*/
1426+
void onShutdown(const GapShutdownCallback_t &callback);
1427+
1428+
/**
1429+
* Register a Gap shutdown event handler.
1430+
*
1431+
* @param[in] objPtr Instance used to invoke @p memberPtr.
1432+
* @param[in] memberPtr Shutdown event handler to register.
1433+
*/
1434+
template<typename T>
1435+
void onShutdown(T *objPtr, void (T::*memberPtr)(const Gap *))
1436+
{
1437+
shutdownCallChain.add(objPtr, memberPtr);
1438+
}
1439+
1440+
/**
1441+
* Access the callchain of shutdown event handler.
1442+
*
1443+
* @note To register callbacks, use onShutdown().add(callback).
1444+
*
1445+
* @note To unregister callbacks, use onShutdown().detach(callback).
1446+
*
1447+
* @return A reference to the shutdown event callback chain.
1448+
*/
1449+
GapShutdownCallbackChain_t &onShutdown();
1450+
13001451
#if !defined(DOXYGEN_ONLY)
13011452
/*
13021453
* API reserved for the controller driver to set the random static address.
@@ -1312,6 +1463,7 @@ class Gap : public StaticInterface<Impl, Gap> {
13121463
*/
13131464
Gap();
13141465

1466+
13151467
/* ----------------- API to override in derived class -------------- */
13161468

13171469
bool isFeatureSupported_(controller_supported_features_t feature);
@@ -1441,17 +1593,32 @@ class Gap : public StaticInterface<Impl, Gap> {
14411593
peripheral_privacy_configuration_t *configuration
14421594
);
14431595
ble_error_t setCentralPrivacyConfiguration_(
1444-
const central_privay_configuration_t *configuration
1596+
const central_privacy_configuration_t *configuration
14451597
);
14461598
ble_error_t getCentralPrivacyConfiguration_(
1447-
central_privay_configuration_t *configuration
1599+
central_privacy_configuration_t *configuration
14481600
);
14491601
ble_error_t setRandomStaticAddress_(const ble::address_t& address);
14501602
uint8_t getMaxWhitelistSize_(void) const;
14511603
ble_error_t getWhitelist_(whitelist_t &whitelist) const;
14521604
ble_error_t setWhitelist_(const whitelist_t &whitelist);
14531605

1606+
ble_error_t getAddress_(
1607+
BLEProtocol::AddressType_t *typeP,
1608+
BLEProtocol::AddressBytes_t address
1609+
);
1610+
1611+
/* Note: Implementation must call the base class reset_ */
1612+
ble_error_t reset_(void);
1613+
14541614
protected:
1615+
1616+
/**
1617+
* Callchain containing all registered callback handlers for shutdown
1618+
* events.
1619+
*/
1620+
GapShutdownCallbackChain_t shutdownCallChain;
1621+
14551622
/**
14561623
* Event handler provided by the application.
14571624
*/

0 commit comments

Comments
 (0)