Skip to content

Ble conditional compilation #13811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions connectivity/FEATURE_BLE/include/ble/SecurityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ class SecurityManager
// Pairing
//

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

/**
* Indicate to the application that pairing has completed.
Expand Down Expand Up @@ -327,6 +329,7 @@ class SecurityManager
(void)passkey;
}

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

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

#if BLE_FEATURE_SECURE_CONNECTIONS
/**
* Notify the application that a key was pressed by the peer during passkey entry.
*
Expand All @@ -360,6 +365,7 @@ class SecurityManager
(void)connectionHandle;
(void)keypress;
}
#endif // BLE_FEATURE_SECURE_CONNECTIONS

/**
* Indicate to the application it needs to return legacy pairing OOB to the stack.
Expand Down Expand Up @@ -402,6 +408,7 @@ class SecurityManager
// Keys
//

#if BLE_FEATURE_SIGNING
/**
* Deliver the signing key to the application.
*
Expand All @@ -414,6 +421,8 @@ class SecurityManager
(void)csrk;
(void)authenticated;
}
#endif // BLE_FEATURE_SIGNING

/**
* Prevent polymorphic deletion and avoid unnecessary virtual destructor
* as the SecurityManager class will never delete the instance it contains.
Expand Down Expand Up @@ -526,6 +535,7 @@ class SecurityManager
// Pairing
//

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

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

/**
* Reject pairing request if the local device is the slave or cancel an outstanding
Expand Down Expand Up @@ -577,6 +590,7 @@ class SecurityManager
// Feature support
//

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

////////////////////////////////////////////////////////////////////////////
// Security settings
Expand Down Expand Up @@ -766,6 +781,7 @@ class SecurityManager
*/
ble_error_t setOOBDataUsage(ble::connection_handle_t connectionHandle, bool useOOB, bool OOBProvidesMITM = true);

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

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

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

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

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

////////////////////////////////////////////////////////////////////////////
// Keys
//

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

////////////////////////////////////////////////////////////////////////////
// Privacy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ static const hciEvtParse_t hciEvtParseFcnTbl[] =
hciEvtParseLeConnCteReqEnableCmdCmpl,
hciEvtParseLeConnCteRspEnableCmdCmpl,
hciEvtParseLeReadAntennaInfoCmdCmpl,
#if HCI_VER_BT >= HCI_VER_BT_CORE_SPEC_5_2
hciEvtParseLeCisEst,
hciEvtParseLeCisReq,
hciEvtParseDisconnectCmpl,
Expand All @@ -235,6 +236,7 @@ static const hciEvtParse_t hciEvtParseFcnTbl[] =
hciEvtParseLeBigSyncLost,
hciEvtParseLeBigTermSyncCmpl,
hciEvtParseLeBigInfoAdvRpt
#endif // HCI_VER_BT_CORE_SPEC_5_2
};

/* HCI event structure length table, indexed by internal callback event value */
Expand Down Expand Up @@ -308,6 +310,7 @@ static const uint8_t hciEvtCbackLen[] =
sizeof(hciLeConnCteReqEnableCmdCmplEvt_t),
sizeof(hciLeConnCteRspEnableCmdCmplEvt_t),
sizeof(hciLeReadAntennaInfoCmdCmplEvt_t),
#if HCI_VER_BT >= HCI_VER_BT_CORE_SPEC_5_2
sizeof(HciLeCisEstEvt_t),
sizeof(HciLeCisReqEvt_t),
sizeof(hciDisconnectCmplEvt_t),
Expand All @@ -326,6 +329,7 @@ static const uint8_t hciEvtCbackLen[] =
sizeof(HciLeBigSyncLostEvt_t),
sizeof(HciLeBigTermSyncCmplEvt_t),
sizeof(HciLeBigInfoAdvRptEvt_t)
#endif
};

/* Global event statistics. */
Expand Down Expand Up @@ -2583,6 +2587,7 @@ void hciEvtProcessCmdCmpl(uint8_t *p, uint8_t len)
cbackEvt = HCI_LE_PER_ADV_SET_INFO_TRSF_CMD_CMPL_CBACK_EVT;
break;

#if HCI_VER_BT >= HCI_VER_BT_CORE_SPEC_5_2
case HCI_OPCODE_LE_SET_CIG_PARAMS:
cbackEvt = HCI_LE_SET_CIG_PARAMS_CMD_CMPL_CBACK_EVT;
break;
Expand Down Expand Up @@ -2618,6 +2623,7 @@ void hciEvtProcessCmdCmpl(uint8_t *p, uint8_t len)
case HCI_OPCODE_READ_LOCAL_SUP_CONTROLLER_DLY:
cbackEvt = HCI_READ_LOCAL_SUP_CTR_DLY_CMD_CMPL_CBACK_EVT;
break;
#endif

default:
/* test for vendor specific command completion OGF. */
Expand Down Expand Up @@ -2851,6 +2857,7 @@ void hciEvtProcessMsg(uint8_t *pEvt)
cbackEvt = HCI_LE_CTE_REQ_FAILED_CBACK_EVT;
break;

#if HCI_VER_BT >= HCI_VER_BT_CORE_SPEC_5_2
case HCI_LE_CIS_EST_EVT:
/* if CIS connection created successfully */
if (*pEvt == HCI_SUCCESS)
Expand Down Expand Up @@ -2888,6 +2895,7 @@ void hciEvtProcessMsg(uint8_t *pEvt)
case HCI_LE_BIG_INFO_ADV_REPORT_EVT:
cbackEvt = HCI_LE_BIG_INFO_ADV_REPORT_CBACK_EVT;
break;
#endif

