Skip to content

RDKEMW-13607: merge pair code with mac hash methods#191

Open
egalla204 wants to merge 4 commits intodevelopfrom
feature/RDKEMW-13607_ctrlm_standardize_pairing_methods
Open

RDKEMW-13607: merge pair code with mac hash methods#191
egalla204 wants to merge 4 commits intodevelopfrom
feature/RDKEMW-13607_ctrlm_standardize_pairing_methods

Conversation

@egalla204
Copy link
Copy Markdown
Contributor

No description provided.

@egalla204 egalla204 requested a review from a team as a code owner April 2, 2026 01:18
Copilot AI review requested due to automatic review settings April 2, 2026 01:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR unifies BLE targeted pairing so the system uses a single “pair with code” path for both advertising-name-based pairing and MAC-hash-based pairing, removing the separate MAC-hash pairing APIs and the need to pass the originating IR key code through IPC.

Changes:

  • Remove pairWithMacHash / startPairingWithMacHash / startWithMacHash APIs and route all targeted pairing through the existing “pair with code” flow.
  • Update the BLE model config parsing to use a new advertisingNames object (required regexPairing, optional targeted pairing format + reconnect regex).
  • Simplify IPC for Main_StartPairWithCode by removing the key_code field.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/ctrlm_ir_controller.cpp Stops sending key_code in the pair-with-code request and only forwards the pairing byte.
src/ble/hal/configsettings/configmodelsettings.cpp Parses new advertisingNames config structure; adjusts optional/required behavior and logging.
src/ble/hal/blercu/blercupairingstatemachine.h Removes startWithMacHash() declaration.
src/ble/hal/blercu/blercupairingstatemachine.cpp Merges MAC-hash and code pairing behavior into startWithCode() and keeps MAC-hash matching as a fallback.
src/ble/hal/blercu/blercucontroller.h Removes startPairingWithMacHash() from the controller interface.
src/ble/hal/blercu/blercucontroller.cpp Removes the controller implementation of MAC-hash pairing.
src/ble/hal/blercu/blercucontroller_p.h Removes override for startPairingWithMacHash().
src/ble/ctrlm_ble_rcu_interface.h Removes pairWithMacHash() from the BLE RCU interface.
src/ble/ctrlm_ble_rcu_interface.cpp Removes pairWithMacHash() implementation; pairing is done via pairWithCode().
src/ble/ctrlm_ble_network.cpp Always calls pairWithCode() for targeted pairing requests.
include/ctrlm_ipc.h Removes key_code from ctrlm_iarm_call_StartPairWithCode_params_t.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +157 to +160
// advertisingNames.optional array
json_t *optionalNames = json_object_get(advertisingNamesObj, "optional");
if (!optionalNames || !json_is_object(optionalNames)) {
XLOGD_INFO("missing or invalid 'optionalNames' field, not fatal, continuing...");
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "advertisingNames.optional array" but the code treats advertisingNames.optional as a JSON object (json_is_object). Also, the log message refers to "optionalNames" rather than the actual key path "advertisingNames.optional", which makes config/debugging harder. Please align the comment + log messages with the real JSON shape and key name.

Suggested change
// advertisingNames.optional array
json_t *optionalNames = json_object_get(advertisingNamesObj, "optional");
if (!optionalNames || !json_is_object(optionalNames)) {
XLOGD_INFO("missing or invalid 'optionalNames' field, not fatal, continuing...");
// advertisingNames.optional object
json_t *optionalNames = json_object_get(advertisingNamesObj, "optional");
if (!optionalNames || !json_is_object(optionalNames)) {
XLOGD_INFO("missing or invalid 'advertisingNames.optional' field, not fatal, continuing...");

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings April 3, 2026 16:20
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

XLOGD_INFO("Pairing and reconnect advertising name regex <%s>", json_string_value(obj));


// advertisingNames.optional array
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says advertisingNames.optional is an "array", but the parser expects an object (json_is_object). Please update the comment to match the actual schema to avoid confusion for future config edits.

Suggested change
// advertisingNames.optional array
// advertisingNames.optional object

Copilot uses AI. Check for mistakes.
Comment on lines 314 to +320
std::string servicesRequiredStr;
for (const auto& service : m_servicesRequired) {
servicesRequiredStr += service + ", ";
}
servicesRequiredStr = servicesRequiredStr.substr(0, servicesRequiredStr.length() - 2); // Remove the trailing comma and space

XLOGD_DEBUG("m_servicesRequired = <%s>", servicesRequiredStr.c_str());
XLOGD_INFO("Services required = <%s>", servicesRequiredStr.c_str());
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

servicesRequiredStr is always trimmed with substr(...length() - 2) even when m_servicesRequired is empty (e.g., config provides an empty services.required array). This relies on unsigned wraparound and makes the intent unclear. Please only trim when the string has a trailing delimiter (or build the joined string without appending a trailing ", ").

Copilot uses AI. Check for mistakes.
Comment on lines +274 to 278
// the pairing could be either the mac hash or the code embedded in the name,
// so store both for use when processing found devices
m_pairingCode = pairingCode;
m_pairingMacHash = -1;
m_pairingMacHash = pairingCode;

Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

startWithCode() now sets m_pairingMacHash = pairingCode, which enables the MAC-hash pairing path for every targeted pairing request. In processDevice(), a MAC-hash match does not validate the device name/type, so any nearby BLE device with a colliding 8-bit hash could be treated as a pairing target. Consider tightening the MAC-hash path (e.g., additionally require the name to match one of the supported remote regexes, or only enable hash matching when the request explicitly indicates MAC-hash mode).

Copilot uses AI. Check for mistakes.
Comment on lines 778 to 805
// Iterate through list of supported remotes and compare names
vector<regex>::const_iterator it_name = m_targetedPairingNames.begin();
for (; it_name != m_targetedPairingNames.end(); ++it_name) {
if (std::regex_match(name.c_str(), *it_name)) {
XLOGD_INFO("Device (%s, %s) has a name targeted for pairing!",
XLOGD_INFO("Device (%s, %s) name has a match in the pairing name target list!",
name.c_str(), address.toString().c_str());
break;
}
}

if (it_name == m_targetedPairingNames.end()) {
// Device not found through conventional means, see if we are pairing based on MAC hash
// Because if we are pairing based on MAC hash, m_targetedPairingNames is first cleared
XLOGD_INFO("Device (%s, %s) name not in name target list, checking other pairing methods...", name.c_str(), address.toString().c_str());

if (m_pairingMacHash != -1) {
// Device not found through name match, see if there is a MAC hash match
// Check if MAC hash matches
int macHash = 0;
for (int i = 0; i < 6; ++i) {
macHash += (int)address[i];
}
macHash &= 0xFF;
XLOGD_INFO("Pairing based on MAC hash, requested MAC hash = 0x%02X, this device = 0x%02X (%s, %s)",
m_pairingMacHash, macHash, name.c_str(), address.toString().c_str());
if (m_pairingMacHash != macHash) {
XLOGD_INFO("Device (%s, %s) MAC hash (0x%02X) does not match requested MAC hash (0x%02X), ignoring... ",
name.c_str(), address.toString().c_str(), macHash, m_pairingMacHash);
return;
} else {
XLOGD_INFO("Device (%s, %s) MAC hash matches!", name.c_str(), address.toString().c_str());
}
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

processDevice() logs at INFO for common non-target cases (name not in list, MAC hash mismatch, MAC list mismatch, etc.). During discovery this can execute for many devices and can flood logs / impact performance. Please downgrade the per-device non-target/mismatch logs to DEBUG (keep INFO for actual targets / state changes).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants