Skip to content
Open
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
39 changes: 39 additions & 0 deletions src/btrCore.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ int b_rdk_logger_enabled = 0;
#define BTRCORE_REMOTE_OUI_LENGTH 8
#define BTRCORE_AMAZON_OUI_LENGTH 8
#define BTRCORE_GOOGLE_OUI_LENGTH 8
#define BTRCORE_XBOX_GEN3_OUI_LENGTH 8

static char * BTRCORE_REMOTE_OUI_VALUES[] = {
"20:44:41", //LC103
Expand All @@ -96,6 +97,13 @@ static char * BTRCORE_GOOGLE_OUI_VALUES[] = {
"CA:7B:25", //Stadia2TFX-0fa6
NULL
};

static char* BTRCORE_XBOX_GEN3_OUI_VALUES[] = {
"44:16:22", // Microsoft (Xbox Gen3)
"9C:AA:1B", // Microsoft (Xbox Gen3)
NULL
};

/* Local types */
//TODO: Move to a private header
typedef enum _enBTRCoreTaskOp {
Expand Down Expand Up @@ -857,6 +865,24 @@ static BOOLEAN btrCore_IsLunaGamepad(
}
return FALSE;
}

static BOOLEAN
btrCore_IsXboxGen3Gamepad(char* pcAddress) {
unsigned char i;
if (pcAddress == NULL) {
BTRCORELOG_ERROR("Received NULL mac address\n");
return FALSE;
}

for (i = 0; BTRCORE_XBOX_GEN3_OUI_VALUES[i] != NULL; i++) {
if (!strncmp(pcAddress, BTRCORE_XBOX_GEN3_OUI_VALUES[i], BTRCORE_XBOX_GEN3_OUI_LENGTH)) {
BTRCORELOG_DEBUG("Device OUI matches Xbox Gen3 gamepad\n");
return TRUE;
}
}
return FALSE;
}

static BOOLEAN btrCore_IsDeviceRdkRcu(
char * pcAddress,
unsigned short ui16Appearance
Expand Down Expand Up @@ -7113,6 +7139,19 @@ btrCore_BTDeviceStatusUpdateCb (
strncpy(FoundDevice.pcDeviceName, apstBTDeviceInfo->pcName, BD_NAME_LEN);
strncpy(FoundDevice.pcDeviceAddress, apstBTDeviceInfo->pcAddress, BD_NAME_LEN);

/* Xbox Gen3 exception: force immediate UI update with a temporary name */
if (btrCore_IsDevNameSameAsAddress(&FoundDevice) &&
btrCore_IsXboxGen3Gamepad(FoundDevice.pcDeviceAddress)) {
Comment on lines +7142 to +7144
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

PR description says this is for "Debug purpose for coverity", but the diff adds product behavior (new Xbox Gen3 OUI list + forcing device name updates). Please update the PR description to reflect the actual functional change and expected user impact, or gate this logic behind a debug/diagnostic flag if it’s intended to be temporary.

Copilot uses AI. Check for mistakes.
errno_t rc;
rc = strcpy_s(FoundDevice.pcDeviceName,BD_NAME_LEN,"Xbox Wireless Controller");
Copy link
Contributor

Choose a reason for hiding this comment

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

Coverity Issue - Array compared against 0

Comparing an array to null is not useful: ""Xbox Wireless Controller" != NULL", since the test will always evaluate as true.

Medium Impact, CWE-398
NO_EFFECT

How to fix

Was ""Xbox Wireless Controller"" formerly declared as a pointer?

ERR_CHK(rc);

rc = strcpy_s(apstBTDeviceInfo->pcName,BD_NAME_LEN,"Xbox Wireless Controller");
Comment on lines +7146 to +7149
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

In the new Xbox Gen3 block, strcpy_s is called with BD_NAME_LEN as the destination size for both FoundDevice.pcDeviceName and apstBTDeviceInfo->pcName. FoundDevice.pcDeviceName is sized BD_NAME_LEN + 1 and apstBTDeviceInfo->pcName is BT_MAX_STR_LEN, so passing BD_NAME_LEN is an incorrect/needlessly small bound and can turn future string changes into runtime-constraint failures. Prefer passing the actual destination buffer size (e.g., sizeof(FoundDevice.pcDeviceName) / sizeof(apstBTDeviceInfo->pcName) or the correct constant including the NUL).

Suggested change
rc = strcpy_s(FoundDevice.pcDeviceName,BD_NAME_LEN,"Xbox Wireless Controller");
ERR_CHK(rc);
rc = strcpy_s(apstBTDeviceInfo->pcName,BD_NAME_LEN,"Xbox Wireless Controller");
rc = strcpy_s(FoundDevice.pcDeviceName, sizeof(FoundDevice.pcDeviceName), "Xbox Wireless Controller");
ERR_CHK(rc);
rc = strcpy_s(apstBTDeviceInfo->pcName, sizeof(apstBTDeviceInfo->pcName), "Xbox Wireless Controller");

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Coverity Issue - Array compared against 0

Comparing an array to null is not useful: ""Xbox Wireless Controller" != NULL", since the test will always evaluate as true.

Medium Impact, CWE-398
NO_EFFECT

How to fix

Was ""Xbox Wireless Controller"" formerly declared as a pointer?

ERR_CHK(rc);

BTRCORELOG_INFO("Gen3 detected by OUI; forcing UI update with temporary name for %s\n",FoundDevice.pcDeviceAddress);
Comment on lines +7142 to +7152
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

This change introduces new behavioral logic (Xbox Gen3 OUI detection that mutates pcName to force an immediate UI update), but the existing unit tests for btrCore_BTDeviceStatusUpdateCb don’t appear to exercise this branch. Please add a test case where deviceInfo.pcName initially equals deviceInfo.pcAddress and the address matches one of the new OUIs, and assert that the callback updates the name as expected.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Coverity Issue - String not null terminated

Passing unterminated string "FoundDevice.pcDeviceAddress" to "fprintf", which expects a null-terminated string.

High Impact, CWE-170
STRING_NULL

}

Comment on lines +7142 to +7154
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

The indentation/bracing in the new Xbox Gen3 exception block is inconsistent with the surrounding code (mixed tab/space at the comment line and misaligned closing brace). Please reformat this block to match the file’s existing indentation so it’s easier to read and avoids diffs caused by whitespace-only changes later.

Suggested change
/* Xbox Gen3 exception: force immediate UI update with a temporary name */
if (btrCore_IsDevNameSameAsAddress(&FoundDevice) &&
btrCore_IsXboxGen3Gamepad(FoundDevice.pcDeviceAddress)) {
errno_t rc;
rc = strcpy_s(FoundDevice.pcDeviceName,BD_NAME_LEN,"Xbox Wireless Controller");
ERR_CHK(rc);
rc = strcpy_s(apstBTDeviceInfo->pcName,BD_NAME_LEN,"Xbox Wireless Controller");
ERR_CHK(rc);
BTRCORELOG_INFO("Gen3 detected by OUI; forcing UI update with temporary name for %s\n",FoundDevice.pcDeviceAddress);
}
/* Xbox Gen3 exception: force immediate UI update with a temporary name */
if (btrCore_IsDevNameSameAsAddress(&FoundDevice) &&
btrCore_IsXboxGen3Gamepad(FoundDevice.pcDeviceAddress)) {
errno_t rc;
rc = strcpy_s(FoundDevice.pcDeviceName, BD_NAME_LEN, "Xbox Wireless Controller");
ERR_CHK(rc);
rc = strcpy_s(apstBTDeviceInfo->pcName, BD_NAME_LEN, "Xbox Wireless Controller");
ERR_CHK(rc);
BTRCORELOG_INFO("Gen3 detected by OUI; forcing UI update with temporary name for %s\n", FoundDevice.pcDeviceAddress);
}

Copilot uses AI. Check for mistakes.
if(btrCore_IsDevNameSameAsAddress(&FoundDevice)) {
if ((lenBTRCoreDevType == enBTRCoreSpeakers) || (lenBTRCoreDevType == enBTRCoreHeadSet) || (enBTRCoreHID == lenBTRCoreDevType)) {
BTRCORELOG_INFO("pcName - %s pcAddress - %s DeviceType - %d skipCount - %lld\n",apstBTDeviceInfo->pcName,apstBTDeviceInfo->pcAddress,lenBTRCoreDevType,lpstlhBTRCore->skipDeviceDiscUpdate);
Expand Down
Loading