@@ -533,6 +533,21 @@ class Gap {
533
533
*/
534
534
typedef ble::peer_address_type_t PeerAddressType_t;
535
535
536
+ /* *
537
+ * Enumeration of BLE PHY
538
+ */
539
+ typedef ble::phy_t Phy_t;
540
+
541
+ /* *
542
+ * Set of BLE PHYs
543
+ */
544
+ typedef ble::phys_t Phys_t;
545
+
546
+ /* *
547
+ * Enumeration of type of symbols that can be used with LE coded PHY.
548
+ */
549
+ typedef ble::coded_symbol_per_bit_t CodedSymbolPerBit_t;
550
+
536
551
/* *
537
552
* Parameters of a BLE connection.
538
553
*/
@@ -1071,6 +1086,68 @@ class Gap {
1071
1086
typedef CallChainOfFunctionPointersWithContext<const Gap *>
1072
1087
GapShutdownCallbackChain_t;
1073
1088
1089
+
1090
+ /* *
1091
+ * Definition of the general handler of Gap related events.
1092
+ */
1093
+ struct EventHandler {
1094
+ /* *
1095
+ * Function invoked when the current transmitter and receiver PHY have
1096
+ * been read for a given connection.
1097
+ *
1098
+ * @param status Status of the operation: BLE_ERROR_NONE in case of
1099
+ * success or an appropriate error code.
1100
+ *
1101
+ * @param connectionHandle: The handle of the connection for which the
1102
+ * PHYs have been read.
1103
+ *
1104
+ * @param txPhy PHY used by the transmitter.
1105
+ *
1106
+ * @param rxPhy PHY used by the receiver.
1107
+ */
1108
+ virtual void onPhyRead (
1109
+ ble_error_t status,
1110
+ Handle_t connectionHandle,
1111
+ ble::phy_t txPhy,
1112
+ ble::phy_t rxPhy
1113
+ ) = 0;
1114
+
1115
+ /* *
1116
+ * Function invoked when the update process of the PHY has been completed.
1117
+ *
1118
+ * The process can be initiated by a call to the function setPhy, the
1119
+ * local bluetooth subsystem or the peer.
1120
+ *
1121
+ * @param status Status of the operation: BLE_ERROR_NONE in case of
1122
+ * success or an appropriate error code.
1123
+ *
1124
+ * @param connectionHandle: The handle of the connection on which the
1125
+ * operation was made.
1126
+ *
1127
+ * @param txPhy PHY used by the transmitter.
1128
+ *
1129
+ * @param rxPhy PHY used by the receiver.
1130
+ *
1131
+ * @note Success doesn't mean the PHY has been updated it means both
1132
+ * ends have negociated the best phy according to their configuration and
1133
+ * capabilities. The PHY currently used are present in the txPhy and
1134
+ * rxPhy parameters.
1135
+ */
1136
+ virtual void onPhyUpdateComplete (
1137
+ ble_error_t status,
1138
+ Handle_t connectionHandle,
1139
+ ble::phy_t txPhy,
1140
+ ble::phy_t rxPhy
1141
+ ) = 0;
1142
+
1143
+ protected:
1144
+ /* *
1145
+ * Prevent polymorphic deletion and avoid uncessery virtual destructor
1146
+ * as the Gap class will never delete the instance it contains.
1147
+ */
1148
+ ~EventHandler () { }
1149
+ };
1150
+
1074
1151
/*
1075
1152
* The following functions are meant to be overridden in the platform-specific subclass.
1076
1153
*/
@@ -1331,6 +1408,72 @@ class Gap {
1331
1408
const GapScanningParams *scanParams
1332
1409
);
1333
1410
1411
+ /* *
1412
+ * Read the PHY used by the transmitter and the receiver on a connection.
1413
+ *
1414
+ * Once the PHY has been read, it is reported back via the function onPhyRead
1415
+ * of the event handler registered by the application.
1416
+ *
1417
+ * @param connection Handle of the connection for which the PHY being used is
1418
+ * queried.
1419
+ *
1420
+ * @return BLE_ERROR_NONE if the read PHY procedure has been started or an
1421
+ * appropriate error code.
1422
+ */
1423
+ virtual ble_error_t readPhy (Handle_t connection) {
1424
+ return BLE_ERROR_NOT_IMPLEMENTED;
1425
+ }
1426
+
1427
+ /* *
1428
+ * Set the prefered PHYs to use in a connection.
1429
+ *
1430
+ * @param txPhy: Set of PHYs prefered for tx operations. If NULL then no
1431
+ * prefered PHYs are set and the default value of the subsytem is used.
1432
+ *
1433
+ * @param rxPhy: Set of PHYs prefered for rx operations. If NULL then no
1434
+ * prefered PHYs are set and the default value of the subsytem is used.
1435
+ *
1436
+ * @return BLE_ERROR_NONE if the preferences have been set or an appropriate
1437
+ * error code.
1438
+ */
1439
+ virtual ble_error_t setPreferedPhys (
1440
+ const Phys_t* txPhys,
1441
+ const Phys_t* rxPhys
1442
+ ) {
1443
+ return BLE_ERROR_NOT_IMPLEMENTED;
1444
+ }
1445
+
1446
+ /* *
1447
+ * Update the PHY used by a connection.
1448
+ *
1449
+ * Once the update process has been completed, it is reported back to the
1450
+ * application via the function onPhyUpdateComplete of the event handler
1451
+ * registered by the application.
1452
+ *
1453
+ * @param connection Handle of the connection to update.
1454
+ *
1455
+ * @param txPhys Set of PHYs prefered for tx operations. If NULL then the
1456
+ * choice is up to the Bluetooth subsystem.
1457
+ *
1458
+ * @param rxPhys Set of PHYs prefered for rx operations. If NULL then the
1459
+ * choice is up to the Bluetooth subsystem.
1460
+ *
1461
+ * @param codedSymbol Number of symbols used to code a bit when le coded is
1462
+ * used. If the value is UNDEFINED then the choice is up to the Bluetooth
1463
+ * subsystem.
1464
+ *
1465
+ * @return BLE_ERROR_NONE if the update PHY procedure has been successfully
1466
+ * started or an error code.
1467
+ */
1468
+ virtual ble_error_t setPhy (
1469
+ Handle_t connection,
1470
+ const Phys_t* txPhys,
1471
+ const Phys_t* rxPhys,
1472
+ CodedSymbolPerBit_t codedSymbol
1473
+ ) {
1474
+ return BLE_ERROR_NONE;
1475
+ }
1476
+
1334
1477
/* *
1335
1478
* Initiate a disconnection procedure.
1336
1479
*
@@ -2446,6 +2589,17 @@ class Gap {
2446
2589
2447
2590
/* Event handlers. */
2448
2591
public:
2592
+
2593
+ /* *
2594
+ * Assign the event handler implementation that will be used by the gap
2595
+ * module to signal events back to the application.
2596
+ *
2597
+ * @param handler Application implementation of an Eventhandler.
2598
+ */
2599
+ void setEventHandler (EventHandler* handler) {
2600
+ _eventHandler = handler;
2601
+ }
2602
+
2449
2603
/* *
2450
2604
* Register a callback handling timeout events.
2451
2605
*
@@ -2674,6 +2828,7 @@ class Gap {
2674
2828
disconnectionCallChain.clear ();
2675
2829
radioNotificationCallback = NULL ;
2676
2830
onAdvertisementReport = NULL ;
2831
+ _eventHandler = NULL ;
2677
2832
2678
2833
return BLE_ERROR_NONE;
2679
2834
}
@@ -2694,7 +2849,8 @@ class Gap {
2694
2849
radioNotificationCallback(),
2695
2850
onAdvertisementReport(),
2696
2851
connectionCallChain(),
2697
- disconnectionCallChain() {
2852
+ disconnectionCallChain(),
2853
+ _eventHandler(NULL ) {
2698
2854
_advPayload.clear ();
2699
2855
_scanResponse.clear ();
2700
2856
}
@@ -2938,6 +3094,11 @@ class Gap {
2938
3094
*/
2939
3095
DisconnectionEventCallbackChain_t disconnectionCallChain;
2940
3096
3097
+ /* *
3098
+ * Event handler provided by the application.
3099
+ */
3100
+ EventHandler* _eventHandler;
3101
+
2941
3102
private:
2942
3103
/* *
2943
3104
* Callchain containing all registered callback handlers for shutdown
0 commit comments