Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 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 | ******************************************************************************/ |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 18 | #include "ProtoDispBluetoothHci.h" |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 19 | #include <cutils/log.h> |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 20 | #include "_OverrideLog.h" |
| 21 | #include "nfc_target.h" |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 22 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 23 | extern uint8_t* HCIDisp1(char* p_descr, uint8_t* p_data); |
Ruchi Kandoi | 512ee63 | 2017-01-03 13:59:10 -0800 | [diff] [blame] | 24 | extern uint32_t ScrProtocolTraceFlag; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 25 | #define HCI_GEN_TRACE \ |
| 26 | (TRACE_CTRL_GENERAL | TRACE_LAYER_HCI | TRACE_ORG_PROTO_DISP | hci_trace_type) |
Ruchi Kandoi | 512ee63 | 2017-01-03 13:59:10 -0800 | [diff] [blame] | 27 | static uint8_t hci_trace_type = 0; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 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"}; |
Ruchi Kandoi | 512ee63 | 2017-01-03 13:59:10 -0800 | [diff] [blame] | 41 | static uint8_t* p_end_hci = NULL; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 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); |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 45 | |
| 46 | /////////////////////////////////////////// |
| 47 | /////////////////////////////////////////// |
| 48 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 49 | uint8_t* HCIDisp1Ext(char* p_descr, uint8_t* p_data, char* p_ext) { |
| 50 | if (p_data == p_end_hci) return p_data; |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 51 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 52 | char buff[200]; |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 53 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 54 | sprintf(buff, "%40s : %u (0x%02x): %s", p_descr, *p_data, *p_data, p_ext); |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 55 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 56 | ScrLog(HCI_GEN_TRACE, "%s", buff); |
| 57 | return (p_data + 1); |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 58 | } |
| 59 | |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 60 | /******************************************************************************* |
| 61 | ** |
| 62 | ** Function disp_sleepmode |
| 63 | ** |
| 64 | ** Description Displays VSC sleep mode |
| 65 | ** |
| 66 | ** Returns none. |
| 67 | ** |
| 68 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 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); |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 96 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 97 | ScrLog(HCI_GEN_TRACE, "--"); |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 98 | } |
| 99 | |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 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 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 109 | void disp_sleepmode_evt(uint8_t* p) { |
| 110 | uint8_t len = p[1], status = p[5]; |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 111 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 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); |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 118 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 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, "--"); |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /******************************************************************************* |
| 127 | ** |
| 128 | ** Function ProtoDispBluetoothHciCmd |
| 129 | ** |
| 130 | ** Description Display a HCI command string |
| 131 | ** |
| 132 | ** Returns: |
| 133 | ** Nothing |
| 134 | ** |
| 135 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 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 | } |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 143 | } |
| 144 | |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 145 | /******************************************************************************* |
| 146 | ** |
| 147 | ** Function ProtoDispBluetoothHciEvt |
| 148 | ** |
| 149 | ** Description display a NCI event |
| 150 | ** |
| 151 | ** Returns: |
| 152 | ** Nothing |
| 153 | ** |
| 154 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 155 | void ProtoDispBluetoothHciEvt(NFC_HDR* pBuffer) { |
| 156 | if (!(ScrProtocolTraceFlag & SCR_PROTO_TRACE_HCI_SUMMARY)) return; |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 157 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 158 | uint8_t* p = (uint8_t*)(pBuffer + 1) + pBuffer->offset; |
| 159 | if (*p == 0x0e) // command complete |
| 160 | { |
| 161 | if (*(p + 1) == 4) // length |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 162 | { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 163 | if (*(p + 3) == 0x27 && *(p + 4) == 0xfc) // opcode 0x27fc (sleep mode) |
| 164 | { |
| 165 | disp_sleepmode_evt(p); |
| 166 | } |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 167 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 168 | } |
Evan Chu | a24be4f | 2013-11-13 15:30:16 -0500 | [diff] [blame] | 169 | } |