]> granicus.if.org Git - esp-idf/blob - components/bt/bluedroid/stack/btm/btm_ble_cont_energy.c
Merge branch 'bugfix/spiram_malloc_reserve_internal_fragments' into 'master'
[esp-idf] / components / bt / bluedroid / stack / btm / btm_ble_cont_energy.c
1 /******************************************************************************
2  *
3  *  Copyright (C) 2014  Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18
19 #include <string.h>
20 #include "common/bt_target.h"
21
22 #if (BLE_INCLUDED == TRUE)
23 #include "stack/bt_types.h"
24 #include "stack/hcimsgs.h"
25 #include "stack/btu.h"
26 #include "btm_int.h"
27 //#include "bt_utils.h"
28 #include "stack/hcidefs.h"
29 #include "stack/btm_ble_api.h"
30
31 tBTM_BLE_ENERGY_INFO_CB ble_energy_info_cb;
32
33 /*******************************************************************************
34 **
35 ** Function         btm_ble_cont_energy_cmpl_cback
36 **
37 ** Description      Controller VSC complete callback
38 **
39 ** Parameters
40 **
41 ** Returns          void
42 **
43 *******************************************************************************/
44 void btm_ble_cont_energy_cmpl_cback (tBTM_VSC_CMPL *p_params)
45 {
46     UINT8  *p = p_params->p_param_buf;
47     UINT16  len = p_params->param_len;
48     UINT8  status = 0;
49     UINT32 total_tx_time = 0, total_rx_time = 0, total_idle_time = 0, total_energy_used = 0;
50
51     if (len < 17) {
52         BTM_TRACE_ERROR("wrong length for btm_ble_cont_energy_cmpl_cback");
53         return;
54     }
55
56     STREAM_TO_UINT8(status, p);
57     STREAM_TO_UINT32(total_tx_time, p);
58     STREAM_TO_UINT32(total_rx_time, p);
59     STREAM_TO_UINT32(total_idle_time, p);
60     STREAM_TO_UINT32(total_energy_used, p);
61
62     BTM_TRACE_DEBUG("energy_info status=%d,tx_t=%u, rx_t=%u, ener_used=%u, idle_t=%u",
63                     status, total_tx_time, total_rx_time, total_energy_used, total_idle_time);
64
65     if (NULL != ble_energy_info_cb.p_ener_cback)
66         ble_energy_info_cb.p_ener_cback(total_tx_time, total_rx_time, total_idle_time,
67                                         total_energy_used, status);
68
69     return;
70 }
71
72 /*******************************************************************************
73 **
74 ** Function         BTM_BleGetEnergyInfo
75 **
76 ** Description      This function obtains the energy info
77 **
78 ** Parameters      p_ener_cback - Callback pointer
79 **
80 ** Returns          status
81 **
82 *******************************************************************************/
83 tBTM_STATUS BTM_BleGetEnergyInfo(tBTM_BLE_ENERGY_INFO_CBACK *p_ener_cback)
84 {
85     tBTM_STATUS status = BTM_ILLEGAL_VALUE;
86     tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
87
88     BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb);
89
90     BTM_TRACE_EVENT("BTM_BleGetEnergyInfo\n");
91
92     if (0 == cmn_ble_vsc_cb.energy_support) {
93         BTM_TRACE_ERROR("Controller does not support get energy info\n");
94         return BTM_ERR_PROCESSING;
95     }
96
97     ble_energy_info_cb.p_ener_cback = p_ener_cback;
98     if ((status = BTM_VendorSpecificCommand (HCI_BLE_ENERGY_INFO_OCF, 0, NULL,
99                   btm_ble_cont_energy_cmpl_cback)) != BTM_CMD_STARTED) {
100         BTM_TRACE_ERROR("BTM_BleGetEnergyInfo status: %d", status);
101         return BTM_ILLEGAL_VALUE;
102     }
103
104     return status;
105 }
106
107 #endif
108