Skip to content
Open
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
1 change: 0 additions & 1 deletion include/ctrlm_ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,6 @@ typedef struct {
typedef struct {
unsigned char api_revision; ///< Revision of this API
ctrlm_network_id_t network_id; ///< IN - Identifier of network
unsigned int key_code; ///< IN - Key code from device
unsigned int pair_code; ///< IN - Pairing code from device
ctrlm_iarm_call_result_t result; ///< OUT - return code of the operation
} ctrlm_iarm_call_StartPairWithCode_params_t;
Expand Down
30 changes: 7 additions & 23 deletions src/ble/ctrlm_ble_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ void ctrlm_obj_network_ble_t::req_process_start_pairing(void *data, int size) {
dqm->params->set_result(CTRLM_IARM_CALL_RESULT_SUCCESS, network_id_get());
}
} else {
XLOGD_INFO("Starting pairing with a list of mac addresses! Pairing with first available...");
XLOGD_INFO("Starting pairing with a list of MAC addresses! Pairing with first available...");
if(!ble_rcu_interface_->pairWithMacAddrs(dqm->params->ieee_address_list)) {
XLOGD_ERROR("failed to start BLE remote scan");
dqm->params->set_result(CTRLM_IARM_CALL_RESULT_ERROR, network_id_get());
Expand Down Expand Up @@ -740,29 +740,13 @@ void ctrlm_obj_network_ble_t::req_process_pair_with_code(void *data, int size) {
XLOGD_FATAL("Network is not ready!");
} else {
if (ble_rcu_interface_) {

if (dqm->params->key_code == KEY_BLUETOOTH) {
// KEY_BLUETOOTH means the pairing code is random 3 digit code embedded in the name
// so use pairWithCode
if (!ble_rcu_interface_->pairWithCode(dqm->params->pair_code)) {
// don't log error here, pairWithCode will handle printing the error. We do
// this because there is an error that is merely a warning that we don't want
// logged because it only confuses those analyzing the logs.
// XLOGD_ERROR("failed to start pairing with code");
} else {
dqm->params->result = CTRLM_IARM_CALL_RESULT_SUCCESS;
}
if (!ble_rcu_interface_->pairWithCode(dqm->params->pair_code)) {
// don't log error here, pairWithCode will handle printing the error. We do
// this because there is an error that is merely a warning that we don't want
// logged because it only confuses those analyzing the logs.
// XLOGD_ERROR("failed to start pairing with code");
} else {
// if key_code is either not available or KEY_CONNECT, it means the pairing code is a
// hash of the MAC, so use pairWithMacHash
if (!ble_rcu_interface_->pairWithMacHash(dqm->params->pair_code)) {
// don't log error here, pairWithMacHash will handle printing the error. We do
// this because there is an error that is merely a warning that we don't want
// logged because it only confuses those analyzing the logs.
// XLOGD_ERROR("failed to start pairing with MAC hash");
} else {
dqm->params->result = CTRLM_IARM_CALL_RESULT_SUCCESS;
}
dqm->params->result = CTRLM_IARM_CALL_RESULT_SUCCESS;
}
}
}
Expand Down
25 changes: 0 additions & 25 deletions src/ble/ctrlm_ble_rcu_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,31 +697,6 @@ bool ctrlm_ble_rcu_interface_t::pairWithCode(unsigned int code)
XLOGD_ERROR("controller failed to start pairing, %s: %s", error.name().c_str(), error.message().c_str());
}
return false;
} else {
XLOGD_INFO("started pairing with code %hhu", code);
}
return true;
}

bool ctrlm_ble_rcu_interface_t::pairWithMacHash(unsigned int code)
{
if (!m_controller) {
XLOGD_ERROR("m_controller is NULL!!!");
return false;
}

if (!m_controller->startPairingWithMacHash((uint8_t) code)) {
BleRcuError error = m_controller->lastError();

// Remote will continually send out IR pairing signals until the BLE pair request
// has been received. This means that the "Already in pairing state" error is normal.
// Let's omit this error print because it only serves to confuse those analyzing the logs.
if (error.message() != "Already in pairing state") {
XLOGD_ERROR("controller failed to start pairing, %s: %s", error.name().c_str(), error.message().c_str());
}
return false;
} else {
XLOGD_INFO("started pairing with MAC hash 0x%X", code);
}
return true;
}
Expand Down
1 change: 0 additions & 1 deletion src/ble/ctrlm_ble_rcu_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class ctrlm_ble_rcu_interface_t
void handleDeepsleep(bool wakingUp);

