1 /* 2 * Copyright 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include "btaa/activity_attribution.h" 20 #include "btaa/cmd_evt_classification.h" 21 #include "hal/snoop_logger.h" 22 #include "hci/address.h" 23 24 namespace bluetooth { 25 namespace activity_attribution { 26 27 struct BtaaHciPacket { 28 Activity activity; 29 hci::Address address; 30 uint16_t byte_count; 31 BtaaHciPacketBtaaHciPacket32 BtaaHciPacket() {} BtaaHciPacketBtaaHciPacket33 BtaaHciPacket(Activity activity, hci::Address address, uint16_t byte_count) 34 : activity(activity), address(address), byte_count(byte_count) {} 35 }; 36 37 class DeviceParser { 38 public: 39 void match_handle_with_address(uint16_t connection_handle, hci::Address& address); 40 41 private: 42 std::map<uint16_t, hci::Address> connection_lookup_table_; 43 }; 44 45 struct PendingCommand { 46 hci::OpCode opcode; 47 BtaaHciPacket btaa_hci_packet; 48 }; 49 50 class HciProcessor { 51 public: 52 std::vector<BtaaHciPacket> OnHciPacket(hal::HciPacket packet, hal::SnoopLogger::PacketType type, uint16_t length); 53 54 private: 55 void process_le_event(std::vector<BtaaHciPacket>& btaa_hci_packets, int16_t byte_count, hci::EventView& event); 56 void process_special_event( 57 std::vector<BtaaHciPacket>& btaa_hci_packets, 58 hci::EventCode event_code, 59 uint16_t byte_count, 60 hci::EventView& event); 61 void process_command( 62 std::vector<BtaaHciPacket>& btaa_hci_packets, 63 packet::PacketView<packet::kLittleEndian>& packet_view, 64 uint16_t byte_count); 65 void process_event( 66 std::vector<BtaaHciPacket>& btaa_hci_packets, 67 packet::PacketView<packet::kLittleEndian>& packet_view, 68 uint16_t byte_count); 69 void process_acl( 70 std::vector<BtaaHciPacket>& btaa_hci_packets, 71 packet::PacketView<packet::kLittleEndian>& packet_view, 72 uint16_t byte_count); 73 void process_sco( 74 std::vector<BtaaHciPacket>& btaa_hci_packets, 75 packet::PacketView<packet::kLittleEndian>& packet_view, 76 uint16_t byte_count); 77 void process_iso( 78 std::vector<BtaaHciPacket>& btaa_hci_packets, 79 packet::PacketView<packet::kLittleEndian>& packet_view, 80 uint16_t byte_count); 81 82 DeviceParser device_parser_; 83 PendingCommand pending_command_; 84 }; 85 86 } // namespace activity_attribution 87 } // namespace bluetooth 88