Skip to content
Open
19 changes: 19 additions & 0 deletions include/btrCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,25 @@ enBTRCoreRet BTRCore_GetBluetoothVersion(char *version);
*/
BOOLEAN BTRCore_IsUnsupportedGamepad(unsigned int ui32Vendor, unsigned int ui32Product, unsigned int ui32DeviceId);

/**
* @brief Updates the block state (blocked/unblocked) of a Bluetooth device.
*
* This API sets the device block state for the specified Bluetooth device using its device ID and type.
* It may be used to block or unblock a device from interacting with the Bluetooth core.
*
* @param[in] pstlhBTRCore Pointer to the Bluetooth Core handle.
* @param[in] aBTRCoreDevId Device ID of the target Bluetooth device.
* @param[in] aenBTRCoreDevType Device type of the target Bluetooth device.
* @param[in] isBlocked Desired block state: 1 to block the device, 0 to unblock it.
Comment on lines +1351 to +1360
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

This PR adds a new externally visible API, but there are no corresponding unit tests (the repo has extensive coverage in unitTest/test_btrCore.c for other BTRCore_* APIs). Please add tests that cover success/failure paths (e.g., device not found, BTSetProp failure, and block/unblock values).

Copilot uses AI. Check for mistakes.
*
* @return Returns the status of the operation.
* @retval enBTRCoreSuccess Operation successful.
* @retval enBTRCoreFailure Operation failed; see logs for details.
* @retval enBTRCoreInvalidArg Invalid argument provided.
* @retval enBTRCoreDeviceNotFound Device with given ID not found.
*/
enBTRCoreRet btrCore_UpdateDeviceBlockState (tBTRCoreHandle hBTRCore, tBTRCoreDevId aBTRCoreDevId, enBTRCoreDeviceType aenBTRCoreDevType, int isBlocked);

// Outgoing callbacks Registration Interfaces
/* BTRCore_RegisterDiscoveryCb - Callback to notify the application every time when a new device is found and added to discovery list */
enBTRCoreRet BTRCore_RegisterDiscoveryCb (tBTRCoreHandle hBTRCore, fPtr_BTRCore_DeviceDiscCb afpcBBTRCoreDeviceDiscovery, void* apUserData);
Expand Down
43 changes: 43 additions & 0 deletions src/btrCore.c
Original file line number Diff line number Diff line change
Expand Up @@ -5135,6 +5135,49 @@ BTRCore_ConnectDevice (
return enBTRCoreSuccess;
}

