1/****************************************************************************** 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 ******************************************************************************/ 18#include "OverrideLog.h" 19#include "ProtoDispBluetoothHci.h" 20#include "nfc_target.h" 21#include <cutils/log.h> 22 23 24extern UINT8 *HCIDisp1 (char *p_descr, UINT8 *p_data); 25extern UINT32 ScrProtocolTraceFlag; 26#define HCI_GEN_TRACE (TRACE_CTRL_GENERAL | TRACE_LAYER_HCI | \ 27 TRACE_ORG_PROTO_DISP | hci_trace_type) 28static UINT8 hci_trace_type = 0; 29static char* modes_str [] = 30{ 31 "No sleep mode", 32 "UART", 33 "UART with messaging", 34 "USB", 35 "H4IBSS", 36 "USB with host wake", 37 "SDIO", 38 "UART CS-N", 39 "SPI", 40 "H5", 41 "H4DS", 42 "", 43 "UART with BREAK" 44}; 45static UINT8* p_end_hci = NULL; 46static UINT8* HCIDisp1Ext (char *p_descr, UINT8 *p_data, char * p_ext); 47static void disp_sleepmode (UINT8* p); 48static void disp_sleepmode_evt (UINT8* p); 49 50 51/////////////////////////////////////////// 52/////////////////////////////////////////// 53 54 55UINT8 *HCIDisp1Ext (char *p_descr, UINT8 *p_data, char * p_ext) 56{ 57 if (p_data == p_end_hci) 58 return p_data; 59 60 char buff[200]; 61 62 sprintf (buff, "%40s : %u (0x%02x): %s", p_descr, *p_data, *p_data, p_ext); 63 64 ScrLog (HCI_GEN_TRACE, "%s", buff); 65 return (p_data + 1); 66} 67 68 69/******************************************************************************* 70** 71** Function disp_sleepmode 72** 73** Description Displays VSC sleep mode 74** 75** Returns none. 76** 77*******************************************************************************/ 78void disp_sleepmode(UINT8 * p) 79{ 80 hci_trace_type = TRACE_TYPE_CMD_TX; 81 ScrLog (HCI_GEN_TRACE, "--"); 82 int len = p[2]; 83 ScrLog (HCI_GEN_TRACE, "SEND Command to HCI. Name: Set_Sleepmode_Param (Hex Code: 0xfc27 Param Len: %d)", len); 84 p += 3; 85 p_end_hci = p + len; 86 p = HCIDisp1Ext("Sleep_Mode", p, (*p <= 12) ? modes_str[*p] : ""); 87 p = HCIDisp1("Idle_Threshold_Host", p); 88 p = HCIDisp1("Idle_Threshold_HC", p); 89 p = HCIDisp1Ext("BT_WAKE_Active_Mode", p, (*p == 0) ? "Active Low" : ((*p == 1) ? "Active High" : "")); 90 p = HCIDisp1Ext("HOST_WAKE_Active_Mode", p, (*p == 0) ? "Active Low" : ((*p == 1) ? "Active High" : "")); 91 p = HCIDisp1("Allow_Host_Sleep_During_SCO", p); 92 p = HCIDisp1("Combine_Sleep_Mode_And_LPM", p); 93 p = HCIDisp1("Enable_Tristate_Control_Of_UART_Tx_Line", p); 94 p = HCIDisp1Ext("Active_Connection_Handling_On_Suspend", p, (*p == 0) ? "Maintain connections; sleep when timed activity allows" : ((*p == 1) ? "Sleep until resume is detected" : "")); 95 p = HCIDisp1("Resume_Timeout", p); 96 p = HCIDisp1("Enable_BREAK_To_Host", p); 97 p = HCIDisp1("Pulsed_HOST_WAKE", p); 98 99 ScrLog (HCI_GEN_TRACE, "--"); 100} 101 102 103/******************************************************************************* 104** 105** Function disp_sleepmode_evt 106** 107** Description Displays HCI comand complete event for VSC sleep mode. 108** 109** Returns none. 110** 111*******************************************************************************/ 112void disp_sleepmode_evt(UINT8* p) 113{ 114 UINT8 len=p[1], status=p[5]; 115 116 hci_trace_type = TRACE_TYPE_EVT_RX; 117 ScrLog (HCI_GEN_TRACE, "--"); 118 ScrLog (HCI_GEN_TRACE, "RCVD Event from HCI. Name: HCI_Command_Complete (Hex Code: 0x0e Param Len: %d)", len); 119 120 p = HCIDisp1 ("Num HCI Cmd Packets", p+2); 121 ScrLog (HCI_GEN_TRACE,"%40s : 0xfc27 (Set_Sleepmode_Param)", "Cmd Code"); 122 ScrLog (HCI_GEN_TRACE, "%40s : %d (0x%02x) %s", "Status", status, status, (status == 0) ? "Success" : ""); 123 ScrLog (HCI_GEN_TRACE, "--"); 124} 125 126/******************************************************************************* 127** 128** Function ProtoDispBluetoothHciCmd 129** 130** Description Display a HCI command string 131** 132** Returns: 133** Nothing 134** 135*******************************************************************************/ 136void ProtoDispBluetoothHciCmd (BT_HDR *p_buf) 137{ 138 if (!(ScrProtocolTraceFlag & SCR_PROTO_TRACE_HCI_SUMMARY)) 139 return; 140 UINT8 * p = (UINT8 *)(p_buf + 1) + p_buf->offset; 141 if (*(p) == 0x27 && *(p+1) == 0xfc) // opcode sleep mode 142 { 143 disp_sleepmode(p); 144 } 145} 146 147 148/******************************************************************************* 149** 150** Function ProtoDispBluetoothHciEvt 151** 152** Description display a NCI event 153** 154** Returns: 155** Nothing 156** 157*******************************************************************************/ 158void ProtoDispBluetoothHciEvt (BT_HDR *pBuffer) 159{ 160 if (!(ScrProtocolTraceFlag & SCR_PROTO_TRACE_HCI_SUMMARY)) 161 return; 162 163 UINT8 *p = (UINT8 *)(pBuffer + 1) + pBuffer->offset; 164 if (*p == 0x0e) // command complete 165 { 166 if (*(p+1) == 4) // length 167 { 168 if (*(p+3) == 0x27 && *(p+4) == 0xfc) // opcode 0x27fc (sleep mode) 169 { 170 disp_sleepmode_evt(p); 171 } 172 } 173 } 174} 175