Skip to content

Commit c29a2e2

Browse files
authored
Merge pull request #13811 from pan-/ble-conditional-compilation
Ble conditional compilation
2 parents 77638f9 + ad37f56 commit c29a2e2

File tree

17 files changed

+479
-141
lines changed

17 files changed

+479
-141
lines changed

connectivity/FEATURE_BLE/include/ble/SecurityManager.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ class SecurityManager
247247
// Pairing
248248
//
249249

250+
#if BLE_ROLE_PERIPHERAL
250251
/**
251252
* Request application to accept or reject pairing. Application should respond by
252253
* calling the appropriate function: acceptPairingRequest or cancelPairingRequest
@@ -256,6 +257,7 @@ class SecurityManager
256257
virtual void pairingRequest(ble::connection_handle_t connectionHandle) {
257258
(void)connectionHandle;
258259
}
260+
#endif // BLE_ROLE_PERIPHERAL
259261

260262
/**
261263
* Indicate to the application that pairing has completed.
@@ -327,6 +329,7 @@ class SecurityManager
327329
(void)passkey;
328330
}
329331

332+
#if BLE_FEATURE_SECURE_CONNECTIONS
330333
/**
331334
* Indicate to the application that a confirmation is required. This is used
332335
* when the device does not have a keyboard but has a yes/no button. The device
@@ -339,6 +342,7 @@ class SecurityManager
339342
virtual void confirmationRequest(ble::connection_handle_t connectionHandle) {
340343
(void)connectionHandle;
341344
}
345+
#endif // BLE_FEATURE_SECURE_CONNECTIONS
342346

343347
/**
344348
* Indicate to the application that a passkey is required. The application should
@@ -350,6 +354,7 @@ class SecurityManager
350354
(void)connectionHandle;
351355
}
352356

357+
#if BLE_FEATURE_SECURE_CONNECTIONS
353358
/**
354359
* Notify the application that a key was pressed by the peer during passkey entry.
355360
*
@@ -360,6 +365,7 @@ class SecurityManager
360365
(void)connectionHandle;
361366
(void)keypress;
362367
}
368+
#endif // BLE_FEATURE_SECURE_CONNECTIONS
363369

364370
/**
365371
* Indicate to the application it needs to return legacy pairing OOB to the stack.
@@ -402,6 +408,7 @@ class SecurityManager
402408
// Keys
403409
//
404410

411+
#if BLE_FEATURE_SIGNING
405412
/**
406413
* Deliver the signing key to the application.
407414
*
@@ -414,6 +421,8 @@ class SecurityManager
414421
(void)csrk;
415422
(void)authenticated;
416423
}
424+
#endif // BLE_FEATURE_SIGNING
425+
417426
/**
418427
* Prevent polymorphic deletion and avoid unnecessary virtual destructor
419428
* as the SecurityManager class will never delete the instance it contains.
@@ -526,6 +535,7 @@ class SecurityManager
526535
// Pairing
527536
//
528537

538+
#if BLE_ROLE_CENTRAL
529539
/**
530540
* Request pairing with the peer. Called by the master.
531541
* @note Slave can call requestAuthentication or setLinkEncryption to achieve security.
@@ -534,7 +544,9 @@ class SecurityManager
534544
* @return BLE_ERROR_NONE or appropriate error code indicating the failure reason.
535545
*/
536546
ble_error_t requestPairing(ble::connection_handle_t connectionHandle);
547+
#endif // BLE_ROLE_CENTRAL
537548

549+
#if BLE_ROLE_PERIPHERAL
538550
/**
539551
* Accept the pairing request. Called as a result of pairingRequest being called
540552
* on the event handler.
@@ -543,6 +555,7 @@ class SecurityManager
543555
* @return BLE_ERROR_NONE or appropriate error code indicating the failure reason.
544556
*/
545557
ble_error_t acceptPairingRequest(ble::connection_handle_t connectionHandle);
558+
#endif // BLE_ROLE_PERIPHERAL
546559

547560
/**
548561
* Reject pairing request if the local device is the slave or cancel an outstanding
@@ -577,6 +590,7 @@ class SecurityManager
577590
// Feature support
578591
//
579592

593+
#if BLE_FEATURE_SECURE_CONNECTIONS
580594
/**
581595
* Allow of disallow the use of legacy pairing in case the application only wants
582596
* to force the use of Secure Connections. If legacy pairing is disallowed and either
@@ -594,6 +608,7 @@ class SecurityManager
594608
* @return BLE_ERROR_NONE or appropriate error code indicating the failure reason.
595609
*/
596610
ble_error_t getSecureConnectionsSupport(bool *enabled);
611+
#endif // BLE_FEATURE_SECURE_CONNECTIONS
597612

598613
////////////////////////////////////////////////////////////////////////////
599614
// Security settings
@@ -766,6 +781,7 @@ class SecurityManager
766781
*/
767782
ble_error_t setOOBDataUsage(ble::connection_handle_t connectionHandle, bool useOOB, bool OOBProvidesMITM = true);
768783

784+
#if BLE_FEATURE_SECURE_CONNECTIONS
769785
/**
770786
* Report to the stack if the passkey matches or not. Used during pairing to provide MITM protection.
771787
*
@@ -774,6 +790,7 @@ class SecurityManager
774790
* @return BLE_ERROR_NONE or appropriate error code indicating the failure reason.
775791
*/
776792
ble_error_t confirmationEntered(ble::connection_handle_t connectionHandle, bool confirmation);
793+
#endif // BLE_FEATURE_SECURE_CONNECTIONS
777794

778795
/**
779796
* Supply the stack with the user entered passkey.
@@ -784,6 +801,7 @@ class SecurityManager
784801
*/
785802
ble_error_t passkeyEntered(ble::connection_handle_t connectionHandle, Passkey_t passkey);
786803

804+
#if BLE_FEATURE_SECURE_CONNECTIONS
787805
/**
788806
* Send a notification to the peer that the user pressed a key on the local device.
789807
* @note This will only be delivered if the keypress notifications have been enabled during pairing.
@@ -793,6 +811,7 @@ class SecurityManager
793811
* @return BLE_ERROR_NONE or appropriate error code indicating the failure reason.
794812
*/
795813
ble_error_t sendKeypressNotification(ble::connection_handle_t connectionHandle, ble::Keypress_t keypress);
814+
#endif // BLE_FEATURE_SECURE_CONNECTIONS
796815

797816
/**
798817
* Supply the stack with the OOB data for legacy connections.
@@ -803,6 +822,7 @@ class SecurityManager
803822
*/
804823
ble_error_t legacyPairingOobReceived(const ble::address_t *address, const ble::oob_tk_t *tk);
805824

825+
#if BLE_FEATURE_SECURE_CONNECTIONS
806826
/**
807827
* Supply the stack with the OOB data for secure connections.
808828
*
@@ -813,11 +833,13 @@ class SecurityManager
813833
* @return BLE_ERROR_NONE or appropriate error code indicating the failure reason.
814834
*/
815835
ble_error_t oobReceived(const ble::address_t *address, const ble::oob_lesc_value_t *random, const ble::oob_confirm_t *confirm);
836+
#endif // BLE_FEATURE_SECURE_CONNECTIONS
816837

817838
////////////////////////////////////////////////////////////////////////////
818839
// Keys
819840
//
820841

842+
#if BLE_FEATURE_SIGNING
821843
/**
822844
* Retrieves a signing key through a signingKey event.
823845
* If a signing key is not present, pairing/authentication will be attempted.
@@ -830,6 +852,7 @@ class SecurityManager
830852
* @return BLE_ERROR_NONE or appropriate error code indicating the failure reason.
831853
*/
832854
ble_error_t getSigningKey(ble::connection_handle_t connectionHandle, bool authenticated);
855+
#endif // BLE_FEATURE_SIGNING
833856

834857
////////////////////////////////////////////////////////////////////////////
835858
// Privacy

connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/sources/hci/dual_chip/hci_evt.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ static const hciEvtParse_t hciEvtParseFcnTbl[] =
217217
hciEvtParseLeConnCteReqEnableCmdCmpl,
218218
hciEvtParseLeConnCteRspEnableCmdCmpl,
219219
hciEvtParseLeReadAntennaInfoCmdCmpl,
220+
#if HCI_VER_BT >= HCI_VER_BT_CORE_SPEC_5_2
220221
hciEvtParseLeCisEst,
221222
hciEvtParseLeCisReq,
222223
hciEvtParseDisconnectCmpl,
@@ -235,6 +236,7 @@ static const hciEvtParse_t hciEvtParseFcnTbl[] =
235236
hciEvtParseLeBigSyncLost,
236237
hciEvtParseLeBigTermSyncCmpl,
237238
hciEvtParseLeBigInfoAdvRpt
239+
#endif // HCI_VER_BT_CORE_SPEC_5_2
238240
};
239241

240242
/* HCI event structure length table, indexed by internal callback event value */
@@ -308,6 +310,7 @@ static const uint8_t hciEvtCbackLen[] =
308310
sizeof(hciLeConnCteReqEnableCmdCmplEvt_t),
309311
sizeof(hciLeConnCteRspEnableCmdCmplEvt_t),
310312
sizeof(hciLeReadAntennaInfoCmdCmplEvt_t),
313+
#if HCI_VER_BT >= HCI_VER_BT_CORE_SPEC_5_2
311314
sizeof(HciLeCisEstEvt_t),
312315
sizeof(HciLeCisReqEvt_t),
313316
sizeof(hciDisconnectCmplEvt_t),
@@ -326,6 +329,7 @@ static const uint8_t hciEvtCbackLen[] =
326329
sizeof(HciLeBigSyncLostEvt_t),
327330
sizeof(HciLeBigTermSyncCmplEvt_t),
328331
sizeof(HciLeBigInfoAdvRptEvt_t)
332+
#endif
329333
};
330334

