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.
@@ -1164,7 +1227,7 @@ class Gap : public StaticInterface<Impl, Gap> {
1164
1227
/* *
1165
1228
* Default peripheral privacy configuration.
1166
1229
*/
1167
- static const central_privay_configuration_t
1230
+ static const central_privacy_configuration_t
1168
1231
default_central_privacy_configuration;
1169
1232
1170
1233
@@ -1238,7 +1301,7 @@ class Gap : public StaticInterface<Impl, Gap> {
1238
1301
* @return BLE_ERROR_NONE in case of success or an appropriate error code.
1239
1302
*/
1240
1303
ble_error_t setCentralPrivacyConfiguration (
1241
- const central_privay_configuration_t *configuration
1304
+ const central_privacy_configuration_t *configuration
1242
1305
);
1243
1306
1244
1307
/* *
@@ -1250,7 +1313,7 @@ class Gap : public StaticInterface<Impl, Gap> {
1250
1313
* @return BLE_ERROR_NONE in case of success or an appropriate error code.
1251
1314
*/
1252
1315
ble_error_t getCentralPrivacyConfiguration (
1253
- central_privay_configuration_t *configuration
1316
+ central_privacy_configuration_t *configuration
1254
1317
);
1255
1318
#endif // BLE_ROLE_OBSERVER
1256
1319
#endif // BLE_FEATURE_PRIVACY
@@ -1297,6 +1360,94 @@ class Gap : public StaticInterface<Impl, Gap> {
1297
1360
1298
1361
#endif // BLE_FEATURE_WHITELIST
1299
1362
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
+
1300
1451
#if !defined(DOXYGEN_ONLY)
1301
1452
/*
1302
1453
* API reserved for the controller driver to set the random static address.
@@ -1312,6 +1463,7 @@ class Gap : public StaticInterface<Impl, Gap> {
1312
1463
*/
1313
1464
Gap ();
1314
1465
1466
+
1315
1467
/* ----------------- API to override in derived class -------------- */
1316
1468
1317
1469
bool isFeatureSupported_ (controller_supported_features_t feature);
@@ -1441,17 +1593,32 @@ class Gap : public StaticInterface<Impl, Gap> {
1441
1593
peripheral_privacy_configuration_t *configuration
1442
1594
);
1443
1595
ble_error_t setCentralPrivacyConfiguration_ (
1444
- const central_privay_configuration_t *configuration
1596
+ const central_privacy_configuration_t *configuration
1445
1597
);
1446
1598
ble_error_t getCentralPrivacyConfiguration_ (
1447
- central_privay_configuration_t *configuration
1599
+ central_privacy_configuration_t *configuration
1448
1600
);
1449
1601
ble_error_t setRandomStaticAddress_ (const ble::address_t & address);
1450
1602
uint8_t getMaxWhitelistSize_ (void ) const ;
1451
1603
ble_error_t getWhitelist_ (whitelist_t &whitelist) const ;
1452
1604
ble_error_t setWhitelist_ (const whitelist_t &whitelist);
1453
1605
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
+
1454
1614
protected:
1615
+
1616
+ /* *
1617
+ * Callchain containing all registered callback handlers for shutdown
1618
+ * events.
1619
+ */
1620
+ GapShutdownCallbackChain_t shutdownCallChain;
1621
+
1455
1622
/* *
1456
1623
* Event handler provided by the application.
1457
1624
*/
0 commit comments