RDKEMW-13607: merge pair code with mac hash methods#191
RDKEMW-13607: merge pair code with mac hash methods#191
Conversation
There was a problem hiding this comment.
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/startWithMacHashAPIs and route all targeted pairing through the existing “pair with code” flow. - Update the BLE model config parsing to use a new
advertisingNamesobject (requiredregexPairing, optional targeted pairing format + reconnect regex). - Simplify IPC for
Main_StartPairWithCodeby removing thekey_codefield.
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.
| // 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..."); |
There was a problem hiding this comment.
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.
| // 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..."); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
| // advertisingNames.optional array | |
| // advertisingNames.optional object |
| 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()); |
There was a problem hiding this comment.
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 ", ").
| // 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; | ||
|
|
There was a problem hiding this comment.
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).
| // 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()); | ||
| } |
There was a problem hiding this comment.
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).
No description provided.