331335
/* Global event statistics. */
@@ -2583,6 +2587,7 @@ void hciEvtProcessCmdCmpl(uint8_t *p, uint8_t len)
25832587
cbackEvt = HCI_LE_PER_ADV_SET_INFO_TRSF_CMD_CMPL_CBACK_EVT;
25842588
break;
25852589

2590+
#if HCI_VER_BT >= HCI_VER_BT_CORE_SPEC_5_2
25862591
case HCI_OPCODE_LE_SET_CIG_PARAMS:
25872592
cbackEvt = HCI_LE_SET_CIG_PARAMS_CMD_CMPL_CBACK_EVT;
25882593
break;
@@ -2618,6 +2623,7 @@ void hciEvtProcessCmdCmpl(uint8_t *p, uint8_t len)
26182623
case HCI_OPCODE_READ_LOCAL_SUP_CONTROLLER_DLY:
26192624
cbackEvt = HCI_READ_LOCAL_SUP_CTR_DLY_CMD_CMPL_CBACK_EVT;
26202625
break;
2626+
#endif
26212627

26222628
default:
26232629
/* test for vendor specific command completion OGF. */
@@ -2851,6 +2857,7 @@ void hciEvtProcessMsg(uint8_t *pEvt)
28512857
cbackEvt = HCI_LE_CTE_REQ_FAILED_CBACK_EVT;
28522858
break;
28532859

2860+
#if HCI_VER_BT >= HCI_VER_BT_CORE_SPEC_5_2
28542861
case HCI_LE_CIS_EST_EVT:
28552862
/* if CIS connection created successfully */
28562863
if (*pEvt == HCI_SUCCESS)
@@ -2888,6 +2895,7 @@ void hciEvtProcessMsg(uint8_t *pEvt)
28882895
case HCI_LE_BIG_INFO_ADV_REPORT_EVT:
28892896
cbackEvt = HCI_LE_BIG_INFO_ADV_REPORT_CBACK_EVT;
28902897
break;
2898+
#endif
28912899

28922900
default:
28932901
break;
@@ -2899,11 +2907,13 @@ void hciEvtProcessMsg(uint8_t *pEvt)
28992907

29002908
/* if disconnect is for CIS connection */
29012909
BYTES_TO_UINT16(handle, (pEvt + 1));
2910+
#if HCI_VER_BT >= HCI_VER_BT_CORE_SPEC_5_2
29022911
if (hciCoreCisByHandle(handle) != NULL)
29032912
{
29042913
cbackEvt = HCI_CIS_DISCONNECT_CMPL_CBACK_EVT;
29052914
}
29062915
else
2916+
#endif
29072917
{
29082918
cbackEvt = HCI_DISCONNECT_CMPL_CBACK_EVT;
29092919
}
@@ -2991,11 +3001,13 @@ void hciEvtProcessMsg(uint8_t *pEvt)
29913001
BYTES_TO_UINT16(handle, (pEvt + 1));
29923002
hciCoreConnClose(handle);
29933003
}
3004+
#if HCI_VER_BT >= HCI_VER_BT_CORE_SPEC_5_2
29943005
else if (cbackEvt == HCI_CIS_DISCONNECT_CMPL_CBACK_EVT)
29953006
{
29963007
BYTES_TO_UINT16(handle, (pEvt + 1));
29973008
hciCoreCisClose(handle);
29983009
}
3010+
#endif
29993011
}
30003012
}
30013013

connectivity/FEATURE_BLE/libraries/cordio_stack/wsf/include/hci_defs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,11 @@ extern "C" {
14211421
#define HCI_VER_BT_CORE_SPEC_5_2 0x0B /*!< Bluetooth core specification 5.2 */
14221422
/**@}*/
14231423

1424+
#ifndef HCI_VER_BT
1425+
#define HCI_VER_BT HCI_VER_BT_CORE_SPEC_5_1
1426+
#endif
1427+
1428+
14241429
/** \name Parameter lengths
14251430
*
14261431
*/

connectivity/FEATURE_BLE/source/SecurityManager.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,19 @@ ble_error_t SecurityManager::generateWhitelistFromBondTable(::ble::whitelist_t *
5757
return impl->generateWhitelistFromBondTable(whitelist);
5858
}
5959

60+
#if BLE_ROLE_CENTRAL
6061
ble_error_t SecurityManager::requestPairing(ble::connection_handle_t connectionHandle)
6162
{
6263
return impl->requestPairing(connectionHandle);
6364
}
65+
#endif
6466

67+
#if BLE_ROLE_PERIPHERAL
6568
ble_error_t SecurityManager::acceptPairingRequest(ble::connection_handle_t connectionHandle)
6669
{
6770
return impl->acceptPairingRequest(connectionHandle);
6871
}
72+
#endif
6973

7074
ble_error_t SecurityManager::cancelPairingRequest(ble::connection_handle_t connectionHandle)
7175
{
@@ -82,6 +86,7 @@ ble_error_t SecurityManager::getPeerIdentity(ble::connection_handle_t connection
8286
return impl->getPeerIdentity(connectionHandle);
8387
}
8488

89+
#if BLE_FEATURE_SECURE_CONNECTIONS
8590
ble_error_t SecurityManager::allowLegacyPairing(bool allow)
8691
{
8792
return impl->allowLegacyPairing(allow);
@@ -91,6 +96,7 @@ ble_error_t SecurityManager::getSecureConnectionsSupport(bool *enabled)
9196
{
9297
return impl->getSecureConnectionsSupport(enabled);
9398
}
99+
#endif
94100

95101
ble_error_t SecurityManager::setIoCapability(SecurityIOCapabilities_t iocaps)
96102
{
@@ -162,35 +168,43 @@ ble_error_t SecurityManager::setOOBDataUsage(ble::connection_handle_t connection
162168
return impl->setOOBDataUsage(connectionHandle, useOOB, OOBProvidesMITM);
163169
}
164170

171+
#if BLE_FEATURE_SECURE_CONNECTIONS
165172
ble_error_t SecurityManager::confirmationEntered(ble::connection_handle_t connectionHandle, bool confirmation)
166173
{
167174
return impl->confirmationEntered(connectionHandle, confirmation);
168175
}
176+
#endif // BLE_FEATURE_SECURE_CONNECTIONS
169177

170178
ble_error_t SecurityManager::passkeyEntered(ble::connection_handle_t connectionHandle, Passkey_t passkey)
171179
{
172180
return impl->passkeyEntered(connectionHandle, passkey);
173181
}
174182

183+
#if BLE_FEATURE_SECURE_CONNECTIONS
175184
ble_error_t SecurityManager::sendKeypressNotification(ble::connection_handle_t connectionHandle, ble::Keypress_t keypress)
176185
{
177186
return impl->sendKeypressNotification(connectionHandle, keypress);
178187
}
188+
#endif // BLE_FEATURE_SECURE_CONNECTIONS
179189

180190
ble_error_t SecurityManager::legacyPairingOobReceived(const ble::address_t *address, const ble::oob_tk_t *tk)
181191
{
182192
return impl->legacyPairingOobReceived(address, tk);
183193
}
184194

195+
#if BLE_FEATURE_SECURE_CONNECTIONS
185196
ble_error_t SecurityManager::oobReceived(const ble::address_t *address, const ble::oob_lesc_value_t *random, const ble::oob_confirm_t *confirm)
186197
{
187198
return impl->oobReceived(address, random, confirm);
188199
}
200+
#endif // BLE_FEATURE_SECURE_CONNECTIONS
189201

202+
#if BLE_FEATURE_SIGNING
190203
ble_error_t SecurityManager::getSigningKey(ble::connection_handle_t connectionHandle, bool authenticated)
191204
{
192205
return impl->getSigningKey(connectionHandle, authenticated);
193206
}
207+
#endif // BLE_FEATURE_SIGNING
194208

195209
#if BLE_FEATURE_PRIVACY
196210
ble_error_t SecurityManager::setPrivateAddressTimeout(

connectivity/FEATURE_BLE/source/cordio/source/BLEInstanceBaseImpl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ void BLEInstanceBase::stack_handler(wsfEventMask_t event, wsfMsgHdr_t *msg)
414414

415415
void BLEInstanceBase::device_manager_cb(dmEvt_t *dm_event)
416416
{
417+
#if BLE_FEATURE_CONNECTABLE
417418
if (dm_event->hdr.status == HCI_SUCCESS && dm_event->hdr.event == DM_CONN_DATA_LEN_CHANGE_IND) {
418419
// this event can only happen after a connection has been established therefore gap is present
419420
ble::PalGapEventHandler *handler;
@@ -427,6 +428,7 @@ void BLEInstanceBase::device_manager_cb(dmEvt_t *dm_event)
427428
}
428429
return;
429430
}
431+
#endif
430432

431433
BLEInstanceBase::deviceInstance().stack_handler(0, &dm_event->hdr);
432434
}

0 commit comments

Comments
 (0)