blob: 363f59db3d9a31bccc3b33c25034b0172e422c1b [file] [log] [blame]
Evan Chua24be4f2013-11-13 15:30:16 -05001/******************************************************************************
2 *
3 * Copyright (C) 2011-2012 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 ******************************************************************************/
Evan Chua24be4f2013-11-13 15:30:16 -050018#include "ProtoDispBluetoothHci.h"
Evan Chua24be4f2013-11-13 15:30:16 -050019#include <cutils/log.h>
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080020#include "_OverrideLog.h"
21#include "nfc_target.h"
Evan Chua24be4f2013-11-13 15:30:16 -050022
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080023extern uint8_t* HCIDisp1(char* p_descr, uint8_t* p_data);
Ruchi Kandoi512ee632017-01-03 13:59:10 -080024extern uint32_t ScrProtocolTraceFlag;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080025#define HCI_GEN_TRACE \
26 (TRACE_CTRL_GENERAL | TRACE_LAYER_HCI | TRACE_ORG_PROTO_DISP | hci_trace_type)
Ruchi Kandoi512ee632017-01-03 13:59:10 -080027static uint8_t hci_trace_type = 0;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080028static char* modes_str[] = {"No sleep mode",
29 "UART",
30 "UART with messaging",
31 "USB",
32 "H4IBSS",
33 "USB with host wake",
34 "SDIO",
35 "UART CS-N",
36 "SPI",
37 "H5",
38 "H4DS",
39 "",
40 "UART with BREAK"};
Ruchi Kandoi512ee632017-01-03 13:59:10 -080041static uint8_t* p_end_hci = NULL;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080042static uint8_t* HCIDisp1Ext(char* p_descr, uint8_t* p_data, char* p_ext);
43static void disp_sleepmode(uint8_t* p);
44static void disp_sleepmode_evt(uint8_t* p);
Evan Chua24be4f2013-11-13 15:30:16 -050045
46///////////////////////////////////////////
47///////////////////////////////////////////
48
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080049uint8_t* HCIDisp1Ext(char* p_descr, uint8_t* p_data, char* p_ext) {
50 if (p_data == p_end_hci) return p_data;
Evan Chua24be4f2013-11-13 15:30:16 -050051
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080052 char buff[200];
Evan Chua24be4f2013-11-13 15:30:16 -050053
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080054 sprintf(buff, "%40s : %u (0x%02x): %s", p_descr, *p_data, *p_data, p_ext);
Evan Chua24be4f2013-11-13 15:30:16 -050055
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080056 ScrLog(HCI_GEN_TRACE, "%s", buff);
57 return (p_data + 1);
Evan Chua24be4f2013-11-13 15:30:16 -050058}
59
Evan Chua24be4f2013-11-13 15:30:16 -050060/*******************************************************************************
61**
62** Function disp_sleepmode
63**
64** Description Displays VSC sleep mode
65**
66** Returns none.
67**
68*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080069void disp_sleepmode(uint8_t* p) {
70 hci_trace_type = TRACE_TYPE_CMD_TX;
71 ScrLog(HCI_GEN_TRACE, "--");
72 int len = p[2];
73 ScrLog(HCI_GEN_TRACE,
74 "SEND Command to HCI. Name: Set_Sleepmode_Param (Hex Code: 0xfc27 "
75 "Param Len: %d)",
76 len);
77 p += 3;
78 p_end_hci = p + len;
79 p = HCIDisp1Ext("Sleep_Mode", p, (*p <= 12) ? modes_str[*p] : "");
80 p = HCIDisp1("Idle_Threshold_Host", p);
81 p = HCIDisp1("Idle_Threshold_HC", p);
82 p = HCIDisp1Ext("BT_WAKE_Active_Mode", p,
83 (*p == 0) ? "Active Low" : ((*p == 1) ? "Active High" : ""));
84 p = HCIDisp1Ext("HOST_WAKE_Active_Mode", p,
85 (*p == 0) ? "Active Low" : ((*p == 1) ? "Active High" : ""));
86 p = HCIDisp1("Allow_Host_Sleep_During_SCO", p);
87 p = HCIDisp1("Combine_Sleep_Mode_And_LPM", p);
88 p = HCIDisp1("Enable_Tristate_Control_Of_UART_Tx_Line", p);
89 p = HCIDisp1Ext("Active_Connection_Handling_On_Suspend", p,
90 (*p == 0)
91 ? "Maintain connections; sleep when timed activity allows"
92 : ((*p == 1) ? "Sleep until resume is detected" : ""));
93 p = HCIDisp1("Resume_Timeout", p);
94 p = HCIDisp1("Enable_BREAK_To_Host", p);
95 p = HCIDisp1("Pulsed_HOST_WAKE", p);
Evan Chua24be4f2013-11-13 15:30:16 -050096
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080097 ScrLog(HCI_GEN_TRACE, "--");
Evan Chua24be4f2013-11-13 15:30:16 -050098}
99
Evan Chua24be4f2013-11-13 15:30:16 -0500100/*******************************************************************************
101**
102** Function disp_sleepmode_evt
103**
104** Description Displays HCI comand complete event for VSC sleep mode.
105**
106** Returns none.
107**
108*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800109void disp_sleepmode_evt(uint8_t* p) {
110 uint8_t len = p[1], status = p[5];
Evan Chua24be4f2013-11-13 15:30:16 -0500111
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800112 hci_trace_type = TRACE_TYPE_EVT_RX;
113 ScrLog(HCI_GEN_TRACE, "--");
114 ScrLog(HCI_GEN_TRACE,
115 "RCVD Event from HCI. Name: HCI_Command_Complete (Hex Code: 0x0e "
116 "Param Len: %d)",
117 len);
Evan Chua24be4f2013-11-13 15:30:16 -0500118
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800119 p = HCIDisp1("Num HCI Cmd Packets", p + 2);
120 ScrLog(HCI_GEN_TRACE, "%40s : 0xfc27 (Set_Sleepmode_Param)", "Cmd Code");
121 ScrLog(HCI_GEN_TRACE, "%40s : %d (0x%02x) %s", "Status", status, status,
122 (status == 0) ? "Success" : "");
123 ScrLog(HCI_GEN_TRACE, "--");
Evan Chua24be4f2013-11-13 15:30:16 -0500124}
125
126/*******************************************************************************
127**
128** Function ProtoDispBluetoothHciCmd
129**
130** Description Display a HCI command string
131**
132** Returns:
133** Nothing
134**
135*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800136void ProtoDispBluetoothHciCmd(NFC_HDR* p_buf) {
137 if (!(ScrProtocolTraceFlag & SCR_PROTO_TRACE_HCI_SUMMARY)) return;
138 uint8_t* p = (uint8_t*)(p_buf + 1) + p_buf->offset;
139 if (*(p) == 0x27 && *(p + 1) == 0xfc) // opcode sleep mode
140 {
141 disp_sleepmode(p);
142 }
Evan Chua24be4f2013-11-13 15:30:16 -0500143}
144
Evan Chua24be4f2013-11-13 15:30:16 -0500145/*******************************************************************************
146**
147** Function ProtoDispBluetoothHciEvt
148**
149** Description display a NCI event
150**
151** Returns:
152** Nothing
153**
154*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800155void ProtoDispBluetoothHciEvt(NFC_HDR* pBuffer) {
156 if (!(ScrProtocolTraceFlag & SCR_PROTO_TRACE_HCI_SUMMARY)) return;
Evan Chua24be4f2013-11-13 15:30:16 -0500157
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800158 uint8_t* p = (uint8_t*)(pBuffer + 1) + pBuffer->offset;
159 if (*p == 0x0e) // command complete
160 {
161 if (*(p + 1) == 4) // length
Evan Chua24be4f2013-11-13 15:30:16 -0500162 {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800163 if (*(p + 3) == 0x27 && *(p + 4) == 0xfc) // opcode 0x27fc (sleep mode)
164 {
165 disp_sleepmode_evt(p);
166 }
Evan Chua24be4f2013-11-13 15:30:16 -0500167 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800168 }
Evan Chua24be4f2013-11-13 15:30:16 -0500169}