default:
break;
Expand All @@ -2899,11 +2907,13 @@ void hciEvtProcessMsg(uint8_t *pEvt)

/* if disconnect is for CIS connection */
BYTES_TO_UINT16(handle, (pEvt + 1));
#if HCI_VER_BT >= HCI_VER_BT_CORE_SPEC_5_2
if (hciCoreCisByHandle(handle) != NULL)
{
cbackEvt = HCI_CIS_DISCONNECT_CMPL_CBACK_EVT;
}
else
#endif
{
cbackEvt = HCI_DISCONNECT_CMPL_CBACK_EVT;
}
Expand Down Expand Up @@ -2991,11 +3001,13 @@ void hciEvtProcessMsg(uint8_t *pEvt)
BYTES_TO_UINT16(handle, (pEvt + 1));
hciCoreConnClose(handle);
}
#if HCI_VER_BT >= HCI_VER_BT_CORE_SPEC_5_2
else if (cbackEvt == HCI_CIS_DISCONNECT_CMPL_CBACK_EVT)
{
BYTES_TO_UINT16(handle, (pEvt + 1));
hciCoreCisClose(handle);
}
#endif
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,11 @@ extern "C" {
#define HCI_VER_BT_CORE_SPEC_5_2 0x0B /*!< Bluetooth core specification 5.2 */
/**@}*/

#ifndef HCI_VER_BT
#define HCI_VER_BT HCI_VER_BT_CORE_SPEC_5_1
#endif


/** \name Parameter lengths
*
*/
Expand Down
14 changes: 14 additions & 0 deletions connectivity/FEATURE_BLE/source/SecurityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,19 @@ ble_error_t SecurityManager::generateWhitelistFromBondTable(::ble::whitelist_t *
return impl->generateWhitelistFromBondTable(whitelist);
}

#if BLE_ROLE_CENTRAL
ble_error_t SecurityManager::requestPairing(ble::connection_handle_t connectionHandle)
{
return impl->requestPairing(connectionHandle);
}
#endif

#if BLE_ROLE_PERIPHERAL
ble_error_t SecurityManager::acceptPairingRequest(ble::connection_handle_t connectionHandle)
{
return impl->acceptPairingRequest(connectionHandle);
}
#endif

ble_error_t SecurityManager::cancelPairingRequest(ble::connection_handle_t connectionHandle)
{
Expand All @@ -82,6 +86,7 @@ ble_error_t SecurityManager::getPeerIdentity(ble::connection_handle_t connection
return impl->getPeerIdentity(connectionHandle);
}

#if BLE_FEATURE_SECURE_CONNECTIONS
ble_error_t SecurityManager::allowLegacyPairing(bool allow)
{
return impl->allowLegacyPairing(allow);
Expand All @@ -91,6 +96,7 @@ ble_error_t SecurityManager::getSecureConnectionsSupport(bool *enabled)
{
return impl->getSecureConnectionsSupport(enabled);
}
#endif

ble_error_t SecurityManager::setIoCapability(SecurityIOCapabilities_t iocaps)
{
Expand Down Expand Up @@ -162,35 +168,43 @@ ble_error_t SecurityManager::setOOBDataUsage(ble::connection_handle_t connection
return impl->setOOBDataUsage(connectionHandle, useOOB, OOBProvidesMITM);
}

#if BLE_FEATURE_SECURE_CONNECTIONS
ble_error_t SecurityManager::confirmationEntered(ble::connection_handle_t connectionHandle, bool confirmation)
{
return impl->confirmationEntered(connectionHandle, confirmation);
}
#endif // BLE_FEATURE_SECURE_CONNECTIONS

ble_error_t SecurityManager::passkeyEntered(ble::connection_handle_t connectionHandle, Passkey_t passkey)
{
return impl->passkeyEntered(connectionHandle, passkey);
}

#if BLE_FEATURE_SECURE_CONNECTIONS
ble_error_t SecurityManager::sendKeypressNotification(ble::connection_handle_t connectionHandle, ble::Keypress_t keypress)
{
return impl->sendKeypressNotification(connectionHandle, keypress);
}
#endif // BLE_FEATURE_SECURE_CONNECTIONS

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

#if BLE_FEATURE_SECURE_CONNECTIONS
ble_error_t SecurityManager::oobReceived(const ble::address_t *address, const ble::oob_lesc_value_t *random, const ble::oob_confirm_t *confirm)
{
return impl->oobReceived(address, random, confirm);
}
#endif // BLE_FEATURE_SECURE_CONNECTIONS

#if BLE_FEATURE_SIGNING
ble_error_t SecurityManager::getSigningKey(ble::connection_handle_t connectionHandle, bool authenticated)
{
return impl->getSigningKey(connectionHandle, authenticated);
}
#endif // BLE_FEATURE_SIGNING

#if BLE_FEATURE_PRIVACY
ble_error_t SecurityManager::setPrivateAddressTimeout(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ void BLEInstanceBase::stack_handler(wsfEventMask_t event, wsfMsgHdr_t *msg)

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

BLEInstanceBase::deviceInstance().stack_handler(0, &dm_event->hdr);
}
Expand Down
Loading