• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ProtoDispBluetoothHci.h"
19 #include <cutils/log.h>
20 #include "_OverrideLog.h"
21 #include "nfc_target.h"
22 
23 extern uint8_t* HCIDisp1(char* p_descr, uint8_t* p_data);
24 extern uint32_t ScrProtocolTraceFlag;
25 #define HCI_GEN_TRACE \
26   (TRACE_CTRL_GENERAL | TRACE_LAYER_HCI | TRACE_ORG_PROTO_DISP | hci_trace_type)
27 static uint8_t hci_trace_type = 0;
28 static 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"};
41 static uint8_t* p_end_hci = NULL;
42 static uint8_t* HCIDisp1Ext(char* p_descr, uint8_t* p_data, char* p_ext);
43 static void disp_sleepmode(uint8_t* p);
44 static void disp_sleepmode_evt(uint8_t* p);
45 
46 ///////////////////////////////////////////
47 ///////////////////////////////////////////
48 
HCIDisp1Ext(char * p_descr,uint8_t * p_data,char * p_ext)49 uint8_t* HCIDisp1Ext(char* p_descr, uint8_t* p_data, char* p_ext) {
50   if (p_data == p_end_hci) return p_data;
51 
52   char buff[200];
53 
54   sprintf(buff, "%40s : %u (0x%02x): %s", p_descr, *p_data, *p_data, p_ext);
55 
56   ScrLog(HCI_GEN_TRACE, "%s", buff);
57   return (p_data + 1);
58 }
59 
60 /*******************************************************************************
61 **
62 ** Function         disp_sleepmode
63 **
64 ** Description      Displays VSC sleep mode
65 **
66 ** Returns          none.
67 **
68 *******************************************************************************/
disp_sleepmode(uint8_t * p)69 void 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);
96 
97   ScrLog(HCI_GEN_TRACE, "--");
98 }
99 
100 /*******************************************************************************
101 **
102 ** Function         disp_sleepmode_evt
103 **
104 ** Description      Displays HCI comand complete event for VSC sleep mode.
105 **
106 ** Returns          none.
107 **
108 *******************************************************************************/
disp_sleepmode_evt(uint8_t * p)109 void disp_sleepmode_evt(uint8_t* p) {
110   uint8_t len = p[1], status = p[5];
111 
112   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);
118 
119   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, "--");
124 }
125 
126 /*******************************************************************************
127 **
128 ** Function         ProtoDispBluetoothHciCmd
129 **
130 ** Description      Display a HCI command string
131 **
132 ** Returns:
133 **                  Nothing
134 **
135 *******************************************************************************/
ProtoDispBluetoothHciCmd(NFC_HDR * p_buf)136 void 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   }
143 }
144 
145 /*******************************************************************************
146 **
147 ** Function         ProtoDispBluetoothHciEvt
148 **
149 ** Description      display a NCI event
150 **
151 ** Returns:
152 **                  Nothing
153 **
154 *******************************************************************************/
ProtoDispBluetoothHciEvt(NFC_HDR * pBuffer)155 void ProtoDispBluetoothHciEvt(NFC_HDR* pBuffer) {
156   if (!(ScrProtocolTraceFlag & SCR_PROTO_TRACE_HCI_SUMMARY)) return;
157 
158   uint8_t* p = (uint8_t*)(pBuffer + 1) + pBuffer->offset;
159   if (*p == 0x0e)  // command complete
160   {
161     if (*(p + 1) == 4)  // length
162     {
163       if (*(p + 3) == 0x27 && *(p + 4) == 0xfc)  // opcode 0x27fc (sleep mode)
164       {
165         disp_sleepmode_evt(p);
166       }
167     }
168   }
169 }
170