20
20
#include " BLERoles.h"
21
21
#include " ble/common/StaticInterface.h"
22
22
#include " ble/BLETypes.h"
23
+ #include " ble/CallChainOfFunctionPointersWithContext.h"
23
24
#include " ble/gap/AdvertisingDataBuilder.h"
24
25
#include " ble/gap/AdvertisingDataSimpleBuilder.h"
25
26
#include " ble/gap/ConnectionParameters.h"
@@ -278,6 +279,21 @@ class Gap : public StaticInterface<Impl, Gap> {
278
279
#endif
279
280
using StaticInterface<Impl, ::ble::interface::Gap>::impl;
280
281
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
+
281
297
public:
282
298
283
299
/* *
@@ -531,6 +547,53 @@ class Gap : public StaticInterface<Impl, Gap> {
531
547
}
532
548
};
533
549
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
+
534
597
/* *
535
598
* Assign the event handler implementation that will be used by the gap
536
599
* module to signal events back to the application.
@@ -944,6 +1007,34 @@ class Gap : public StaticInterface<Impl, Gap> {
944
1007
#endif // BLE_ROLE_CENTRAL
945
1008
946
1009
#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
+
947
1038
/* *
948
1039
* Update connection parameters of an existing connection.
949
1040
*
@@ -1164,7 +1255,7 @@ class Gap : public StaticInterface<Impl, Gap> {
1164
1255
/* *
1165
1256
* Default peripheral privacy configuration.
1166
1257
*/
1167
- static const central_privay_configuration_t
1258
+ static const central_privacy_configuration_t
1168
1259
default_central_privacy_configuration;
1169
1260
1170
1261
@@ -1238,7 +1329,7 @@ class Gap : public StaticInterface<Impl, Gap> {
1238
1329
* @return BLE_ERROR_NONE in case of success or an appropriate error code.
1239
1330
*/
1240
1331
ble_error_t setCentralPrivacyConfiguration (
1241
- const central_privay_configuration_t *configuration
1332
+ const central_privacy_configuration_t *configuration
1242
1333
);
1243
1334
1244
1335
/* *
@@ -1250,7 +1341,7 @@ class Gap : public StaticInterface<Impl, Gap> {
1250
1341
* @return BLE_ERROR_NONE in case of success or an appropriate error code.
1251
1342
*/
1252
1343
ble_error_t getCentralPrivacyConfiguration (
1253
- central_privay_configuration_t *configuration
1344
+ central_privacy_configuration_t *configuration
1254
1345
);
1255
1346
#endif // BLE_ROLE_OBSERVER
1256
1347
#endif // BLE_FEATURE_PRIVACY
@@ -1297,6 +1388,94 @@ class Gap : public StaticInterface<Impl, Gap> {
1297
1388
1298
1389
#endif // BLE_FEATURE_WHITELIST
1299
1390
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
+
1300
1479
#if !defined(DOXYGEN_ONLY)
1301
1480
/*
1302
1481
* API reserved for the controller driver to set the random static address.
@@ -1312,6 +1491,7 @@ class Gap : public StaticInterface<Impl, Gap> {
1312
1491
*/
1313
1492
Gap ();
1314
1493
1494
+
1315
1495
/* ----------------- API to override in derived class -------------- */
1316
1496
1317
1497
bool isFeatureSupported_ (controller_supported_features_t feature);
@@ -1394,6 +1574,10 @@ class Gap : public StaticInterface<Impl, Gap> {
1394
1574
const ConnectionParameters &connectionParams
1395
1575
);
1396
1576
ble_error_t cancelConnect_ ();
1577
+ ble_error_t getPreferredConnectionParams_ (ConnectionParams_t *params);
1578
+ ble_error_t setPreferredConnectionParams_ (
1579
+ const ConnectionParams_t *params
1580
+ );
1397
1581
ble_error_t updateConnectionParameters_ (
1398
1582
connection_handle_t connectionHandle,
1399
1583
conn_interval_t minConnectionInterval,
@@ -1441,17 +1625,32 @@ class Gap : public StaticInterface<Impl, Gap> {
1441
1625
peripheral_privacy_configuration_t *configuration
1442
1626
);
1443
1627
ble_error_t setCentralPrivacyConfiguration_ (
1444
- const central_privay_configuration_t *configuration
1628
+ const central_privacy_configuration_t *configuration
1445
1629
);
1446
1630
ble_error_t getCentralPrivacyConfiguration_ (
1447
- central_privay_configuration_t *configuration
1631
+ central_privacy_configuration_t *configuration
1448
1632
);
1449
1633
ble_error_t setRandomStaticAddress_ (const ble::address_t & address);
1450
1634
uint8_t getMaxWhitelistSize_ (void ) const ;
1451
1635
ble_error_t getWhitelist_ (whitelist_t &whitelist) const ;
1452
1636
ble_error_t setWhitelist_ (const whitelist_t &whitelist);
1453
1637
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
+
1454
1646
protected:
1647
+
1648
+ /* *
1649
+ * Callchain containing all registered callback handlers for shutdown
1650
+ * events.
1651
+ */
1652
+ GapShutdownCallbackChain_t shutdownCallChain;
1653
+
1455
1654
/* *
1456
1655
* Event handler provided by the application.
1457
1656
*/
0 commit comments