enBTRCoreRet btrCore_UpdateDeviceBlockState (
tBTRCoreHandle hBTRCore,
tBTRCoreDevId aBTRCoreDevId,
enBTRCoreDeviceType aenBTRCoreDevType,
int isBlocked
Comment on lines +5138 to +5142
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

This function uses aenBTRCoreDevType in the signature but never references it, which will fail the build under -Wall -Werror due to -Wunused-parameter. Either use it (e.g., via btrCore_GetDeviceInfoKnown(...)) or explicitly mark it unused if it’s intentionally ignored.

Copilot uses AI. Check for mistakes.
) {

stBTRCoreHdl* pstlhBTRCore = NULL;
if (!hBTRCore) {
BTRCORELOG_ERROR("Invalid BT Core Handle\n");
return enBTRCoreInvalidArg;
}

pstlhBTRCore = (stBTRCoreHdl*)hBTRCore;

Comment on lines +5138 to +5152
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

The new API takes tBTRCoreHandle* (i.e., void**) but the rest of BTRCore public APIs take tBTRCoreHandle (void*). The implementation then casts hBTRCore directly to stBTRCoreHdl*, which will be an invalid pointer if callers pass the handle by value like other APIs. Please change the signature to take tBTRCoreHandle hBTRCore and align the null-handle return code with the existing pattern (enBTRCoreNotInitialized).

Copilot uses AI. Check for mistakes.
const char *pDevicePath = NULL;
int i;
enBTDeviceType enBTDevice = enBTDevUnknown;

for (i = 0; i < pstlhBTRCore->numOfPairedDevices; ++i) {
if (pstlhBTRCore->stKnownDevicesArr[i].tDeviceId == aBTRCoreDevId) {
pDevicePath = pstlhBTRCore->stKnownDevicesArr[i].pcDevicePath;
enBTDevice = pstlhBTRCore->stKnownDevicesArr[i].enDeviceType;
Comment on lines +5155 to +5160
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

enBTDevice is declared as enBTDeviceType, but it’s being assigned from stKnownDevicesArr[i].enDeviceType (type enBTRCoreDeviceClass). This mixes unrelated enums and will produce an invalid value for later calls; avoid deriving the BT interface type from the device class here.

Copilot uses AI. Check for mistakes.
break;
}
}

if (!pDevicePath) {
BTRCORELOG_ERROR("Device ID %lld not found\n", aBTRCoreDevId);
return enBTRCoreDeviceNotFound;
}

Comment on lines +5154 to +5169
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

aenBTRCoreDevType is currently unused, and this function manually scans stKnownDevicesArr to find the MAC/type. Elsewhere (e.g., connect/disconnect/unpair) the code uses helpers like btrCore_GetDeviceInfoKnown / btrCore_GetDeviceInfo / btrCore_GetKnownDeviceMac, which also handle the aBTRCoreDevId < BTRCORE_MAX_NUM_BT_DEVICES case and keep the lookup logic consistent. Reuse the existing helper(s) here to avoid divergent device-ID resolution and to make use of the aenBTRCoreDevType parameter (or remove it if it’s not needed).

Suggested change
int i;
enBTDeviceType enBTDevice = enBTDevUnknown;
for (i = 0; i < pstlhBTRCore->numOfPairedDevices; ++i) {
if (pstlhBTRCore->stKnownDevicesArr[i].tDeviceId == aBTRCoreDevId) {
pDeviceAddress = pstlhBTRCore->stKnownDevicesArr[i].pcDeviceAddress;
enBTDevice = pstlhBTRCore->stKnownDevicesArr[i].enDeviceType;
break;
}
}
if (!pDeviceAddress) {
BTRCORELOG_ERROR("Device ID %lld not found\n", aBTRCoreDevId);
return enBTRCoreDeviceNotFound;
}
enBTDeviceType enBTDevice = enBTDevUnknown;
stBTRCoreBTDevice lstBTDeviceInfo;
memset(&lstBTDeviceInfo, 0, sizeof(lstBTDeviceInfo));
/* Use common helper to resolve device ID to address/type, so that
* aBTRCoreDevId and aenBTRCoreDevType are handled consistently with
* other operations (connect/disconnect/unpair, etc.).
*/
if (btrCore_GetDeviceInfo(pstlhBTRCore,
aBTRCoreDevId,
aenBTRCoreDevType,
&lstBTDeviceInfo) != enBTRCoreSuccess) {
BTRCORELOG_ERROR("Device ID %lld not found\n", aBTRCoreDevId);
return enBTRCoreDeviceNotFound;
}
pDeviceAddress = lstBTDeviceInfo.pcDeviceAddress;
enBTDevice = lstBTDeviceInfo.enDeviceType;

Copilot uses AI. Check for mistakes.
unBTOpIfceProp lunBtOpDevProp;
lunBtOpDevProp.enBtDeviceProp = enBTDevPropBlocked;
int BlockDevice = isBlocked ? 1 : 0;

if (BtrCore_BTSetProp(pstlhBTRCore->connHdl, pDevicePath, enBTDevice, lunBtOpDevProp, &BlockDevice)) {
BTRCORELOG_ERROR("Set Device Property enBTDevPropBlocked - FAILED\n");
Comment on lines +5155 to +5175
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

The third argument to BtrCore_BTSetProp is enBTOpIfceType (e.g., enBTDevice), but this function defines enBTDevice as an enBTDeviceType variable and passes it through. That’s a type/semantic mismatch and will either not compile cleanly or call the API with the wrong enum value. Pass the enBTDevice interface type constant here, and keep the device-type enum separate if needed.

Copilot uses AI. Check for mistakes.
return enBTRCoreFailure;
}

return enBTRCoreSuccess;
}
Comment on lines +5138 to +5180
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

There are existing unit tests for btrCore.c logic in unitTest/test_btrCore.c, but no tests cover this newly introduced device-block/unblock API. Please add unit tests for at least: invalid handle, device-not-found, and successful blocked/unblocked property setting (with BtrCore_BTSetProp mocked).

Copilot uses AI. Check for mistakes.

enBTRCoreRet
BTRCore_DisconnectDevice (
Expand Down
Loading