Skip to content
Open
Show file tree
Hide file tree
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
135 changes: 117 additions & 18 deletions src/ifce/btrMgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
#define BTMGR_PROCESS_NAME "btMgrBus"
#define RDK_LOGGER_BTMGR_NAME "LOG.RDK.BTRMGR"
#define RDK_LOGGER_BTCORE_NAME "LOG.RDK.BTRCORE"
#define BTRMGR_REMOTE_DEVICE "Remote Device"


#ifdef RDKTV_PERSIST_VOLUME
#define BTRMGR_DEFAULT_SET_VOLUME_INTERVAL 2
Expand Down Expand Up @@ -136,7 +138,7 @@
BTRMGR_STARTUP_AUD_RETRY,
} enBTRMGRStartupAudio;

// Move to private header ?

Check failure on line 141 in src/ifce/btrMgr.c

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'src/ifce/btrMgr.c' (Match: rdk/components/generic/bluetooth_mgr/rdk/components/generic/bluetooth_mgr/2009, 10664 lines, url: https://code.rdkcentral.com/r/plugins/gitiles/rdk/components/generic/bluetooth_mgr/+archive/RDK-DEV-2009.tar.gz, file: src/ifce/btrMgr.c)

Check failure on line 141 in src/ifce/btrMgr.c

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'src/ifce/btrMgr.c' (Match: rdk/components/generic/bluetooth_mgr/rdk/components/generic/bluetooth_mgr/2011, 10664 lines, url: https://code.rdkcentral.com/r/plugins/gitiles/rdk/components/generic/bluetooth_mgr/+archive/RDK-DEV-2011.tar.gz, file: src/ifce/btrMgr.c)
typedef struct _stBTRMgrStreamingInfo {
tBTRMgrAcHdl hBTRMgrAcHdl;
tBTRMgrSoHdl hBTRMgrSoHdl;
Expand Down Expand Up @@ -237,18 +239,19 @@
unsigned char gDebugModeEnabled = 0; //shared with audiocaptureMgr
#endif

STATIC void* gpvMainLoop = NULL;
STATIC void* gpvMainLoopThread = NULL;
STATIC BTRMGR_EventCallback gfpcBBTRMgrEventOut = NULL;
STATIC BOOLEAN gIsAdvertisementSet = FALSE;
STATIC BOOLEAN gIsDeviceAdvertising = FALSE;
STATIC BOOLEAN gIsDiscoveryOpInternal = FALSE;
STATIC BOOLEAN gEliteIncomCon = FALSE;
#ifdef RDKTV_PERSIST_VOLUME
STATIC BOOLEAN gSkipVolumeUpdate = FALSE;
STATIC volatile guint gSkipVolumeUpdateTimeoutRef = 0;
STATIC volatile guint gDefaultSetVolumeTimeoutRef = 0;
STATIC volatile guint gDefaultConInProgressTimeoutRef = 0;
static void* gpvMainLoop = NULL;
static void* gpvMainLoopThread = NULL;
static BTRMGR_EventCallback gfpcBBTRMgrEventOut = NULL;
static BOOLEAN gIsAdvertisementSet = FALSE;
static BOOLEAN gIsDeviceAdvertising = FALSE;
static BOOLEAN gIsDiscoveryOpInternal = FALSE;
static BOOLEAN gEliteIncomCon = FALSE;
static BOOLEAN gbGamepadStandbyMode = FALSE;
#ifdef RDKTV_PERSIST_VOLUME_SKY
static BOOLEAN gSkipVolumeUpdate = FALSE;
static volatile guint gSkipVolumeUpdateTimeoutRef = 0;
static volatile guint gDefaultSetVolumeTimeoutRef = 0;
static volatile guint gDefaultConInProgressTimeoutRef = 0;
#endif

#ifdef LE_MODE
Expand Down Expand Up @@ -3927,11 +3930,14 @@
BTRMGRLOG_ERROR ("Could not initialize SD - SysDiag module\n");
}


#ifdef LE_MODE
btrMgr_CheckBroadcastAvailability();
#else
btrMgr_CheckAudioInServiceAvailability();
btrMgr_CheckHidGamePadServiceAvailability();
//this should be the gamepad state anyway, but make sure in case of an unexpected shutdown in standby/lightsleep mode
BTRCore_refreshLEActionListForGamepads(ghBTRCoreHdl);
#endif

#if 0
Expand Down Expand Up @@ -5973,6 +5979,26 @@
}
#endif //AUTO_CONNECT_ENABLED

//get power state as we do not need to connect if the power state is not ON and power callback will always be registered
char lcPowerState[BTRMGR_LE_STR_LEN_MAX] = {'\0'};
BTRMGR_SysDiagChar_t lpcPowerString = BTRMGR_SYS_DIAG_POWERSTATE;

if (eBTRMgrSuccess == BTRMGR_SD_GetData(ghBTRMgrSdHdl, lpcPowerString, lcPowerState)) {
if(strncmp(lcPowerState, BTRMGR_SYS_DIAG_PWRST_ON, strlen(BTRMGR_SYS_DIAG_PWRST_ON) != 0))
{
BTRMGRLOG_ERROR("Power state is %s no need to try connecting device as it will connect once ON\n", lcPowerState);
return BTRMGR_RESULT_GENERIC_FAILURE;
}
else
{
BTRMGRLOG_INFO("Power state is ON\n");
}
}
else
{
BTRMGRLOG_ERROR("Could not get power state\n");
}

gIsAudOutStartupInProgress = BTRMGR_STARTUP_AUD_UNKNOWN;
if (BTRMgr_PI_GetAllProfiles(ghBTRMgrPiHdl, &lstPersistentData) == eBTRMgrFailure) {
btrMgr_AddPersistentEntry (aui8AdapterIdx, 0, BTRMGR_A2DP_SINK_PROFILE_ID, isConnected);
Expand Down Expand Up @@ -8935,6 +8961,12 @@
stBTRCoreDevStatusCBInfo *cb_data = (stBTRCoreDevStatusCBInfo*)user_data;
BTRMGRLOG_DEBUG("Posting Device Found Event ..\n");
btrMgr_MapDevstatusInfoToEventInfo ((void *)cb_data, &lstEventMessage, BTRMGR_EVENT_DEVICE_FOUND);
if (gbGamepadStandbyMode && ((lstEventMessage.m_pairedDevice.m_deviceType == BTRMGR_DEVICE_TYPE_HID) ||
(lstEventMessage.m_pairedDevice.m_deviceType == BTRMGR_DEVICE_TYPE_HID_GAMEPAD)))
{
BTRMGRLOG_WARN("Device is in standby mode, we won't post to the upper layers if a device is found\n");
return G_SOURCE_REMOVE;
}
if (gfpcBBTRMgrEventOut) {
gfpcBBTRMgrEventOut(lstEventMessage);
}
Expand Down Expand Up @@ -9008,6 +9040,8 @@
if( BTRMGR_StartAudioStreamingOut_StartUp(lui8AdapterIdx, BTRMGR_DEVICE_OP_TYPE_AUDIO_OUTPUT) != BTRMGR_RESULT_SUCCESS) {
BTRMGRLOG_ERROR ("ConnPwrStChange - BTRMGR_StartAudioStreamingOut_StartUp Failed!\n");
}
//gamepads should connect back now
BTRCore_refreshLEActionListForGamepads(ghBTRCoreHdl);
}

#endif
Expand Down Expand Up @@ -9152,7 +9186,14 @@
stBTRMgrSysDiagStatus* apstBtrMgrSdStatus,
void* apvUserData
) {
eBTRMgrRet leBtrMgrSdRet = eBTRMgrFailure;
eBTRMgrRet leBtrMgrSdRet = eBTRMgrSuccess;

BTRMGR_Result_t lenBtrMgrResult = BTRMGR_RESULT_SUCCESS;
enBTRCoreRet lenBtrCoreRet = enBTRCoreSuccess;
unsigned short ui16LoopIdx = 0;
BTRMGR_ConnectedDevicesList_t *lstConnectedDevices;
unsigned int ui32sleepTimeOut = 1;
gboolean isRemoteDev = FALSE;

if ((apstBtrMgrSdStatus != NULL) &&
#ifndef LE_MODE
Expand All @@ -9178,6 +9219,59 @@
if (gConnPwrStChangeTimeOutRef)
leBtrMgrSdRet = eBTRMgrSuccess;
}

if ((apstBtrMgrSdStatus != NULL) && (apstBtrMgrSdStatus->enSysDiagChar == BTRMGR_SYS_DIAG_POWERSTATE))
{
if (!strncmp(apstBtrMgrSdStatus->pcSysDiagRes, BTRMGR_SYS_DIAG_PWRST_ON, strlen(BTRMGR_SYS_DIAG_PWRST_ON)))
{
BTRMGRLOG_INFO("Exited standby mode, allowing gamepads to connect\n");
gbGamepadStandbyMode = FALSE;
}
else if (!strncmp(apstBtrMgrSdStatus->pcSysDiagRes, BTRMGR_SYS_DIAG_PWRST_STANDBY, strlen(BTRMGR_SYS_DIAG_PWRST_STANDBY)) ||
!strncmp(apstBtrMgrSdStatus->pcSysDiagRes, BTRMGR_SYS_DIAG_PWRST_STDBY_LIGHT_SLEEP, strlen(BTRMGR_SYS_DIAG_PWRST_STDBY_LIGHT_SLEEP)))
{
BTRMGRLOG_INFO("Entered standby mode, disconnecting gamepads\n");
gbGamepadStandbyMode = TRUE;
//stop any gamepads from connecting whilst in standby mode
BTRCore_clearLEActionListForGamepads(ghBTRCoreHdl);
//Disconnect all connected gamepads
lstConnectedDevices = malloc(sizeof(BTRMGR_ConnectedDevicesList_t));
if (!lstConnectedDevices)
{
BTRMGRLOG_ERROR("Run out memory for connected devices list\n");
return eBTRMgrFailure;
}
if ((lenBtrMgrResult = BTRMGR_GetConnectedDevices(0, lstConnectedDevices)) == BTRMGR_RESULT_SUCCESS) {
BTRMGRLOG_DEBUG ("Connected Devices = %d\n", lstConnectedDevices->m_numOfDevices);

for (ui16LoopIdx = 0; ui16LoopIdx < lstConnectedDevices->m_numOfDevices; ui16LoopIdx++) {
unsigned int ui32confirmIdx = 2;
enBTRCoreDeviceType lenBtrCoreDevTy = enBTRCoreUnknown;
enBTRCoreDeviceClass lenBtrCoreDevCl = enBTRCore_DC_Unknown;
isRemoteDev = btrMgr_IsDeviceRdkRcu(&lstConnectedDevices->m_deviceProperty[ui16LoopIdx].m_serviceInfo, lstConnectedDevices->m_deviceProperty[ui16LoopIdx].m_ui16DevAppearanceBleSpec);
BTRCore_GetDeviceTypeClass(ghBTRCoreHdl, lstConnectedDevices->m_deviceProperty[ui16LoopIdx].m_deviceHandle, &lenBtrCoreDevTy, &lenBtrCoreDevCl);

if (!isRemoteDev && ((lstConnectedDevices->m_deviceProperty[ui16LoopIdx].m_deviceType == BTRMGR_DEVICE_TYPE_HID) ||
(lstConnectedDevices->m_deviceProperty[ui16LoopIdx].m_deviceType == BTRMGR_DEVICE_TYPE_HID_GAMEPAD)))
{
if (BTRCore_DisconnectDevice(ghBTRCoreHdl, lstConnectedDevices->m_deviceProperty[ui16LoopIdx].m_deviceHandle, lenBtrCoreDevTy) != enBTRCoreSuccess) {
BTRMGRLOG_ERROR ("Failed to Disconnect - %llu\n", lstConnectedDevices->m_deviceProperty[ui16LoopIdx].m_deviceHandle);
}

do {
unsigned int ui32sleepIdx = 2;

do {
sleep(ui32sleepTimeOut);
lenBtrCoreRet = BTRCore_GetDeviceDisconnected(ghBTRCoreHdl, lstConnectedDevices->m_deviceProperty[ui16LoopIdx].m_deviceHandle, lenBtrCoreDevTy);
} while ((lenBtrCoreRet != enBTRCoreSuccess) && (--ui32sleepIdx));
} while (--ui32confirmIdx);
}
}
}
free(lstConnectedDevices);
}
}

return leBtrMgrSdRet;
}
Expand All @@ -9186,6 +9280,7 @@
{
BTRMGR_EventMessage_t lstEventMessage;
MEMSET_S(&lstEventMessage, sizeof(lstEventMessage), 0, sizeof(lstEventMessage));

lstEventMessage.m_adapterIndex = 0;
lstEventMessage.m_eventType = BTRMGR_EVENT_RECEIVED_EXTERNAL_CONNECT_REQUEST;
lstEventMessage.m_externalDevice.m_deviceHandle = ((stBTRCoreDevStatusCBInfo*)p_StatusCB)->deviceId;
Expand Down Expand Up @@ -10306,7 +10401,8 @@
(BTRMGR_XBOX_GAMESIR_VENDOR_ID == MVendorId && BTRMGR_XBOX_GAMESIR_PRODUCT_ID == ui32MProductId) ||
(BTRMGR_NINTENDO_GAMESIR_VENDOR_ID == MVendorId && BTRMGR_NINTENDO_GAMESIR_PRODUCT_ID == ui32MProductId) ||
(BTRMGR_XBOX_ADAPTIVE_VENDOR_ID == MVendorId && BTRMGR_XBOX_ADAPTIVE_PRODUCT_ID == ui32MProductId))) &&
isDeinitInProgress != TRUE) {
isDeinitInProgress != TRUE &&
!gbGamepadStandbyMode) {

if (apstConnCbInfo->stKnownDevice.tDeviceId != ghBTRMgrDevHdlPairingInProgress &&
apstConnCbInfo->stKnownDevice.tDeviceId != ghBTRMgrDevHdlConnInProgress) {
Expand Down Expand Up @@ -10367,10 +10463,13 @@
else {
BTRMGRLOG_ERROR ("Incoming Connection denied\n");
*api32ConnInAuthResp = 0;
if (ghBTRMgrDevHdlLastDisconnected == apstConnCbInfo->stKnownDevice.tDeviceId) {
BTRMGRLOG_INFO("Restarting the timer to clear the disconnection status\n");
btrMgr_ClearDisconnectStatusHoldOffTimer();
btrMgr_SetDisconnectStatusHoldOffTimer();
if (!gbGamepadStandbyMode)
{
if (ghBTRMgrDevHdlLastDisconnected == apstConnCbInfo->stKnownDevice.tDeviceId) {
BTRMGRLOG_INFO("Restarting the timer to clear the disconnection status\n");
btrMgr_ClearDisconnectStatusHoldOffTimer();
btrMgr_SetDisconnectStatusHoldOffTimer();
}
}
}
}
Expand Down
48 changes: 36 additions & 12 deletions src/sysDiag/btrMgr_SysDiag.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ extern rbusHandle_t rbusHandle;
typedef struct _stBTRMgrSDHdl {
#ifndef BUILD_FOR_PI
PowerController_PowerState_t _powerState;
bool registeredPowerCb;
#endif
stBTRMgrSysDiagStatus lstBtrMgrSysDiagStat;
fPtr_BTRMgr_SD_StatusCb fpcBSdStatus;
Expand Down Expand Up @@ -230,6 +231,7 @@ BTRMgr_SD_Init (
sDHandle->lstBtrMgrSysDiagStat.enSysDiagChar = BTRMGR_SYS_DIAG_UNKNOWN;
#ifndef BUILD_FOR_PI
sDHandle->_powerState = POWER_STATE_OFF;
sDHandle->registeredPowerCb = FALSE;
#endif
sDHandle->fpcBSdStatus= afpcBSdStatus;
sDHandle->pvcBUserData= apvUserData;
Expand All @@ -245,8 +247,14 @@ BTRMgr_SD_DeInit (
tBTRMgrSDHdl hBTRMgrSdHdl
) {
stBTRMgrSDHdl* pstBtrMgrSdHdl = (stBTRMgrSDHdl*)hBTRMgrSdHdl;

if (NULL != pstBtrMgrSdHdl) {
#ifdef BTR_SYS_DIAG_IARM_ENABLE
if (pstBtrMgrSdHdl->registeredPowerCb)
{
pstBtrMgrSdHdl->registeredPowerCb = FALSE;
IARM_Bus_UnRegisterEventHandler(IARM_BUS_PWRMGR_NAME, IARM_BUS_PWRMGR_EVENT_MODECHANGED);
}
#endif //BTR_SYS_DIAG_IARM_ENABLE
gpstSDHandle = NULL;
free((void*)pstBtrMgrSdHdl);
pstBtrMgrSdHdl = NULL;
Expand Down Expand Up @@ -640,18 +648,25 @@ BTRMGR_SD_GetData (

pstBtrMgrSdHdl->lstBtrMgrSysDiagStat.enSysDiagChar = BTRMGR_SYS_DIAG_POWERSTATE;
strncpy(pstBtrMgrSdHdl->lstBtrMgrSysDiagStat.pcSysDiagRes, aData, BTRMGR_STR_LEN_MAX - 1);
pstBtrMgrSdHdl->_powerState = curState;

if (curState != POWER_STATE_ON) {
BTRMGRLOG_WARN("BTRMGR_SYS_DIAG_POWERSTATE PWRMGR :%d - %s\n", curState, aData);
PowerController_RegisterPowerModeChangedCallback(btrMgr_SysDiag_powerModeChangeCb, NULL);
pstBtrMgrSdHdl->_powerState = param.curState;

BTRMGRLOG_WARN("BTRMGR_SYS_DIAG_POWERSTATE PWRMGR :%d - %s\n", param.curState, aData);
if (!pstBtrMgrSdHdl->registeredPowerCb)
{
pstBtrMgrSdHdl->registeredPowerCb = TRUE;
PowerController_RegisterPowerModeChangedCallback(btrMgr_SysDiag_powerModeChangeCb, NULL);
}

}
else {
BTRMGRLOG_ERROR("BTRMGR_SYS_DIAG_POWERSTATE Failure : Return code is %d\n", res);
/* In case of Failure to call GetPowerState registet the event handler anyway */
PowerController_RegisterPowerModeChangedCallback(btrMgr_SysDiag_powerModeChangeCb, NULL);
rc = eBTRMgrFailure;
BTRMGRLOG_DEBUG("BTRMGR_SYS_DIAG_POWERSTATE Failure : Return code is %d\n", res);
/* In case of Failure to call GetPowerState registet the event handler anyway */
if (!pstBtrMgrSdHdl->registeredPowerCb)
{
pstBtrMgrSdHdl->registeredPowerCb = TRUE;
PowerController_RegisterPowerModeChangedCallback(btrMgr_SysDiag_powerModeChangeCb, NULL);
}
rc = eBTRMgrFailure;
}
#else
rc = eBTRMgrFailure;
Expand Down Expand Up @@ -821,8 +836,17 @@ btrMgr_SysDiag_powerModeChangeCb (
gpstSDHandle->lstBtrMgrSysDiagStat.enSysDiagChar = BTRMGR_SYS_DIAG_POWERSTATE;


if (gpstSDHandle->_powerState != newState && (newState != POWER_STATE_ON && newState != POWER_STATE_STANDBY_LIGHT_SLEEP)) {
BTRMGRLOG_WARN("BTRMGR_SYS_DIAG_POWERSTATE - Device is being suspended\n");
if (gpstSDHandle->_powerState != param->data.state.newState && (param->data.state.newState == POWER_STATE_STANDBY || param->data.state.newState == POWER_STATE_STANDBY_LIGHT_SLEEP || param->data.state.newState == POWER_STATE_STANDBY_DEEP_SLEEP)) {
BTRMGRLOG_WARN("BTRMGR_SYS_DIAG_POWERSTATE - Device is being suspended: %s\n", gpstSDHandle->lstBtrMgrSysDiagStat.pcSysDiagRes);
if (gpstSDHandle->fpcBSdStatus) {
stBTRMgrSysDiagStatus lstBtrMgrSysDiagStat;
eBTRMgrRet leBtrMgrSdRet = eBTRMgrSuccess;

MEMCPY_S(&lstBtrMgrSysDiagStat, sizeof(stBTRMgrSysDiagStatus), &gpstSDHandle->lstBtrMgrSysDiagStat, sizeof(stBTRMgrSysDiagStatus));
if ((leBtrMgrSdRet = gpstSDHandle->fpcBSdStatus(&lstBtrMgrSysDiagStat, gpstSDHandle->pvcBUserData)) != eBTRMgrSuccess) {
BTRMGRLOG_ERROR("BTRMGR_SYS_DIAG_POWERSTATE - Device suspended - NOT PROCESSED\n");
}
}
}

if (gpstSDHandle->_powerState != newState && newState == POWER_STATE_ON) {
Expand Down
Loading