Skip to content

Commit 240fc8f

Browse files
committed
Add to Gap/GenericGap non-deprecated APIs originally in LegacyGap
1 parent 69b044f commit 240fc8f

File tree

4 files changed

+355
-322
lines changed

4 files changed

+355
-322
lines changed

features/FEATURE_BLE/ble/gap/Gap.h

Lines changed: 204 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.
@@ -944,6 +1007,34 @@ class Gap : public StaticInterface<Impl, Gap> {
9441007
#endif // BLE_ROLE_CENTRAL
9451008

9461009
#if BLE_FEATURE_CONNECTABLE
1010+
/**
1011+
* Returned the preferred connection parameters exposed in the GATT Generic
1012+
* Access Service.
1013+
*
1014+
* @param[out] params Structure where the parameters are stored.
1015+
*
1016+
* @return BLE_ERROR_NONE if the parameters were successfully filled into
1017+
* @p params.
1018+
*/
1019+
ble_error_t getPreferredConnectionParams(ConnectionParams_t *params);
1020+
1021+
/**
1022+
* Set the value of the preferred connection parameters exposed in the GATT
1023+
* Generic Access Service.
1024+
*
1025+
* A connected peer may read the characteristic exposing these parameters
1026+
* and request an update of the connection parameters to accommodate the
1027+
* local device.
1028+
*
1029+
* @param[in] params Value of the preferred connection parameters.
1030+
*
1031+
* @return BLE_ERROR_NONE if the preferred connection params were set
1032+
* correctly.
1033+
*/
1034+
ble_error_t setPreferredConnectionParams(
1035+
const ConnectionParams_t *params
1036+
);
1037+
9471038
/**
9481039
* Update connection parameters of an existing connection.
9491040
*
@@ -1164,7 +1255,7 @@ class Gap : public StaticInterface<Impl, Gap> {
11641255
/**
11651256
* Default peripheral privacy configuration.
11661257
*/
1167-
static const central_privay_configuration_t
1258+
static const central_privacy_configuration_t
11681259
default_central_privacy_configuration;
11691260

11701261

@@ -1238,7 +1329,7 @@ class Gap : public StaticInterface<Impl, Gap> {
12381329
* @return BLE_ERROR_NONE in case of success or an appropriate error code.
12391330
*/
12401331
ble_error_t setCentralPrivacyConfiguration(
1241-
const central_privay_configuration_t *configuration
1332+
const central_privacy_configuration_t *configuration
12421333
);
12431334

12441335
/**
@@ -1250,7 +1341,7 @@ class Gap : public StaticInterface<Impl, Gap> {
12501341
* @return BLE_ERROR_NONE in case of success or an appropriate error code.
12511342
*/
12521343
ble_error_t getCentralPrivacyConfiguration(
1253-
central_privay_configuration_t *configuration
1344+
central_privacy_configuration_t *configuration
12541345
);
12551346
#endif // BLE_ROLE_OBSERVER
12561347
#endif // BLE_FEATURE_PRIVACY
@@ -1297,6 +1388,94 @@ class Gap : public StaticInterface<Impl, Gap> {
12971388

12981389
#endif // BLE_FEATURE_WHITELIST
12991390

1391+
/**
1392+
* Fetch the current address and its type.
1393+
*
1394+
* @param[out] typeP Type of the current address set.
1395+
* @param[out] address Value of the current address.
1396+
*
1397+
* @note If privacy is enabled the device address may be unavailable to
1398+
* application code.
1399+
*
1400+
* @return BLE_ERROR_NONE on success.
1401+
*/
1402+
ble_error_t getAddress(
1403+
BLEProtocol::AddressType_t *typeP,
1404+
BLEProtocol::AddressBytes_t address
1405+
);
1406+
1407+
/**
1408+
* Return the type of a random address.
1409+
*
1410+
* @param[in] address The random address to retrieve the type from. The
1411+
* address must be ordered in little endian.
1412+
*
1413+
* @param[out] addressType Type of the address to fill.
1414+
*
1415+
* @return BLE_ERROR_NONE in case of success or BLE_ERROR_INVALID_PARAM if
1416+
* the address in input was not identifiable as a random address.
1417+
*/
1418+
static ble_error_t getRandomAddressType(
1419+
const BLEProtocol::AddressBytes_t address,
1420+
ble::random_address_type_t *addressType
1421+
);
1422+
1423+
/**
1424+
* Reset the Gap instance.
1425+
*
1426+
* Reset process starts by notifying all registered shutdown event handlers
1427+
* that the Gap instance is about to be shut down. Then, it clears all Gap state
1428+
* of the associated object and then cleans the state present in the vendor
1429+
* implementation.
1430+
*
1431+
* This function is meant to be overridden in the platform-specific
1432+
* subclass. Nevertheless, the subclass only resets its
1433+
* state and not the data held in Gap members. This is achieved by a
1434+
* call to Gap::reset() from the subclass' reset() implementation.
1435+
*
1436+
* @return BLE_ERROR_NONE on success.
1437+
*
1438+
* @note Currently, a call to reset() does not reset the advertising and
1439+
* scan parameters to default values.
1440+
*/
1441+
ble_error_t reset(void);
1442+
1443+
/**
1444+
* Register a Gap shutdown event handler.
1445+
*
1446+
* The handler is called when the Gap instance is about to shut down.
1447+
* It is usually issued after a call to BLE::shutdown().
1448+
*
1449+
* @param[in] callback Shutdown event handler to register.
1450+
*
1451+
* @note To unregister a shutdown event handler, use
1452+
* onShutdown().detach(callback).
1453+
*/
1454+
void onShutdown(const GapShutdownCallback_t &callback);
1455+
1456+
/**
1457+
* Register a Gap shutdown event handler.
1458+
*
1459+
* @param[in] objPtr Instance used to invoke @p memberPtr.
1460+
* @param[in] memberPtr Shutdown event handler to register.
1461+
*/
1462+
template<typename T>
1463+
void onShutdown(T *objPtr, void (T::*memberPtr)(const Gap *))
1464+
{
1465+
shutdownCallChain.add(objPtr, memberPtr);
1466+
}
1467+
1468+
/**
1469+
* Access the callchain of shutdown event handler.
1470+
*
1471+
* @note To register callbacks, use onShutdown().add(callback).
1472+
*
1473+
* @note To unregister callbacks, use onShutdown().detach(callback).
1474+
*
1475+
* @return A reference to the shutdown event callback chain.
1476+
*/
1477+
GapShutdownCallbackChain_t &onShutdown();
1478+
13001479
#if !defined(DOXYGEN_ONLY)
13011480
/*
13021481
* API reserved for the controller driver to set the random static address.
@@ -1312,6 +1491,7 @@ class Gap : public StaticInterface<Impl, Gap> {
13121491
*/
13131492
Gap();
13141493

1494+
13151495
/* ----------------- API to override in derived class -------------- */
13161496

13171497
bool isFeatureSupported_(controller_supported_features_t feature);
@@ -1394,6 +1574,10 @@ class Gap : public StaticInterface<Impl, Gap> {
13941574
const ConnectionParameters &connectionParams
13951575
);
13961576
ble_error_t cancelConnect_();
1577+
ble_error_t getPreferredConnectionParams_(ConnectionParams_t *params);
1578+
ble_error_t setPreferredConnectionParams_(
1579+
const ConnectionParams_t *params
1580+
);
13971581
ble_error_t updateConnectionParameters_(
13981582
connection_handle_t connectionHandle,
13991583
conn_interval_t minConnectionInterval,
@@ -1441,17 +1625,32 @@ class Gap : public StaticInterface<Impl, Gap> {
14411625
peripheral_privacy_configuration_t *configuration
14421626
);
14431627
ble_error_t setCentralPrivacyConfiguration_(
1444-
const central_privay_configuration_t *configuration
1628+
const central_privacy_configuration_t *configuration
14451629
);
14461630
ble_error_t getCentralPrivacyConfiguration_(
1447-
central_privay_configuration_t *configuration
1631+
central_privacy_configuration_t *configuration
14481632
);
14491633
ble_error_t setRandomStaticAddress_(const ble::address_t& address);
14501634
uint8_t getMaxWhitelistSize_(void) const;
14511635
ble_error_t getWhitelist_(whitelist_t &whitelist) const;
14521636
ble_error_t setWhitelist_(const whitelist_t &whitelist);
14531637

1638+
ble_error_t getAddress_(
1639+
BLEProtocol::AddressType_t *typeP,
1640+
BLEProtocol::AddressBytes_t address
1641+
);
1642+
1643+
/* Note: Implementation must call the base class reset_ */
1644+
ble_error_t reset_(void);
1645+
14541646
protected:
1647+
1648+
/**
1649+
* Callchain containing all registered callback handlers for shutdown
1650+
* events.
1651+
*/
1652+
GapShutdownCallbackChain_t shutdownCallChain;
1653+
14551654
/**
14561655
* Event handler provided by the application.
14571656
*/

0 commit comments

Comments
 (0)