diff --git a/include/btrCore.h b/include/btrCore.h index 3b5e64a..82b729b 100644 --- a/include/btrCore.h +++ b/include/btrCore.h @@ -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. + * + * @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); diff --git a/src/btrCore.c b/src/btrCore.c index d1d5967..38e3fcc 100644 --- a/src/btrCore.c +++ b/src/btrCore.c @@ -5135,6 +5135,49 @@ BTRCore_ConnectDevice ( return enBTRCoreSuccess; } +enBTRCoreRet btrCore_UpdateDeviceBlockState ( + tBTRCoreHandle hBTRCore, + tBTRCoreDevId aBTRCoreDevId, + enBTRCoreDeviceType aenBTRCoreDevType, + int isBlocked +) { + + stBTRCoreHdl* pstlhBTRCore = NULL; + if (!hBTRCore) { + BTRCORELOG_ERROR("Invalid BT Core Handle\n"); + return enBTRCoreInvalidArg; + } + + pstlhBTRCore = (stBTRCoreHdl*)hBTRCore; + + 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; + break; + } + } + + if (!pDevicePath) { + BTRCORELOG_ERROR("Device ID %lld not found\n", aBTRCoreDevId); + return enBTRCoreDeviceNotFound; + } + + 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"); + return enBTRCoreFailure; + } + + return enBTRCoreSuccess; +} enBTRCoreRet BTRCore_DisconnectDevice (