bool pairWithCode(unsigned int code);
bool pairWithMacHash(unsigned int code);
bool pairWithMacAddrs(const std::vector<uint64_t> &macAddrList);
bool pairAutoWithTimeout(int timeoutMs);
bool pairCancel();
Expand Down
59 changes: 2 additions & 57 deletions src/ble/hal/blercu/blercucontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ bool BleRcuControllerImpl::startPairingAutoWithTimeout(int timeoutMs)
bool BleRcuControllerImpl::startPairingWithCode(uint8_t pairingCode)
{
if (m_pairingStateMachine.isRunning()) {
if (m_pairingStateMachine.isAutoPairing()) {
if (m_pairingStateMachine.isScanningForAutoPair()) {

XLOGD_WARN("received targeted pairing request in auto pair mode, cancelling auto pair first...");

Expand Down Expand Up @@ -271,61 +271,6 @@ bool BleRcuControllerImpl::startPairingWithCode(uint8_t pairingCode)
return true;
}

// -----------------------------------------------------------------------------
/*!
\fn bool BleRcuController::startPairingWithMacHash(uint8_t macHash)

Attempts to start the pairing procedure looking for a device that has
a MAC address matching the supplied MAC hash.

The MAC hash is calculated by adding all the bytes of the MAC address
together, and masking with 0xFF.
e.g., MAC = AA:BB:CC:DD:EE:FF, hash = (AA+BB+CC+DD+EE+FF) & 0xFF

If the controller is currently in pairing mode this method will fail and
return \c false. If the bluetooth adaptor is not available or not powered
then this function will also fail and return \c false.

If \c false is returned use BleRcuController::lastError() to get the failure
reason.

\note This object doesn't actually run the pairing procedure, instead it
just starts and stops the \l{BleRcuPairingStateMachine} object.

\see cancelPairing(), isPairing() & pairingCode()
*/
bool BleRcuControllerImpl::startPairingWithMacHash(uint8_t macHash)
{
if (m_pairingStateMachine.isRunning()) {
if (m_pairingStateMachine.isAutoPairing()) {

XLOGD_WARN("received targeted pairing request in auto pair mode, cancelling auto pair first...");

m_ignorePairingFailure = true;
m_pairingStateMachine.stop();

m_lastError = BleRcuError(BleRcuError::Busy, "Cancelling auto pair operation, send another request.");
} else {
XLOGD_DEBUG("requested pairing while currently running a pairing operation, ignoring request");
m_lastError = BleRcuError(BleRcuError::Busy, "Already in pairing state");
}
return false;
}

// check that the manager has powered on the adapter, without this we
// obviously can't scan / pair / etc. The only time the adaptor should
// (legitimately) be unavailable is right at start-up
if (!m_adapter->isAvailable() || !m_adapter->isPowered()) {
m_lastError = BleRcuError(BleRcuError::General, "Adaptor not available or not powered");
return false;
}

// start the pairing process
m_pairingStateMachine.startWithMacHash(macHash);

return true;
}

// -----------------------------------------------------------------------------
/*!
\fn bool BleRcuController::startPairingWithList(std::vector<BleAddress> macAddrList)
Expand All @@ -348,7 +293,7 @@ bool BleRcuControllerImpl::startPairingWithMacHash(uint8_t macHash)
bool BleRcuControllerImpl::startPairingWithList(const std::vector<BleAddress> &macAddrList)
{
if (m_pairingStateMachine.isRunning()) {
if (m_pairingStateMachine.isAutoPairing()) {
if (m_pairingStateMachine.isScanningForAutoPair()) {

XLOGD_WARN("received targeted pairing request in auto pair mode, cancelling auto pair first...");

Expand Down
1 change: 0 additions & 1 deletion src/ble/hal/blercu/blercucontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class BleRcuController

virtual bool startPairingAutoWithTimeout(int timeoutMs) = 0;
virtual bool startPairingWithCode(uint8_t pairingCode) = 0;
virtual bool startPairingWithMacHash(uint8_t macHash) = 0;
virtual bool startPairingWithList(const std::vector<BleAddress> &macAddrList) = 0;
virtual bool cancelPairing() = 0;

Expand Down
1 change: 0 additions & 1 deletion src/ble/hal/blercu/blercucontroller_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class BleRcuControllerImpl final : public BleRcuController

bool startPairingAutoWithTimeout(int timeoutMs) override;
bool startPairingWithCode(uint8_t pairingCode) override;
bool startPairingWithMacHash(uint8_t macHash) override;
bool startPairingWithList(const std::vector<BleAddress> &macAddrList) override;

bool cancelPairing() override;
Expand Down
Loading
Loading