2016-09-26 09:37:39 -04:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000-2012 Broadcom Corporation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file contains functions that manages ACL link modes.
|
|
|
|
* This includes operations such as active, hold,
|
|
|
|
* park and sniff modes.
|
|
|
|
*
|
|
|
|
* This module contains both internal and external (API)
|
|
|
|
* functions. External (API) functions are distinguishable
|
|
|
|
* by their names beginning with uppercase BTM.
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
//#define LOG_TAG "bt_btm_pm"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
//#include <stdio.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "stack/bt_types.h"
|
|
|
|
#include "stack/hcimsgs.h"
|
|
|
|
#include "stack/btu.h"
|
|
|
|
#include "stack/btm_api.h"
|
2016-09-26 09:37:39 -04:00
|
|
|
#include "btm_int.h"
|
|
|
|
#include "l2c_int.h"
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "stack/hcidefs.h"
|
2016-09-26 09:37:39 -04:00
|
|
|
//#include "bt_utils.h"
|
|
|
|
//#include "osi/include/log.h"
|
2020-07-01 14:35:54 -04:00
|
|
|
#include "osi/allocator.h"
|
2016-09-26 09:37:39 -04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* to handle different modes */
|
|
|
|
/*****************************************************************************/
|
|
|
|
#define BTM_PM_STORED_MASK 0x80 /* set this mask if the command is stored */
|
|
|
|
#define BTM_PM_NUM_SET_MODES 3 /* only hold, sniff & park */
|
|
|
|
|
|
|
|
/* Usage: (ptr_features[ offset ] & mask )?TRUE:FALSE */
|
|
|
|
/* offset to supported feature */
|
|
|
|
const UINT8 btm_pm_mode_off[BTM_PM_NUM_SET_MODES] = {0, 0, 1};
|
|
|
|
/* mask to supported feature */
|
|
|
|
const UINT8 btm_pm_mode_msk[BTM_PM_NUM_SET_MODES] = {0x40, 0x80, 0x01};
|
|
|
|
|
|
|
|
#define BTM_PM_GET_MD1 1
|
|
|
|
#define BTM_PM_GET_MD2 2
|
|
|
|
#define BTM_PM_GET_COMP 3
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
const UINT8 btm_pm_md_comp_matrix[BTM_PM_NUM_SET_MODES * BTM_PM_NUM_SET_MODES] = {
|
2016-09-26 09:37:39 -04:00
|
|
|
BTM_PM_GET_COMP,
|
|
|
|
BTM_PM_GET_MD2,
|
|
|
|
BTM_PM_GET_MD2,
|
|
|
|
|
|
|
|
BTM_PM_GET_MD1,
|
|
|
|
BTM_PM_GET_COMP,
|
|
|
|
BTM_PM_GET_MD1,
|
|
|
|
|
|
|
|
BTM_PM_GET_MD1,
|
|
|
|
BTM_PM_GET_MD2,
|
|
|
|
BTM_PM_GET_COMP
|
|
|
|
};
|
|
|
|
|
|
|
|
/* function prototype */
|
2020-07-01 14:35:54 -04:00
|
|
|
static tBTM_STATUS btm_pm_snd_md_req( UINT8 pm_id, UINT16 link_hdl, tBTM_PM_PWR_MD *p_mode );
|
2019-03-15 08:59:55 -04:00
|
|
|
#if (!CONFIG_BT_STACK_NO_LOG)
|
2016-09-26 09:37:39 -04:00
|
|
|
static const char *mode_to_string(tBTM_PM_MODE mode);
|
2019-03-15 08:59:55 -04:00
|
|
|
#endif
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
#ifdef BTM_PM_DEBUG
|
|
|
|
#undef BTM_PM_DEBUG
|
|
|
|
#define BTM_PM_DEBUG TRUE
|
|
|
|
#endif
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if BTM_PM_DEBUG == TRUE
|
2016-11-24 13:10:15 -05:00
|
|
|
const char *btm_pm_state_str[] = {
|
2016-09-26 09:37:39 -04:00
|
|
|
"pm_active_state",
|
|
|
|
"pm_hold_state",
|
|
|
|
"pm_sniff_state",
|
|
|
|
"pm_park_state",
|
|
|
|
"pm_pend_state"
|
|
|
|
};
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
const char *btm_pm_event_str[] = {
|
2016-09-26 09:37:39 -04:00
|
|
|
"pm_set_mode_event",
|
|
|
|
"pm_hci_sts_event",
|
|
|
|
"pm_mod_chg_event",
|
|
|
|
"pm_update_event"
|
|
|
|
};
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
const char *btm_pm_action_str[] = {
|
2016-09-26 09:37:39 -04:00
|
|
|
"pm_set_mode_action",
|
|
|
|
"pm_update_db_action",
|
|
|
|
"pm_mod_chg_action",
|
|
|
|
"pm_hci_sts_action",
|
|
|
|
"pm_update_action"
|
|
|
|
};
|
|
|
|
#endif // BTM_PM_DEBUG
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* P U B L I C F U N C T I O N S */
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_PmRegister
|
|
|
|
**
|
|
|
|
** Description register or deregister with power manager
|
|
|
|
**
|
|
|
|
** Returns BTM_SUCCESS if successful,
|
|
|
|
** BTM_NO_RESOURCES if no room to hold registration
|
|
|
|
** BTM_ILLEGAL_VALUE
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_PmRegister (UINT8 mask, UINT8 *p_pm_id, tBTM_PM_STATUS_CBACK *p_cb)
|
|
|
|
{
|
|
|
|
int xx;
|
|
|
|
|
|
|
|
/* de-register */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (mask & BTM_PM_DEREG) {
|
|
|
|
if (*p_pm_id >= BTM_MAX_PM_RECORDS) {
|
2016-09-26 09:37:39 -04:00
|
|
|
return BTM_ILLEGAL_VALUE;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
btm_cb.pm_reg_db[*p_pm_id].mask = BTM_PM_REC_NOT_USED;
|
|
|
|
return BTM_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
for (xx = 0; xx < BTM_MAX_PM_RECORDS; xx++) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* find an unused entry */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (btm_cb.pm_reg_db[xx].mask == BTM_PM_REC_NOT_USED) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* if register for notification, should provide callback routine */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (mask & BTM_PM_REG_NOTIF) {
|
|
|
|
if (p_cb == NULL) {
|
2016-09-26 09:37:39 -04:00
|
|
|
return BTM_ILLEGAL_VALUE;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
btm_cb.pm_reg_db[xx].cback = p_cb;
|
|
|
|
}
|
|
|
|
btm_cb.pm_reg_db[xx].mask = mask;
|
|
|
|
*p_pm_id = xx;
|
|
|
|
return BTM_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return BTM_NO_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_SetPowerMode
|
|
|
|
**
|
|
|
|
** Description store the mode in control block or
|
|
|
|
** alter ACL connection behavior.
|
|
|
|
**
|
|
|
|
** Returns BTM_SUCCESS if successful,
|
|
|
|
** BTM_UNKNOWN_ADDR if bd addr is not active or bad
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_SetPowerMode (UINT8 pm_id, BD_ADDR remote_bda, tBTM_PM_PWR_MD *p_mode)
|
|
|
|
{
|
|
|
|
UINT8 *p_features;
|
2020-07-01 14:35:54 -04:00
|
|
|
int ind;
|
2016-09-26 09:37:39 -04:00
|
|
|
tBTM_PM_MCB *p_cb = NULL; /* per ACL link */
|
|
|
|
tBTM_PM_MODE mode;
|
|
|
|
int temp_pm_id;
|
2020-07-01 14:35:54 -04:00
|
|
|
tACL_CONN *p_acl_cb;
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (pm_id >= BTM_MAX_PM_RECORDS) {
|
2016-09-26 09:37:39 -04:00
|
|
|
pm_id = BTM_PM_SET_ONLY_ID;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_mode == NULL) {
|
2016-09-26 09:37:39 -04:00
|
|
|
return BTM_ILLEGAL_VALUE;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
BTM_TRACE_API( "BTM_SetPowerMode: pm_id %d BDA: %08x mode:0x%x", pm_id,
|
2016-11-24 13:10:15 -05:00
|
|
|
(remote_bda[2] << 24) + (remote_bda[3] << 16) + (remote_bda[4] << 8) + remote_bda[5], p_mode->mode);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* take out the force bit */
|
|
|
|
mode = p_mode->mode & ~BTM_PM_MD_FORCE;
|
|
|
|
|
2020-07-01 14:35:54 -04:00
|
|
|
p_acl_cb = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
|
2020-09-22 09:07:14 -04:00
|
|
|
if (p_acl_cb == NULL){
|
|
|
|
return BTM_UNKNOWN_ADDR;
|
|
|
|
}
|
|
|
|
|
2020-07-01 14:35:54 -04:00
|
|
|
p_cb = p_acl_cb->p_pm_mode_db;
|
2016-11-24 13:10:15 -05:00
|
|
|
if (mode != BTM_PM_MD_ACTIVE) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* check if the requested mode is supported */
|
|
|
|
ind = mode - BTM_PM_MD_HOLD; /* make it base 0 */
|
|
|
|
p_features = BTM_ReadLocalFeatures();
|
2016-11-24 13:10:15 -05:00
|
|
|
if ( !(p_features[ btm_pm_mode_off[ind] ] & btm_pm_mode_msk[ind] ) ) {
|
2016-09-26 09:37:39 -04:00
|
|
|
return BTM_MODE_UNSUPPORTED;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (mode == p_cb->state) { /* the requested mode is current mode */
|
2016-09-26 09:37:39 -04:00
|
|
|
/* already in the requested mode and the current interval has less latency than the max */
|
2016-11-24 13:10:15 -05:00
|
|
|
if ( (mode == BTM_PM_MD_ACTIVE) ||
|
|
|
|
((p_mode->mode & BTM_PM_MD_FORCE) && (p_mode->max >= p_cb->interval) && (p_mode->min <= p_cb->interval)) ||
|
|
|
|
((p_mode->mode & BTM_PM_MD_FORCE) == 0 && (p_mode->max >= p_cb->interval)) ) {
|
2016-09-26 09:37:39 -04:00
|
|
|
BTM_TRACE_DEBUG( "BTM_SetPowerMode: mode:0x%x interval %d max:%d, min:%d", p_mode->mode, p_cb->interval, p_mode->max, p_mode->min);
|
|
|
|
return BTM_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
temp_pm_id = pm_id;
|
2016-11-24 13:10:15 -05:00
|
|
|
if (pm_id == BTM_PM_SET_ONLY_ID) {
|
2016-09-26 09:37:39 -04:00
|
|
|
temp_pm_id = BTM_MAX_PM_RECORDS;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* update mode database */
|
2016-11-24 13:10:15 -05:00
|
|
|
if ( ((pm_id != BTM_PM_SET_ONLY_ID) &&
|
|
|
|
(btm_cb.pm_reg_db[pm_id].mask & BTM_PM_REG_SET))
|
2020-11-10 02:40:01 -05:00
|
|
|
|| ((pm_id == BTM_PM_SET_ONLY_ID)
|
2020-07-01 14:35:54 -04:00
|
|
|
&& (btm_cb.pm_pend_link_hdl != BTM_INVALID_HANDLE)) ) {
|
2016-09-26 09:37:39 -04:00
|
|
|
#if BTM_PM_DEBUG == TRUE
|
2020-07-01 14:35:54 -04:00
|
|
|
BTM_TRACE_DEBUG( "BTM_SetPowerMode: Saving cmd acl handle %d temp_pm_id %d", p_acl_cb->hci_handle, temp_pm_id);
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif // BTM_PM_DEBUG
|
|
|
|
/* Make sure mask is set to BTM_PM_REG_SET */
|
|
|
|
btm_cb.pm_reg_db[temp_pm_id].mask |= BTM_PM_REG_SET;
|
|
|
|
*(&p_cb->req_mode[temp_pm_id]) = *((tBTM_PM_PWR_MD *)p_mode);
|
|
|
|
p_cb->chg_ind = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BTM_PM_DEBUG == TRUE
|
2020-07-01 14:35:54 -04:00
|
|
|
BTM_TRACE_DEBUG( "btm_pm state:0x%x, pm_pend_link_hdl: %d", p_cb->state, btm_cb.pm_pend_link_hdl);
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif // BTM_PM_DEBUG
|
|
|
|
/* if mode == hold or pending, return */
|
2016-11-24 13:10:15 -05:00
|
|
|
if ( (p_cb->state == BTM_PM_STS_HOLD) ||
|
|
|
|
(p_cb->state == BTM_PM_STS_PENDING) ||
|
2020-07-01 14:35:54 -04:00
|
|
|
(btm_cb.pm_pend_link_hdl != BTM_INVALID_HANDLE) ) { /* command pending */
|
|
|
|
if (p_acl_cb->hci_handle != btm_cb.pm_pend_link_hdl) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* set the stored mask */
|
|
|
|
p_cb->state |= BTM_PM_STORED_MASK;
|
2020-07-01 14:35:54 -04:00
|
|
|
BTM_TRACE_DEBUG( "btm_pm state stored:%d", p_acl_cb->hci_handle);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
return BTM_CMD_STORED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-01 14:35:54 -04:00
|
|
|
return btm_pm_snd_md_req(pm_id, p_acl_cb->hci_handle, p_mode);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_ReadPowerMode
|
|
|
|
**
|
|
|
|
** Description This returns the current mode for a specific
|
|
|
|
** ACL connection.
|
|
|
|
**
|
|
|
|
** Input Param remote_bda - device address of desired ACL connection
|
|
|
|
**
|
|
|
|
** Output Param p_mode - address where the current mode is copied into.
|
|
|
|
** BTM_ACL_MODE_NORMAL
|
|
|
|
** BTM_ACL_MODE_HOLD
|
|
|
|
** BTM_ACL_MODE_SNIFF
|
|
|
|
** BTM_ACL_MODE_PARK
|
|
|
|
** (valid only if return code is BTM_SUCCESS)
|
|
|
|
**
|
|
|
|
** Returns BTM_SUCCESS if successful,
|
|
|
|
** BTM_UNKNOWN_ADDR if bd addr is not active or bad
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_ReadPowerMode (BD_ADDR remote_bda, tBTM_PM_MODE *p_mode)
|
|
|
|
{
|
2020-07-01 14:35:54 -04:00
|
|
|
tACL_CONN *p_acl_cb = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
|
|
|
|
if (!p_acl_cb) {
|
2016-09-26 09:37:39 -04:00
|
|
|
return (BTM_UNKNOWN_ADDR);
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2020-07-01 14:35:54 -04:00
|
|
|
*p_mode = p_acl_cb->p_pm_mode_db->state;
|
2016-09-26 09:37:39 -04:00
|
|
|
return BTM_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_SetSsrParams
|
|
|
|
**
|
|
|
|
** Description This sends the given SSR parameters for the given ACL
|
|
|
|
** connection if it is in ACTIVE mode.
|
|
|
|
**
|
|
|
|
** Input Param remote_bda - device address of desired ACL connection
|
|
|
|
** max_lat - maximum latency (in 0.625ms)(0-0xFFFE)
|
|
|
|
** min_rmt_to - minimum remote timeout
|
|
|
|
** min_loc_to - minimum local timeout
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns BTM_SUCCESS if the HCI command is issued successful,
|
|
|
|
** BTM_UNKNOWN_ADDR if bd addr is not active or bad
|
|
|
|
** BTM_CMD_STORED if the command is stored
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_SetSsrParams (BD_ADDR remote_bda, UINT16 max_lat,
|
|
|
|
UINT16 min_rmt_to, UINT16 min_loc_to)
|
|
|
|
{
|
|
|
|
#if (BTM_SSR_INCLUDED == TRUE)
|
|
|
|
int acl_ind;
|
|
|
|
tBTM_PM_MCB *p_cb;
|
2020-07-01 14:35:54 -04:00
|
|
|
tACL_CONN *p_acl_cb = NULL;
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if ( (acl_ind = btm_pm_find_acl_ind(remote_bda)) == MAX_L2CAP_LINKS) {
|
2016-09-26 09:37:39 -04:00
|
|
|
return (BTM_UNKNOWN_ADDR);
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2020-07-01 14:35:54 -04:00
|
|
|
p_acl_cb = btm_bda_to_acl(remote_bda);
|
|
|
|
if (!p_acl_cb) {
|
|
|
|
return (BTM_UNKNOWN_ADDR);
|
|
|
|
}
|
|
|
|
p_cb = p_acl_cb->p_pm_mode_db;
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2020-07-01 14:35:54 -04:00
|
|
|
if (BTM_PM_STS_ACTIVE == p_cb->state ||
|
|
|
|
BTM_PM_STS_SNIFF == p_cb->state) {
|
|
|
|
if (btsnd_hcic_sniff_sub_rate(p_acl_cb->hci_handle, max_lat,
|
2016-11-24 13:10:15 -05:00
|
|
|
min_rmt_to, min_loc_to)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
return BTM_SUCCESS;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else {
|
2016-09-26 09:37:39 -04:00
|
|
|
return BTM_NO_RESOURCES;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
p_cb->max_lat = max_lat;
|
|
|
|
p_cb->min_rmt_to = min_rmt_to;
|
|
|
|
p_cb->min_loc_to = min_loc_to;
|
|
|
|
return BTM_CMD_STORED;
|
|
|
|
#else
|
|
|
|
return BTM_ILLEGAL_ACTION;
|
|
|
|
#endif // BTM_SSR_INCLUDED
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_pm_reset
|
|
|
|
**
|
|
|
|
** Description as a part of the BTM reset process.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_pm_reset(void)
|
|
|
|
{
|
|
|
|
int xx;
|
|
|
|
tBTM_PM_STATUS_CBACK *cb = NULL;
|
|
|
|
|
|
|
|
/* clear the pending request for application */
|
2016-11-24 13:10:15 -05:00
|
|
|
if ( (btm_cb.pm_pend_id != BTM_PM_SET_ONLY_ID) &&
|
|
|
|
(btm_cb.pm_reg_db[btm_cb.pm_pend_id].mask & BTM_PM_REG_NOTIF) ) {
|
2016-09-26 09:37:39 -04:00
|
|
|
cb = btm_cb.pm_reg_db[btm_cb.pm_pend_id].cback;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* clear the register record */
|
2016-11-24 13:10:15 -05:00
|
|
|
for (xx = 0; xx < BTM_MAX_PM_RECORDS; xx++) {
|
2016-09-26 09:37:39 -04:00
|
|
|
btm_cb.pm_reg_db[xx].mask = BTM_PM_REC_NOT_USED;
|
|
|
|
}
|
|
|
|
|
2020-07-01 14:35:54 -04:00
|
|
|
if (cb != NULL && btm_cb.pm_pend_link_hdl != BTM_INVALID_HANDLE) {
|
|
|
|
(*cb)((btm_handle_to_acl(btm_cb.pm_pend_link_hdl))->remote_addr, BTM_PM_STS_ERROR, BTM_DEV_RESET, 0);
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* no command pending */
|
2020-07-01 14:35:54 -04:00
|
|
|
btm_cb.pm_pend_link_hdl = BTM_INVALID_HANDLE;
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_pm_sm_alloc
|
|
|
|
**
|
|
|
|
** Description This function initializes the control block of an ACL link.
|
|
|
|
** It is called when an ACL connection is created.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2020-07-01 14:35:54 -04:00
|
|
|
tBTM_PM_MCB *btm_pm_sm_alloc(void)
|
2016-09-26 09:37:39 -04:00
|
|
|
{
|
2020-07-01 14:35:54 -04:00
|
|
|
tBTM_PM_MCB *p_db = (tBTM_PM_MCB *) osi_malloc(sizeof(tBTM_PM_MCB)); /* per ACL link */
|
|
|
|
if (p_db) {
|
|
|
|
memset (p_db, 0, sizeof(tBTM_PM_MCB));
|
|
|
|
p_db->state = BTM_PM_ST_ACTIVE;
|
|
|
|
if (list_length(btm_cb.p_pm_mode_db_list) >= MAX_L2CAP_LINKS) {
|
|
|
|
osi_free(p_db);
|
|
|
|
p_db = NULL;
|
|
|
|
}
|
|
|
|
if (!list_append(btm_cb.p_pm_mode_db_list, p_db)) {
|
|
|
|
osi_free(p_db);
|
|
|
|
p_db = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return p_db;
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_pm_find_acl_ind
|
|
|
|
**
|
|
|
|
** Description This function initializes the control block of an ACL link.
|
|
|
|
** It is called when an ACL connection is created.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_pm_compare_modes
|
|
|
|
** Description get the "more active" mode of the 2
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2016-11-24 13:10:15 -05:00
|
|
|
static tBTM_PM_PWR_MD *btm_pm_compare_modes(tBTM_PM_PWR_MD *p_md1, tBTM_PM_PWR_MD *p_md2, tBTM_PM_PWR_MD *p_res)
|
2016-09-26 09:37:39 -04:00
|
|
|
{
|
|
|
|
UINT8 res;
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_md1 == NULL) {
|
2016-09-26 09:37:39 -04:00
|
|
|
*p_res = *p_md2;
|
|
|
|
p_res->mode &= ~BTM_PM_MD_FORCE;
|
|
|
|
|
|
|
|
return p_md2;
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_md2->mode == BTM_PM_MD_ACTIVE || p_md1->mode == BTM_PM_MD_ACTIVE) {
|
2016-09-26 09:37:39 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if force bit is involved */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_md1->mode & BTM_PM_MD_FORCE) {
|
2016-09-26 09:37:39 -04:00
|
|
|
*p_res = *p_md1;
|
|
|
|
p_res->mode &= ~BTM_PM_MD_FORCE;
|
|
|
|
return p_res;
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_md2->mode & BTM_PM_MD_FORCE) {
|
2016-09-26 09:37:39 -04:00
|
|
|
*p_res = *p_md2;
|
|
|
|
p_res->mode &= ~BTM_PM_MD_FORCE;
|
|
|
|
return p_res;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = (p_md1->mode - 1) * BTM_PM_NUM_SET_MODES + (p_md2->mode - 1);
|
|
|
|
res = btm_pm_md_comp_matrix[res];
|
2016-11-24 13:10:15 -05:00
|
|
|
switch (res) {
|
2016-09-26 09:37:39 -04:00
|
|
|
case BTM_PM_GET_MD1:
|
|
|
|
*p_res = *p_md1;
|
|
|
|
return p_md1;
|
|
|
|
|
|
|
|
case BTM_PM_GET_MD2:
|
|
|
|
*p_res = *p_md2;
|
|
|
|
return p_md2;
|
|
|
|
|
|
|
|
case BTM_PM_GET_COMP:
|
|
|
|
p_res->mode = p_md1->mode;
|
|
|
|
/* min of the two */
|
2016-11-24 13:10:15 -05:00
|
|
|
p_res->max = (p_md1->max < p_md2->max) ? (p_md1->max) : (p_md2->max);
|
2016-09-26 09:37:39 -04:00
|
|
|
/* max of the two */
|
2016-11-24 13:10:15 -05:00
|
|
|
p_res->min = (p_md1->min > p_md2->min) ? (p_md1->min) : (p_md2->min);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* the intersection is NULL */
|
2016-11-24 13:10:15 -05:00
|
|
|
if ( p_res->max < p_res->min) {
|
2016-09-26 09:37:39 -04:00
|
|
|
return NULL;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_res->mode == BTM_PM_MD_SNIFF) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* max of the two */
|
2016-11-24 13:10:15 -05:00
|
|
|
p_res->attempt = (p_md1->attempt > p_md2->attempt) ? (p_md1->attempt) : (p_md2->attempt);
|
|
|
|
p_res->timeout = (p_md1->timeout > p_md2->timeout) ? (p_md1->timeout) : (p_md2->timeout);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
return p_res;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_pm_get_set_mode
|
|
|
|
** Description get the resulting mode from the registered parties, then compare it
|
|
|
|
** with the requested mode, if the command is from an unregistered party.
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static tBTM_PM_MODE btm_pm_get_set_mode(UINT8 pm_id, tBTM_PM_MCB *p_cb, tBTM_PM_PWR_MD *p_mode, tBTM_PM_PWR_MD *p_res)
|
|
|
|
{
|
|
|
|
int xx, loop_max;
|
|
|
|
tBTM_PM_PWR_MD *p_md = NULL;
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_mode != NULL && p_mode->mode & BTM_PM_MD_FORCE) {
|
2016-09-26 09:37:39 -04:00
|
|
|
*p_res = *p_mode;
|
|
|
|
p_res->mode &= ~BTM_PM_MD_FORCE;
|
|
|
|
return p_res->mode;
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (!p_mode) {
|
|
|
|
loop_max = BTM_MAX_PM_RECORDS + 1;
|
|
|
|
} else {
|
2016-09-26 09:37:39 -04:00
|
|
|
loop_max = BTM_MAX_PM_RECORDS;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
for ( xx = 0; xx < loop_max; xx++) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* g through all the registered "set" parties */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (btm_cb.pm_reg_db[xx].mask & BTM_PM_REG_SET) {
|
|
|
|
if (p_cb->req_mode[xx].mode == BTM_PM_MD_ACTIVE) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* if at least one registered (SET) party says ACTIVE, stay active */
|
|
|
|
return BTM_PM_MD_ACTIVE;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* if registered parties give conflicting information, stay active */
|
2016-11-24 13:10:15 -05:00
|
|
|
if ( (btm_pm_compare_modes(p_md, &p_cb->req_mode[xx], p_res)) == NULL) {
|
2016-09-26 09:37:39 -04:00
|
|
|
return BTM_PM_MD_ACTIVE;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
p_md = p_res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if the resulting mode is NULL(nobody registers SET), use the requested mode */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_md == NULL) {
|
|
|
|
if (p_mode) {
|
2016-09-26 09:37:39 -04:00
|
|
|
*p_res = *((tBTM_PM_PWR_MD *)p_mode);
|
2016-11-24 13:10:15 -05:00
|
|
|
} else { /* p_mode is NULL when btm_pm_snd_md_req is called from btm_pm_proc_mode_change */
|
2016-09-26 09:37:39 -04:00
|
|
|
return BTM_PM_MD_ACTIVE;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
|
|
|
} else {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* if the command is from unregistered party,
|
|
|
|
compare the resulting mode from registered party*/
|
2016-11-24 13:10:15 -05:00
|
|
|
if ( (pm_id == BTM_PM_SET_ONLY_ID) &&
|
|
|
|
((btm_pm_compare_modes(p_mode, p_md, p_res)) == NULL) ) {
|
2016-09-26 09:37:39 -04:00
|
|
|
return BTM_PM_MD_ACTIVE;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return p_res->mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_pm_snd_md_req
|
|
|
|
** Description get the resulting mode and send the resuest to host controller
|
|
|
|
** Returns tBTM_STATUS
|
|
|
|
**, BOOLEAN *p_chg_ind
|
|
|
|
*******************************************************************************/
|
2020-07-01 14:35:54 -04:00
|
|
|
static tBTM_STATUS btm_pm_snd_md_req(UINT8 pm_id, UINT16 link_hdl, tBTM_PM_PWR_MD *p_mode)
|
2016-09-26 09:37:39 -04:00
|
|
|
{
|
|
|
|
tBTM_PM_PWR_MD md_res;
|
|
|
|
tBTM_PM_MODE mode;
|
2020-07-01 14:35:54 -04:00
|
|
|
tACL_CONN *p_acl_cb = btm_handle_to_acl(link_hdl);
|
|
|
|
tBTM_PM_MCB *p_cb = p_acl_cb->p_pm_mode_db;
|
2016-09-26 09:37:39 -04:00
|
|
|
BOOLEAN chg_ind = FALSE;
|
|
|
|
|
|
|
|
mode = btm_pm_get_set_mode(pm_id, p_cb, p_mode, &md_res);
|
|
|
|
md_res.mode = mode;
|
|
|
|
|
|
|
|
#if BTM_PM_DEBUG == TRUE
|
2020-07-01 14:35:54 -04:00
|
|
|
BTM_TRACE_DEBUG( "btm_pm_snd_md_req link_hdl:%d, mode: %d",
|
|
|
|
link_hdl, mode);
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif // BTM_PM_DEBUG
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if ( p_cb->state == mode) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* already in the resulting mode */
|
2016-11-24 13:10:15 -05:00
|
|
|
if ( (mode == BTM_PM_MD_ACTIVE) ||
|
|
|
|
((md_res.max >= p_cb->interval) && (md_res.min <= p_cb->interval)) ) {
|
2016-09-26 09:37:39 -04:00
|
|
|
return BTM_CMD_STORED;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
/* Otherwise, needs to wake, then sleep */
|
|
|
|
chg_ind = TRUE;
|
|
|
|
}
|
|
|
|
p_cb->chg_ind = chg_ind;
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
/* cannot go directly from current mode to resulting mode. */
|
|
|
|
if ( mode != BTM_PM_MD_ACTIVE && p_cb->state != BTM_PM_MD_ACTIVE) {
|
|
|
|
p_cb->chg_ind = TRUE; /* needs to wake, then sleep */
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_cb->chg_ind == TRUE) { /* needs to wake first */
|
2016-09-26 09:37:39 -04:00
|
|
|
md_res.mode = BTM_PM_MD_ACTIVE;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
#if (BTM_SSR_INCLUDED == TRUE)
|
2016-11-24 13:10:15 -05:00
|
|
|
else if (BTM_PM_MD_SNIFF == md_res.mode && p_cb->max_lat) {
|
2020-07-01 14:35:54 -04:00
|
|
|
btsnd_hcic_sniff_sub_rate(link_hdl, p_cb->max_lat,
|
2016-09-26 09:37:39 -04:00
|
|
|
p_cb->min_rmt_to, p_cb->min_loc_to);
|
|
|
|
p_cb->max_lat = 0;
|
|
|
|
}
|
|
|
|
#endif // BTM_SSR_INCLUDED
|
|
|
|
/* Default is failure */
|
2020-07-01 14:35:54 -04:00
|
|
|
btm_cb.pm_pend_link_hdl = BTM_INVALID_HANDLE;
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* send the appropriate HCI command */
|
|
|
|
btm_cb.pm_pend_id = pm_id;
|
|
|
|
|
|
|
|
#if BTM_PM_DEBUG == TRUE
|
2020-07-01 14:35:54 -04:00
|
|
|
BTM_TRACE_DEBUG("btm_pm_snd_md_req state:0x%x, link_hdl: %d", p_cb->state, link_hdl);
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif // BTM_PM_DEBUG
|
|
|
|
|
2018-04-24 22:11:06 -04:00
|
|
|
BTM_TRACE_DEBUG("%s switching from %s to %s.", __func__, mode_to_string(p_cb->state), mode_to_string(md_res.mode));
|
2016-11-24 13:10:15 -05:00
|
|
|
switch (md_res.mode) {
|
2016-09-26 09:37:39 -04:00
|
|
|
case BTM_PM_MD_ACTIVE:
|
2016-11-24 13:10:15 -05:00
|
|
|
switch (p_cb->state) {
|
2016-09-26 09:37:39 -04:00
|
|
|
case BTM_PM_MD_SNIFF:
|
2020-07-01 14:35:54 -04:00
|
|
|
if (btsnd_hcic_exit_sniff_mode(link_hdl)) {
|
|
|
|
btm_cb.pm_pend_link_hdl = link_hdl;
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BTM_PM_MD_PARK:
|
2020-07-01 14:35:54 -04:00
|
|
|
if (btsnd_hcic_exit_park_mode(link_hdl)) {
|
|
|
|
btm_cb.pm_pend_link_hdl = link_hdl;
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Failure btm_cb.pm_pend_link = MAX_L2CAP_LINKS */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTM_PM_MD_HOLD:
|
2020-07-01 14:35:54 -04:00
|
|
|
if (btsnd_hcic_hold_mode (link_hdl,
|
2016-11-24 13:10:15 -05:00
|
|
|
md_res.max, md_res.min)) {
|
2020-07-01 14:35:54 -04:00
|
|
|
btm_cb.pm_pend_link_hdl = link_hdl;
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTM_PM_MD_SNIFF:
|
2020-07-01 14:35:54 -04:00
|
|
|
if (btsnd_hcic_sniff_mode (link_hdl,
|
2016-09-26 09:37:39 -04:00
|
|
|
md_res.max, md_res.min, md_res.attempt,
|
2016-11-24 13:10:15 -05:00
|
|
|
md_res.timeout)) {
|
2020-07-01 14:35:54 -04:00
|
|
|
btm_cb.pm_pend_link_hdl = link_hdl;
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTM_PM_MD_PARK:
|
2020-07-01 14:35:54 -04:00
|
|
|
if (btsnd_hcic_park_mode (link_hdl,
|
2016-11-24 13:10:15 -05:00
|
|
|
md_res.max, md_res.min)) {
|
2020-07-01 14:35:54 -04:00
|
|
|
btm_cb.pm_pend_link_hdl = link_hdl;
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Failure btm_cb.pm_pend_link = MAX_L2CAP_LINKS */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-07-01 14:35:54 -04:00
|
|
|
if (btm_cb.pm_pend_link_hdl == BTM_INVALID_HANDLE) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* the command was not sent */
|
|
|
|
#if BTM_PM_DEBUG == TRUE
|
2020-07-01 14:35:54 -04:00
|
|
|
BTM_TRACE_DEBUG( "pm_pend_link_hdl: %d", btm_cb.pm_pend_link_hdl);
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif // BTM_PM_DEBUG
|
|
|
|
return (BTM_NO_RESOURCES);
|
|
|
|
}
|
|
|
|
|
|
|
|
return BTM_CMD_STARTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_pm_check_stored
|
|
|
|
**
|
|
|
|
** Description This function is called when an HCI command status event occurs
|
|
|
|
** to check if there's any PM command issued while waiting for
|
|
|
|
** HCI command status.
|
|
|
|
**
|
|
|
|
** Returns none.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void btm_pm_check_stored(void)
|
|
|
|
{
|
2020-07-01 14:35:54 -04:00
|
|
|
tACL_CONN *p_acl_cb = NULL;
|
|
|
|
list_node_t *p_node = NULL;
|
|
|
|
for (p_node = list_begin(btm_cb.p_acl_db_list); p_node; p_node = list_next(p_node)) {
|
|
|
|
p_acl_cb = list_node(p_node);
|
|
|
|
if (p_acl_cb->p_pm_mode_db->state & BTM_PM_STORED_MASK) {
|
|
|
|
p_acl_cb->p_pm_mode_db->state &= ~BTM_PM_STORED_MASK;
|
|
|
|
BTM_TRACE_DEBUG( "btm_pm_check_stored :%d", p_acl_cb->hci_handle);
|
|
|
|
btm_pm_snd_md_req(BTM_PM_SET_ONLY_ID, p_acl_cb->hci_handle, NULL);
|
2016-09-26 09:37:39 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-07-01 14:35:54 -04:00
|
|
|
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_pm_proc_cmd_status
|
|
|
|
**
|
|
|
|
** Description This function is called when an HCI command status event occurs
|
|
|
|
** for power manager related commands.
|
|
|
|
**
|
|
|
|
** Input Parms status - status of the event (HCI_SUCCESS if no errors)
|
|
|
|
**
|
|
|
|
** Returns none.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_pm_proc_cmd_status(UINT8 status)
|
|
|
|
{
|
|
|
|
tBTM_PM_MCB *p_cb;
|
|
|
|
tBTM_PM_STATUS pm_status;
|
2020-07-01 14:35:54 -04:00
|
|
|
tACL_CONN *p_acl_cb;
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2020-07-01 14:35:54 -04:00
|
|
|
if (btm_cb.pm_pend_link_hdl == BTM_INVALID_HANDLE) {
|
2016-09-26 09:37:39 -04:00
|
|
|
return;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2020-07-01 14:35:54 -04:00
|
|
|
|
|
|
|
p_acl_cb = btm_handle_to_acl(btm_cb.pm_pend_link_hdl);
|
|
|
|
p_cb = p_acl_cb->p_pm_mode_db;
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (status == HCI_SUCCESS) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p_cb->state = BTM_PM_ST_PENDING;
|
|
|
|
pm_status = BTM_PM_STS_PENDING;
|
|
|
|
#if BTM_PM_DEBUG == TRUE
|
|
|
|
BTM_TRACE_DEBUG( "btm_pm_proc_cmd_status new state:0x%x", p_cb->state);
|
|
|
|
#endif // BTM_PM_DEBUG
|
2016-11-24 13:10:15 -05:00
|
|
|
} else { /* the command was not successfull. Stay in the same state */
|
2016-09-26 09:37:39 -04:00
|
|
|
pm_status = BTM_PM_STS_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* notify the caller is appropriate */
|
2016-11-24 13:10:15 -05:00
|
|
|
if ( (btm_cb.pm_pend_id != BTM_PM_SET_ONLY_ID) &&
|
|
|
|
(btm_cb.pm_reg_db[btm_cb.pm_pend_id].mask & BTM_PM_REG_NOTIF) ) {
|
2020-07-01 14:35:54 -04:00
|
|
|
(*btm_cb.pm_reg_db[btm_cb.pm_pend_id].cback)(p_acl_cb->remote_addr, pm_status, 0, status);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* no pending cmd now */
|
|
|
|
#if BTM_PM_DEBUG == TRUE
|
|
|
|
BTM_TRACE_DEBUG( "btm_pm_proc_cmd_status state:0x%x, pm_pend_link: %d(new: %d)",
|
2020-07-01 14:35:54 -04:00
|
|
|
p_cb->state, btm_cb.pm_pend_link_hdl, MAX_L2CAP_LINKS);
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif // BTM_PM_DEBUG
|
2020-07-01 14:35:54 -04:00
|
|
|
btm_cb.pm_pend_link_hdl = BTM_INVALID_HANDLE;
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
btm_pm_check_stored();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_process_mode_change
|
|
|
|
**
|
|
|
|
** Description This function is called when an HCI mode change event occurs.
|
|
|
|
**
|
|
|
|
** Input Parms hci_status - status of the event (HCI_SUCCESS if no errors)
|
|
|
|
** hci_handle - connection handle associated with the change
|
|
|
|
** mode - HCI_MODE_ACTIVE, HCI_MODE_HOLD, HCI_MODE_SNIFF, or HCI_MODE_PARK
|
|
|
|
** interval - number of baseband slots (meaning depends on mode)
|
|
|
|
**
|
|
|
|
** Returns none.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_pm_proc_mode_change (UINT8 hci_status, UINT16 hci_handle, UINT8 mode, UINT16 interval)
|
|
|
|
{
|
|
|
|
tACL_CONN *p;
|
|
|
|
tBTM_PM_MCB *p_cb = NULL;
|
2020-07-01 14:35:54 -04:00
|
|
|
int yy;
|
2016-09-26 09:37:39 -04:00
|
|
|
tBTM_PM_STATE old_state;
|
|
|
|
tL2C_LCB *p_lcb;
|
|
|
|
|
|
|
|
/* get the index to acl_db */
|
2020-07-01 14:35:54 -04:00
|
|
|
p = btm_handle_to_acl(hci_handle);
|
|
|
|
if (!p) {
|
2016-09-26 09:37:39 -04:00
|
|
|
return;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* update control block */
|
2020-07-01 14:35:54 -04:00
|
|
|
p_cb = p->p_pm_mode_db;
|
2016-09-26 09:37:39 -04:00
|
|
|
old_state = p_cb->state;
|
|
|
|
p_cb->state = mode;
|
|
|
|
p_cb->interval = interval;
|
|
|
|
|
2018-04-24 22:11:06 -04:00
|
|
|
BTM_TRACE_DEBUG("%s switched from %s to %s.", __func__, mode_to_string(old_state), mode_to_string(p_cb->state));
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if ((p_lcb = l2cu_find_lcb_by_bd_addr(p->remote_addr, BT_TRANSPORT_BR_EDR)) != NULL) {
|
|
|
|
if ((p_cb->state == BTM_PM_ST_ACTIVE) || (p_cb->state == BTM_PM_ST_SNIFF)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* There might be any pending packets due to SNIFF or PENDING state */
|
|
|
|
/* Trigger L2C to start transmission of the pending packets. */
|
|
|
|
BTM_TRACE_DEBUG("btm mode change to active; check l2c_link for outgoing packets");
|
|
|
|
l2c_link_check_send_pkts(p_lcb, NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* notify registered parties */
|
2016-11-24 13:10:15 -05:00
|
|
|
for (yy = 0; yy <= BTM_MAX_PM_RECORDS; yy++) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* set req_mode HOLD mode->ACTIVE */
|
2016-11-24 13:10:15 -05:00
|
|
|
if ( (mode == BTM_PM_MD_ACTIVE) && (p_cb->req_mode[yy].mode == BTM_PM_MD_HOLD) ) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p_cb->req_mode[yy].mode = BTM_PM_MD_ACTIVE;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* new request has been made. - post a message to BTU task */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (old_state & BTM_PM_STORED_MASK) {
|
2016-09-26 09:37:39 -04:00
|
|
|
#if BTM_PM_DEBUG == TRUE
|
|
|
|
BTM_TRACE_DEBUG( "btm_pm_proc_mode_change: Sending stored req:%d", xx);
|
|
|
|
#endif // BTM_PM_DEBUG
|
2020-07-01 14:35:54 -04:00
|
|
|
btm_pm_snd_md_req(BTM_PM_SET_ONLY_ID, hci_handle, NULL);
|
2016-11-24 13:10:15 -05:00
|
|
|
} else {
|
2020-07-01 14:35:54 -04:00
|
|
|
list_node_t *p_node = NULL;
|
|
|
|
|
|
|
|
for (p_node =(list_begin(btm_cb.p_pm_mode_db_list)); p_node; p_node = (list_next(p_node))) {
|
|
|
|
p_cb = (tBTM_PM_MCB *)list_node(p_node);
|
|
|
|
if (p_cb->chg_ind == TRUE) {
|
2016-09-26 09:37:39 -04:00
|
|
|
#if BTM_PM_DEBUG == TRUE
|
|
|
|
BTM_TRACE_DEBUG( "btm_pm_proc_mode_change: Sending PM req :%d", zz);
|
|
|
|
#endif // BTM_PM_DEBUG
|
2020-07-01 14:35:54 -04:00
|
|
|
btm_pm_snd_md_req(BTM_PM_SET_ONLY_ID, hci_handle, NULL);
|
2016-09-26 09:37:39 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* notify registered parties */
|
2016-11-24 13:10:15 -05:00
|
|
|
for (yy = 0; yy < BTM_MAX_PM_RECORDS; yy++) {
|
|
|
|
if (btm_cb.pm_reg_db[yy].mask & BTM_PM_REG_NOTIF) {
|
2016-09-26 09:37:39 -04:00
|
|
|
(*btm_cb.pm_reg_db[yy].cback)( p->remote_addr, mode, interval, hci_status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If mode change was because of an active role switch or change link key */
|
|
|
|
btm_cont_rswitch(p, btm_find_dev(p->remote_addr), hci_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_pm_proc_ssr_evt
|
|
|
|
**
|
|
|
|
** Description This function is called when an HCI sniff subrating event occurs.
|
|
|
|
**
|
|
|
|
** Returns none.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
#if (BTM_SSR_INCLUDED == TRUE)
|
|
|
|
void btm_pm_proc_ssr_evt (UINT8 *p, UINT16 evt_len)
|
|
|
|
{
|
|
|
|
UINT8 status;
|
|
|
|
UINT16 handle;
|
|
|
|
UINT16 max_rx_lat;
|
|
|
|
int xx, yy;
|
|
|
|
tBTM_PM_MCB *p_cb;
|
2016-11-24 13:10:15 -05:00
|
|
|
tACL_CONN *p_acl = NULL;
|
2016-09-26 09:37:39 -04:00
|
|
|
UINT16 use_ssr = TRUE;
|
|
|
|
UNUSED(evt_len);
|
|
|
|
|
|
|
|
STREAM_TO_UINT8 (status, p);
|
|
|
|
|
|
|
|
STREAM_TO_UINT16 (handle, p);
|
|
|
|
/* get the index to acl_db */
|
|
|
|
|
|
|
|
p += 2;
|
|
|
|
STREAM_TO_UINT16 (max_rx_lat, p);
|
2020-07-01 14:35:54 -04:00
|
|
|
p_acl = btm_handle_to_acl(handle);
|
|
|
|
if (!p_acl) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
p_cb = p_acl->p_pm_mode_db;
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_cb->interval == max_rx_lat) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* using legacy sniff */
|
|
|
|
use_ssr = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* notify registered parties */
|
2016-11-24 13:10:15 -05:00
|
|
|
for (yy = 0; yy < BTM_MAX_PM_RECORDS; yy++) {
|
|
|
|
if (btm_cb.pm_reg_db[yy].mask & BTM_PM_REG_NOTIF) {
|
|
|
|
if ( p_acl) {
|
2016-09-26 09:37:39 -04:00
|
|
|
(*btm_cb.pm_reg_db[yy].cback)( p_acl->remote_addr, BTM_PM_STS_SSR, use_ssr, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // BTM_SSR_INCLUDED
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_pm_device_in_active_or_sniff_mode
|
|
|
|
**
|
|
|
|
** Description This function is called to check if in active or sniff mode
|
|
|
|
**
|
|
|
|
** Returns TRUE, if in active or sniff mode
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
BOOLEAN btm_pm_device_in_active_or_sniff_mode(void)
|
|
|
|
{
|
|
|
|
/* The active state is the highest state-includes connected device and sniff mode*/
|
|
|
|
|
|
|
|
/* Covers active and sniff modes */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (BTM_GetNumAclLinks() > 0) {
|
2016-09-26 09:37:39 -04:00
|
|
|
BTM_TRACE_DEBUG("%s - ACL links: %d", __func__, BTM_GetNumAclLinks());
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if ((defined BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
|
|
|
|
/* Check BLE states */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (btm_ble_get_conn_st() != BLE_CONN_IDLE) {
|
2016-09-26 09:37:39 -04:00
|
|
|
BTM_TRACE_DEBUG("%s - BLE state: %x", __func__, btm_ble_get_conn_st());
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_pm_device_in_scan_state
|
|
|
|
**
|
|
|
|
** Description This function is called to check if in paging, inquiry or connecting mode
|
|
|
|
**
|
|
|
|
** Returns TRUE, if in paging, inquiry or connecting mode
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
BOOLEAN btm_pm_device_in_scan_state(void)
|
|
|
|
{
|
|
|
|
/* Scan state-paging, inquiry, and trying to connect */
|
|
|
|
|
|
|
|
/* Check for paging */
|
2017-08-17 09:13:45 -04:00
|
|
|
if (btm_cb.is_paging || (!fixed_queue_is_empty(btm_cb.page_queue)) ||
|
2016-11-24 13:10:15 -05:00
|
|
|
BTM_BL_PAGING_STARTED == btm_cb.busy_level) {
|
|
|
|
BTM_TRACE_DEBUG("btm_pm_device_in_scan_state- paging");
|
|
|
|
return TRUE;
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for inquiry */
|
2016-11-24 13:10:15 -05:00
|
|
|
if ((btm_cb.btm_inq_vars.inq_active & (BTM_BR_INQ_ACTIVE_MASK | BTM_BLE_INQ_ACTIVE_MASK)) != 0) {
|
2016-09-26 09:37:39 -04:00
|
|
|
BTM_TRACE_DEBUG("btm_pm_device_in_scan_state- Inq active");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_PM_ReadControllerState
|
|
|
|
**
|
|
|
|
** Description This function is called to obtain the controller state
|
|
|
|
**
|
|
|
|
** Returns Controller State-BTM_CONTRL_ACTIVE, BTM_CONTRL_SCAN, and BTM_CONTRL_IDLE
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_CONTRL_STATE BTM_PM_ReadControllerState(void)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
if (TRUE == btm_pm_device_in_active_or_sniff_mode()) {
|
|
|
|
return BTM_CONTRL_ACTIVE;
|
|
|
|
} else if (TRUE == btm_pm_device_in_scan_state()) {
|
|
|
|
return BTM_CONTRL_SCAN;
|
|
|
|
} else {
|
|
|
|
return BTM_CONTRL_IDLE;
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2019-03-15 08:59:55 -04:00
|
|
|
#if (!CONFIG_BT_STACK_NO_LOG)
|
2016-11-24 13:10:15 -05:00
|
|
|
static const char *mode_to_string(tBTM_PM_MODE mode)
|
|
|
|
{
|
|
|
|
switch (mode) {
|
2016-09-26 09:37:39 -04:00
|
|
|
case BTM_PM_MD_ACTIVE: return "ACTIVE";
|
|
|
|
case BTM_PM_MD_SNIFF: return "SNIFF";
|
|
|
|
case BTM_PM_MD_PARK: return "PARK";
|
|
|
|
case BTM_PM_MD_HOLD: return "HOLD";
|
|
|
|
default: return "UNKNOWN";
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
2019-03-15 08:59:55 -04:00
|
|
|
#endif
|