1 /* 2 * Copyright 2019 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 #define PACKET_TESTING 18 #include "hci/hci_packets.h" 19 20 #include <gtest/gtest.h> 21 #include <forward_list> 22 #include <memory> 23 24 #include "os/log.h" 25 #include "packet/bit_inserter.h" 26 #include "packet/raw_builder.h" 27 28 using bluetooth::packet::BitInserter; 29 using bluetooth::packet::RawBuilder; 30 using std::vector; 31 32 namespace bluetooth { 33 namespace hci { 34 35 std::vector<uint8_t> reset = {0x03, 0x0c, 0x00}; 36 DEFINE_AND_INSTANTIATE_ResetReflectionTest(reset); 37 38 std::vector<uint8_t> reset_complete = {0x0e, 0x04, 0x01, 0x03, 0x0c, 0x00}; 39 DEFINE_AND_INSTANTIATE_ResetCompleteReflectionTest(reset_complete); 40 41 std::vector<uint8_t> read_buffer_size = {0x05, 0x10, 0x00}; 42 DEFINE_AND_INSTANTIATE_ReadBufferSizeReflectionTest(read_buffer_size); 43 44 std::vector<uint8_t> read_buffer_size_complete = {0x0e, 0x0b, 0x01, 0x05, 0x10, 0x00, 0x00, 45 0x04, 0x3c, 0x07, 0x00, 0x08, 0x00}; 46 DEFINE_AND_INSTANTIATE_ReadBufferSizeCompleteReflectionTest(read_buffer_size_complete); 47 48 std::vector<uint8_t> host_buffer_size = {0x33, 0x0c, 0x07, 0x9b, 0x06, 0xff, 0x14, 0x00, 0x0a, 0x00}; 49 DEFINE_AND_INSTANTIATE_HostBufferSizeReflectionTest(host_buffer_size); 50 51 std::vector<uint8_t> host_buffer_size_complete = {0x0e, 0x04, 0x01, 0x33, 0x0c, 0x00}; 52 DEFINE_AND_INSTANTIATE_HostBufferSizeCompleteReflectionTest(host_buffer_size_complete); 53 54 std::vector<uint8_t> read_local_version_information = {0x01, 0x10, 0x00}; 55 DEFINE_AND_INSTANTIATE_ReadLocalVersionInformationReflectionTest(read_local_version_information); 56 57 std::vector<uint8_t> read_local_version_information_complete = {0x0e, 0x0c, 0x01, 0x01, 0x10, 0x00, 0x09, 58 0x00, 0x00, 0x09, 0x1d, 0x00, 0xbe, 0x02}; 59 DEFINE_AND_INSTANTIATE_ReadLocalVersionInformationCompleteReflectionTest(read_local_version_information_complete); 60 61 std::vector<uint8_t> read_bd_addr = {0x09, 0x10, 0x00}; 62 DEFINE_AND_INSTANTIATE_ReadBdAddrReflectionTest(read_bd_addr); 63 64 std::vector<uint8_t> read_bd_addr_complete = {0x0e, 0x0a, 0x01, 0x09, 0x10, 0x00, 0x14, 0x8e, 0x61, 0x5f, 0x36, 0x88}; 65 DEFINE_AND_INSTANTIATE_ReadBdAddrCompleteReflectionTest(read_bd_addr_complete); 66 67 std::vector<uint8_t> read_local_supported_commands = {0x02, 0x10, 0x00}; 68 DEFINE_AND_INSTANTIATE_ReadLocalSupportedCommandsReflectionTest(read_local_supported_commands); 69 70 std::vector<uint8_t> read_local_supported_commands_complete = { 71 0x0e, 0x44, 0x01, 0x02, 0x10, 0x00, /* Supported commands start here (total 64 bytes) */ 72 0xff, 0xff, 0xff, 0x03, 0xce, 0xff, 0xef, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xf2, 0x0f, 0xe8, 0xfe, 73 0x3f, 0xf7, 0x83, 0xff, 0x1c, 0x00, 0x00, 0x00, 0x61, 0xff, 0xff, 0xff, 0x7f, 0xbe, 0x20, 0xf5, 74 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 75 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 76 DEFINE_AND_INSTANTIATE_ReadLocalSupportedCommandsCompleteReflectionTest(read_local_supported_commands_complete); 77 78 std::vector<uint8_t> read_local_extended_features_0 = {0x04, 0x10, 0x01, 0x00}; 79 80 std::vector<uint8_t> read_local_extended_features_complete_0 = {0x0e, 0x0e, 0x01, 0x04, 0x10, 0x00, 0x00, 0x02, 81 0xff, 0xfe, 0x8f, 0xfe, 0xd8, 0x3f, 0x5b, 0x87}; 82 83 std::vector<uint8_t> write_simple_paring_mode = {0x56, 0x0c, 0x01, 0x01}; 84 DEFINE_AND_INSTANTIATE_WriteSimplePairingModeReflectionTest(write_simple_paring_mode); 85 86 std::vector<uint8_t> write_simple_paring_mode_complete = {0x0e, 0x04, 0x01, 0x56, 0x0c, 0x00}; 87 DEFINE_AND_INSTANTIATE_WriteSimplePairingModeCompleteReflectionTest(write_simple_paring_mode_complete); 88 89 std::vector<uint8_t> write_le_host_supported = {0x6d, 0x0c, 0x02, 0x01, 0x01}; 90 DEFINE_AND_INSTANTIATE_WriteLeHostSupportReflectionTest(write_le_host_supported); 91 92 std::vector<uint8_t> write_le_host_supported_complete = {0x0e, 0x04, 0x01, 0x6d, 0x0c, 0x00}; 93 DEFINE_AND_INSTANTIATE_WriteLeHostSupportCompleteReflectionTest(write_le_host_supported_complete); 94 95 std::vector<uint8_t> read_local_extended_features_1 = {0x04, 0x10, 0x01, 0x01}; 96 97 std::vector<uint8_t> read_local_extended_features_complete_1 = {0x0e, 0x0e, 0x01, 0x04, 0x10, 0x00, 0x01, 0x02, 98 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 99 100 std::vector<uint8_t> read_local_extended_features_2 = {0x04, 0x10, 0x01, 0x02}; 101 DEFINE_AND_INSTANTIATE_ReadLocalExtendedFeaturesReflectionTest(read_local_extended_features_0, 102 read_local_extended_features_1, 103 read_local_extended_features_2); 104 105 std::vector<uint8_t> read_local_extended_features_complete_2 = {0x0e, 0x0e, 0x01, 0x04, 0x10, 0x00, 0x02, 0x02, 106 0x45, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 107 DEFINE_AND_INSTANTIATE_ReadLocalExtendedFeaturesCompleteReflectionTest(read_local_extended_features_complete_0, 108 read_local_extended_features_complete_1, 109 read_local_extended_features_complete_2); 110 111 std::vector<uint8_t> write_secure_connections_host_support = {0x7a, 0x0c, 0x01, 0x01}; 112 DEFINE_AND_INSTANTIATE_WriteSecureConnectionsHostSupportReflectionTest(write_secure_connections_host_support); 113 114 std::vector<uint8_t> write_secure_connections_host_support_complete = {0x0e, 0x04, 0x01, 0x7a, 0x0c, 0x00}; 115 DEFINE_AND_INSTANTIATE_WriteSecureConnectionsHostSupportCompleteReflectionTest( 116 write_secure_connections_host_support_complete); 117 118 std::vector<uint8_t> le_read_white_list_size = {0x0f, 0x20, 0x00}; 119 DEFINE_AND_INSTANTIATE_LeReadWhiteListSizeReflectionTest(le_read_white_list_size); 120 121 std::vector<uint8_t> le_read_white_list_size_complete = {0x0e, 0x05, 0x01, 0x0f, 0x20, 0x00, 0x80}; 122 DEFINE_AND_INSTANTIATE_LeReadWhiteListSizeCompleteReflectionTest(le_read_white_list_size_complete); 123 124 std::vector<uint8_t> le_read_buffer_size = {0x02, 0x20, 0x00}; 125 DEFINE_AND_INSTANTIATE_LeReadBufferSizeReflectionTest(le_read_buffer_size); 126 127 std::vector<uint8_t> le_read_buffer_size_complete = {0x0e, 0x07, 0x01, 0x02, 0x20, 0x00, 0xfb, 0x00, 0x10}; 128 DEFINE_AND_INSTANTIATE_LeReadBufferSizeCompleteReflectionTest(le_read_buffer_size_complete); 129 130 std::vector<uint8_t> write_current_iac_laps = {0x3a, 0x0c, 0x07, 0x02, 0x11, 0x8b, 0x9e, 0x22, 0x8b, 0x9e}; 131 DEFINE_AND_INSTANTIATE_WriteCurrentIacLapReflectionTest(write_current_iac_laps); 132 133 std::vector<uint8_t> write_current_iac_laps_complete = {0x0e, 0x04, 0x01, 0x3a, 0x0c, 0x00}; 134 DEFINE_AND_INSTANTIATE_WriteCurrentIacLapCompleteReflectionTest(write_current_iac_laps_complete); 135 136 std::vector<uint8_t> write_inquiry_scan_activity = {0x1e, 0x0c, 0x04, 0x00, 0x08, 0x12, 0x00}; 137 DEFINE_AND_INSTANTIATE_WriteInquiryScanActivityReflectionTest(write_inquiry_scan_activity); 138 139 std::vector<uint8_t> write_inquiry_scan_activity_complete = {0x0e, 0x04, 0x01, 0x1e, 0x0c, 0x00}; 140 DEFINE_AND_INSTANTIATE_WriteInquiryScanActivityCompleteReflectionTest(write_inquiry_scan_activity_complete); 141 142 std::vector<uint8_t> read_inquiry_scan_activity = {0x1d, 0x0c, 0x00}; 143 DEFINE_AND_INSTANTIATE_ReadInquiryScanActivityReflectionTest(read_inquiry_scan_activity); 144 145 std::vector<uint8_t> read_inquiry_scan_activity_complete = {0x0e, 0x08, 0x01, 0x1d, 0x0c, 0x00, 0xaa, 0xbb, 0xcc, 0xdd}; 146 DEFINE_AND_INSTANTIATE_ReadInquiryScanActivityCompleteReflectionTest(read_inquiry_scan_activity_complete); 147 148 std::vector<uint8_t> read_current_iac_lap = {0x39, 0x0c, 0x00}; 149 DEFINE_AND_INSTANTIATE_ReadCurrentIacLapReflectionTest(read_current_iac_lap); 150 151 std::vector<uint8_t> read_current_iac_lap_complete = {0x0e, 0x0b, 0x01, 0x39, 0x0c, 0x00, 0x02, 152 0x11, 0x8b, 0x9e, 0x22, 0x8b, 0x9e}; 153 DEFINE_AND_INSTANTIATE_ReadCurrentIacLapCompleteReflectionTest(read_current_iac_lap_complete); 154 155 std::vector<uint8_t> read_number_of_supported_iac = {0x38, 0x0c, 0x00}; 156 DEFINE_AND_INSTANTIATE_ReadNumberOfSupportedIacReflectionTest(read_number_of_supported_iac); 157 158 std::vector<uint8_t> read_number_of_supported_iac_complete = {0x0e, 0x05, 0x01, 0x38, 0x0c, 0x00, 0x99}; 159 DEFINE_AND_INSTANTIATE_ReadNumberOfSupportedIacCompleteReflectionTest(read_number_of_supported_iac_complete); 160 161 std::vector<uint8_t> read_page_timeout = {0x17, 0x0c, 0x00}; 162 DEFINE_AND_INSTANTIATE_ReadPageTimeoutReflectionTest(read_page_timeout); 163 164 std::vector<uint8_t> read_page_timeout_complete = {0x0e, 0x06, 0x01, 0x17, 0x0c, 0x00, 0x11, 0x22}; 165 DEFINE_AND_INSTANTIATE_ReadPageTimeoutCompleteReflectionTest(read_page_timeout_complete); 166 167 std::vector<uint8_t> write_page_timeout = {0x18, 0x0c, 0x02, 0x00, 0x20}; 168 DEFINE_AND_INSTANTIATE_WritePageTimeoutReflectionTest(write_page_timeout); 169 170 std::vector<uint8_t> write_page_timeout_complete = {0x0e, 0x04, 0x01, 0x18, 0x0c, 0x00}; 171 DEFINE_AND_INSTANTIATE_WritePageTimeoutCompleteReflectionTest(write_page_timeout_complete); 172 173 std::vector<uint8_t> inquiry = {0x01, 0x04, 0x05, 0x33, 0x8b, 0x9e, 0xaa, 0xbb}; 174 DEFINE_AND_INSTANTIATE_InquiryReflectionTest(inquiry); 175 176 std::vector<uint8_t> inquiry_status = {0x0f, 0x04, 0x00, 0x01, 0x01, 0x04}; 177 DEFINE_AND_INSTANTIATE_InquiryStatusReflectionTest(inquiry_status); 178 179 std::vector<uint8_t> inquiry_cancel = {0x02, 0x04, 0x00}; 180 DEFINE_AND_INSTANTIATE_InquiryCancelReflectionTest(inquiry_cancel); 181 182 std::vector<uint8_t> inquiry_cancel_complete = {0x0e, 0x04, 0x01, 0x02, 0x04, 0x00}; 183 DEFINE_AND_INSTANTIATE_InquiryCancelCompleteReflectionTest(inquiry_cancel_complete); 184 185 std::vector<uint8_t> periodic_inquiry_mode = {0x03, 0x04, 0x09, 0x12, 0x34, 0x56, 0x78, 0x11, 0x8b, 0x9e, 0x9a, 0xbc}; 186 DEFINE_AND_INSTANTIATE_PeriodicInquiryModeReflectionTest(periodic_inquiry_mode); 187 188 std::vector<uint8_t> periodic_inquiry_mode_complete = {0x0e, 0x04, 0x01, 0x03, 0x04, 0x00}; 189 DEFINE_AND_INSTANTIATE_PeriodicInquiryModeCompleteReflectionTest(periodic_inquiry_mode_complete); 190 191 std::vector<uint8_t> exit_periodic_inquiry_mode = {0x04, 0x04, 0x00}; 192 DEFINE_AND_INSTANTIATE_ExitPeriodicInquiryModeReflectionTest(exit_periodic_inquiry_mode); 193 194 std::vector<uint8_t> exit_periodic_inquiry_mode_complete = {0x0e, 0x04, 0x01, 0x04, 0x04, 0x00}; 195 DEFINE_AND_INSTANTIATE_ExitPeriodicInquiryModeCompleteReflectionTest(exit_periodic_inquiry_mode_complete); 196 197 std::vector<uint8_t> pixel_3_xl_write_extended_inquiry_response{ 198 0x52, 0x0c, 0xf1, 0x01, 0x0b, 0x09, 0x50, 0x69, 0x78, 0x65, 0x6c, 0x20, 0x33, 0x20, 0x58, 0x4c, 0x19, 0x03, 0x05, 199 0x11, 0x0a, 0x11, 0x0c, 0x11, 0x0e, 0x11, 0x12, 0x11, 0x15, 0x11, 0x16, 0x11, 0x1f, 0x11, 0x2d, 0x11, 0x2f, 0x11, 200 0x00, 0x12, 0x32, 0x11, 0x01, 0x05, 0x81, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 203 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 204 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 205 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 206 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 207 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 208 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 209 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 211 212 std::vector<uint8_t> pixel_3_xl_write_extended_inquiry_response_no_uuids{ 213 0x52, 0x0c, 0xf1, 0x01, 0x0b, 0x09, 0x50, 0x69, 0x78, 0x65, 0x6c, 0x20, 0x33, 0x20, 0x58, 0x4c, 0x01, 0x03, 0x01, 214 0x05, 0x81, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 215 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 216 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 217 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 220 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 222 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 224 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 225 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 226 227 std::vector<uint8_t> pixel_3_xl_write_extended_inquiry_response_no_uuids_just_eir{ 228 pixel_3_xl_write_extended_inquiry_response_no_uuids.begin() + 4, // skip command, size, and fec_required 229 pixel_3_xl_write_extended_inquiry_response_no_uuids.end()}; 230 231 TEST(HciPacketsTest, testWriteExtendedInquiryResponse) { 232 std::shared_ptr<std::vector<uint8_t>> view_bytes = 233 std::make_shared<std::vector<uint8_t>>(pixel_3_xl_write_extended_inquiry_response); 234 235 PacketView<kLittleEndian> packet_bytes_view(view_bytes); 236 auto view = WriteExtendedInquiryResponseView::Create(CommandPacketView::Create(packet_bytes_view)); 237 ASSERT_TRUE(view.IsValid()); 238 auto gap_data = view.GetExtendedInquiryResponse(); 239 ASSERT_GE(gap_data.size(), 4); 240 ASSERT_EQ(gap_data[0].data_type_, GapDataType::COMPLETE_LOCAL_NAME); 241 ASSERT_EQ(gap_data[0].data_.size(), 10); 242 ASSERT_EQ(gap_data[1].data_type_, GapDataType::COMPLETE_LIST_16_BIT_UUIDS); 243 ASSERT_EQ(gap_data[1].data_.size(), 24); 244 ASSERT_EQ(gap_data[2].data_type_, GapDataType::COMPLETE_LIST_32_BIT_UUIDS); 245 ASSERT_EQ(gap_data[2].data_.size(), 0); 246 ASSERT_EQ(gap_data[3].data_type_, GapDataType::COMPLETE_LIST_128_BIT_UUIDS); 247 ASSERT_EQ(gap_data[3].data_.size(), 128); 248 249 std::vector<GapData> no_padding{gap_data.begin(), gap_data.begin() + 4}; 250 auto builder = WriteExtendedInquiryResponseBuilder::Create(view.GetFecRequired(), no_padding); 251 252 std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>(); 253 BitInserter it(*packet_bytes); 254 builder->Serialize(it); 255 256 EXPECT_EQ(packet_bytes->size(), view_bytes->size()); 257 for (size_t i = 0; i < view_bytes->size(); i++) { 258 ASSERT_EQ(packet_bytes->at(i), view_bytes->at(i)); 259 } 260 } 261 262 // TODO: Revisit reflection tests for EIR 263 // DEFINE_AND_INSTANTIATE_WriteExtendedInquiryResponseReflectionTest(pixel_3_xl_write_extended_inquiry_response, 264 // pixel_3_xl_write_extended_inquiry_response_no_uuids); 265 266 std::vector<uint8_t> le_set_scan_parameters{ 267 0x0b, 0x20, 0x07, 0x01, 0x12, 0x00, 0x12, 0x00, 0x01, 0x00, 268 }; 269 TEST(HciPacketsTest, testLeSetScanParameters) { 270 PacketView<kLittleEndian> packet_bytes_view(std::make_shared<std::vector<uint8_t>>(le_set_scan_parameters)); 271 auto view = 272 LeSetScanParametersView::Create(LeScanningCommandView::Create(CommandPacketView::Create(packet_bytes_view))); 273 274 ASSERT(view.IsValid()); 275 ASSERT_EQ(LeScanType::ACTIVE, view.GetLeScanType()); 276 ASSERT_EQ(0x12, view.GetLeScanInterval()); 277 ASSERT_EQ(0x12, view.GetLeScanWindow()); 278 ASSERT_EQ(AddressType::RANDOM_DEVICE_ADDRESS, view.GetOwnAddressType()); 279 ASSERT_EQ(LeSetScanningFilterPolicy::ACCEPT_ALL, view.GetScanningFilterPolicy()); 280 } 281 282 DEFINE_AND_INSTANTIATE_LeSetScanParametersReflectionTest(le_set_scan_parameters); 283 284 std::vector<uint8_t> le_set_scan_enable{ 285 0x0c, 0x20, 0x02, 0x01, 0x00, 286 }; 287 TEST(HciPacketsTest, testLeSetScanEnable) { 288 PacketView<kLittleEndian> packet_bytes_view(std::make_shared<std::vector<uint8_t>>(le_set_scan_enable)); 289 auto view = LeSetScanEnableView::Create(LeScanningCommandView::Create(CommandPacketView::Create(packet_bytes_view))); 290 291 ASSERT(view.IsValid()); 292 ASSERT_EQ(Enable::ENABLED, view.GetLeScanEnable()); 293 ASSERT_EQ(Enable::DISABLED, view.GetFilterDuplicates()); 294 } 295 296 DEFINE_AND_INSTANTIATE_LeSetScanEnableReflectionTest(le_set_scan_enable); 297 298 std::vector<uint8_t> le_get_vendor_capabilities{ 299 0x53, 300 0xfd, 301 0x00, 302 }; 303 TEST(HciPacketsTest, testLeGetVendorCapabilities) { 304 PacketView<kLittleEndian> packet_bytes_view(std::make_shared<std::vector<uint8_t>>(le_get_vendor_capabilities)); 305 auto view = 306 LeGetVendorCapabilitiesView::Create(VendorCommandView::Create(CommandPacketView::Create(packet_bytes_view))); 307 308 ASSERT(view.IsValid()); 309 } 310 311 DEFINE_AND_INSTANTIATE_LeGetVendorCapabilitiesReflectionTest(le_get_vendor_capabilities); 312 313 std::vector<uint8_t> le_get_vendor_capabilities_complete{ 314 0x0e, 0x0c, 0x01, 0x53, 0xfd, 0x00, 0x05, 0x01, 0x00, 0x04, 0x80, 0x01, 0x10, 0x01, 315 }; 316 TEST(HciPacketsTest, testLeGetVendorCapabilitiesComplete) { 317 PacketView<kLittleEndian> packet_bytes_view( 318 std::make_shared<std::vector<uint8_t>>(le_get_vendor_capabilities_complete)); 319 auto view = LeGetVendorCapabilitiesCompleteView::Create( 320 CommandCompleteView::Create(EventPacketView::Create(packet_bytes_view))); 321 322 ASSERT(view.IsValid()); 323 auto base_capabilities = view.GetBaseVendorCapabilities(); 324 ASSERT_EQ(5, base_capabilities.max_advt_instances_); 325 ASSERT_EQ(1, base_capabilities.offloaded_resolution_of_private_address_); 326 ASSERT_EQ(1024, base_capabilities.total_scan_results_storage_); 327 ASSERT_EQ(128, base_capabilities.max_irk_list_sz_); 328 ASSERT_EQ(1, base_capabilities.filtering_support_); 329 ASSERT_EQ(16, base_capabilities.max_filter_); 330 ASSERT_EQ(1, base_capabilities.activity_energy_info_support_); 331 } 332 333 DEFINE_AND_INSTANTIATE_LeGetVendorCapabilitiesCompleteReflectionTest(le_get_vendor_capabilities_complete); 334 335 std::vector<uint8_t> le_set_extended_scan_parameters{ 336 0x41, 0x20, 0x08, 0x01, 0x00, 0x01, 0x01, 0x12, 0x00, 0x12, 0x00, 337 }; 338 339 TEST(HciPacketsTest, testLeSetExtendedScanParameters) { 340 PacketView<kLittleEndian> packet_bytes_view(std::make_shared<std::vector<uint8_t>>(le_set_extended_scan_parameters)); 341 auto view = LeSetExtendedScanParametersView::Create( 342 LeScanningCommandView::Create(CommandPacketView::Create(packet_bytes_view))); 343 344 ASSERT(view.IsValid()); 345 ASSERT_EQ(1, view.GetScanningPhys()); 346 auto params = view.GetParameters(); 347 ASSERT_EQ(1, params.size()); 348 ASSERT_EQ(LeScanType::ACTIVE, params[0].le_scan_type_); 349 ASSERT_EQ(18, params[0].le_scan_interval_); 350 ASSERT_EQ(18, params[0].le_scan_window_); 351 } 352 353 std::vector<uint8_t> le_set_extended_scan_parameters_6553{ 354 0x41, 0x20, 0x08, 0x01, 0x00, 0x01, 0x01, 0x99, 0x19, 0x99, 0x19, 355 }; 356 357 TEST(HciPacketsTest, testLeSetExtendedScanParameters_6553) { 358 PacketView<kLittleEndian> packet_bytes_view( 359 std::make_shared<std::vector<uint8_t>>(le_set_extended_scan_parameters_6553)); 360 auto view = LeSetExtendedScanParametersView::Create( 361 LeScanningCommandView::Create(CommandPacketView::Create(packet_bytes_view))); 362 363 ASSERT(view.IsValid()); 364 ASSERT_EQ(1, view.GetScanningPhys()); 365 auto params = view.GetParameters(); 366 ASSERT_EQ(1, params.size()); 367 ASSERT_EQ(LeScanType::ACTIVE, params[0].le_scan_type_); 368 ASSERT_EQ(6553, params[0].le_scan_interval_); 369 ASSERT_EQ(6553, params[0].le_scan_window_); 370 } 371 372 DEFINE_AND_INSTANTIATE_LeSetExtendedScanParametersReflectionTest(le_set_extended_scan_parameters, 373 le_set_extended_scan_parameters_6553); 374 375 std::vector<uint8_t> le_set_extended_scan_parameters_complete{ 376 0x0e, 0x04, 0x01, 0x41, 0x20, 0x00, 377 }; 378 DEFINE_AND_INSTANTIATE_LeSetExtendedScanParametersCompleteReflectionTest(le_set_extended_scan_parameters_complete); 379 380 std::vector<uint8_t> le_set_extended_scan_enable{ 381 0x42, 0x20, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 382 }; 383 384 TEST(HciPacketsTest, testLeSetExtendedScanEnable) { 385 PacketView<kLittleEndian> packet_bytes_view(std::make_shared<std::vector<uint8_t>>(le_set_extended_scan_enable)); 386 auto view = 387 LeSetExtendedScanEnableView::Create(LeScanningCommandView::Create(CommandPacketView::Create(packet_bytes_view))); 388 389 ASSERT(view.IsValid()); 390 ASSERT_EQ(FilterDuplicates::DISABLED, view.GetFilterDuplicates()); 391 ASSERT_EQ(Enable::ENABLED, view.GetEnable()); 392 ASSERT_EQ(0, view.GetDuration()); 393 ASSERT_EQ(0, view.GetPeriod()); 394 } 395 396 std::vector<uint8_t> le_set_extended_scan_enable_disable{ 397 0x42, 0x20, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 398 }; 399 400 TEST(HciPacketsTest, testLeSetExtendedScanEnableDisable) { 401 PacketView<kLittleEndian> packet_bytes_view( 402 std::make_shared<std::vector<uint8_t>>(le_set_extended_scan_enable_disable)); 403 auto view = 404 LeSetExtendedScanEnableView::Create(LeScanningCommandView::Create(CommandPacketView::Create(packet_bytes_view))); 405 406 ASSERT(view.IsValid()); 407 ASSERT_EQ(FilterDuplicates::ENABLED, view.GetFilterDuplicates()); 408 ASSERT_EQ(Enable::DISABLED, view.GetEnable()); 409 ASSERT_EQ(0, view.GetDuration()); 410 ASSERT_EQ(0, view.GetPeriod()); 411 } 412 413 DEFINE_AND_INSTANTIATE_LeSetExtendedScanEnableReflectionTest(le_set_extended_scan_enable, 414 le_set_extended_scan_enable_disable); 415 416 std::vector<uint8_t> le_set_extended_scan_enable_complete{ 417 0x0e, 0x04, 0x01, 0x42, 0x20, 0x00, 418 }; 419 DEFINE_AND_INSTANTIATE_LeSetExtendedScanEnableCompleteReflectionTest(le_set_extended_scan_enable_complete); 420 421 std::vector<uint8_t> le_extended_create_connection = { 422 0x43, 0x20, 0x2a, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x08, 423 0x30, 0x00, 0x18, 0x00, 0x28, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 424 0x08, 0x30, 0x00, 0x18, 0x00, 0x28, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x00, 0x00}; 425 DEFINE_AND_INSTANTIATE_LeExtendedCreateConnectionReflectionTest(le_extended_create_connection); 426 427 TEST(HciPacketsTest, testLeExtendedCreateConnection) { 428 std::shared_ptr<std::vector<uint8_t>> packet_bytes = 429 std::make_shared<std::vector<uint8_t>>(le_extended_create_connection); 430 PacketView<kLittleEndian> packet_bytes_view(packet_bytes); 431 auto view = LeExtendedCreateConnectionView::Create( 432 LeConnectionManagementCommandView::Create(CommandPacketView::Create(packet_bytes_view))); 433 ASSERT_TRUE(view.IsValid()); 434 } 435 436 std::vector<uint8_t> le_set_extended_advertising_random_address = { 437 0x35, 0x20, 0x07, 0x00, 0x77, 0x58, 0xeb, 0xd3, 0x1c, 0x6e, 438 }; 439 440 TEST(HciPacketsTest, testLeSetExtendedAdvertisingRandomAddress) { 441 std::shared_ptr<std::vector<uint8_t>> packet_bytes = 442 std::make_shared<std::vector<uint8_t>>(le_set_extended_advertising_random_address); 443 PacketView<kLittleEndian> packet_bytes_view(packet_bytes); 444 auto view = LeSetExtendedAdvertisingRandomAddressView::Create( 445 LeAdvertisingCommandView::Create(CommandPacketView::Create(packet_bytes_view))); 446 ASSERT_TRUE(view.IsValid()); 447 uint8_t random_address_bytes[] = {0x77, 0x58, 0xeb, 0xd3, 0x1c, 0x6e}; 448 ASSERT_EQ(0, view.GetAdvertisingHandle()); 449 ASSERT_EQ(Address(random_address_bytes), view.GetAdvertisingRandomAddress()); 450 } 451 DEFINE_AND_INSTANTIATE_LeSetExtendedAdvertisingRandomAddressReflectionTest(le_set_extended_advertising_random_address); 452 453 std::vector<uint8_t> le_set_extended_advertising_random_address_complete{ 454 0x0e, 0x04, 0x01, 0x35, 0x20, 0x00, 455 }; 456 DEFINE_AND_INSTANTIATE_LeSetExtendedAdvertisingRandomAddressCompleteReflectionTest( 457 le_set_extended_advertising_random_address_complete); 458 459 std::vector<uint8_t> le_set_extended_advertising_data{ 460 0x37, 0x20, 0x12, 0x00, 0x03, 0x01, 0x0e, 0x02, 0x01, 0x02, 0x0a, 461 0x09, 0x50, 0x69, 0x78, 0x65, 0x6c, 0x20, 0x33, 0x20, 0x58, 462 }; 463 TEST(HciPacketsTest, testLeSetExtendedAdvertisingData) { 464 std::shared_ptr<std::vector<uint8_t>> packet_bytes = 465 std::make_shared<std::vector<uint8_t>>(le_set_extended_advertising_data); 466 PacketView<kLittleEndian> packet_bytes_view(packet_bytes); 467 auto view = LeSetExtendedAdvertisingDataRawView::Create( 468 LeAdvertisingCommandView::Create(CommandPacketView::Create(packet_bytes_view))); 469 ASSERT_TRUE(view.IsValid()); 470 ASSERT_EQ(0, view.GetAdvertisingHandle()); 471 ASSERT_EQ(Operation::COMPLETE_ADVERTISEMENT, view.GetOperation()); 472 ASSERT_EQ(FragmentPreference::CONTROLLER_SHOULD_NOT, view.GetFragmentPreference()); 473 std::vector<uint8_t> advertising_data{ 474 0x02, 0x01, 0x02, 0x0a, 0x09, 0x50, 0x69, 0x78, 0x65, 0x6c, 0x20, 0x33, 0x20, 0x58, 475 }; 476 ASSERT_EQ(advertising_data, view.GetAdvertisingData()); 477 } 478 479 DEFINE_AND_INSTANTIATE_LeSetExtendedAdvertisingDataRawReflectionTest(le_set_extended_advertising_data); 480 481 std::vector<uint8_t> le_set_extended_advertising_data_complete{ 482 0x0e, 0x04, 0x01, 0x37, 0x20, 0x00, 483 }; 484 DEFINE_AND_INSTANTIATE_LeSetExtendedAdvertisingDataCompleteReflectionTest(le_set_extended_advertising_data_complete); 485 486 std::vector<uint8_t> le_set_extended_advertising_parameters_set_0{ 487 0x36, 0x20, 0x19, 0x00, 0x13, 0x00, 0x90, 0x01, 0x00, 0xc2, 0x01, 0x00, 0x07, 0x01, 488 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf9, 0x01, 0x00, 0x01, 0x01, 0x00, 489 }; 490 TEST(HciPacketsTest, testLeSetExtendedAdvertisingParametersLegacySet0) { 491 std::shared_ptr<std::vector<uint8_t>> packet_bytes = 492 std::make_shared<std::vector<uint8_t>>(le_set_extended_advertising_parameters_set_0); 493 PacketView<kLittleEndian> packet_bytes_view(packet_bytes); 494 auto view = LeSetExtendedAdvertisingLegacyParametersView::Create( 495 LeAdvertisingCommandView::Create(CommandPacketView::Create(packet_bytes_view))); 496 ASSERT_TRUE(view.IsValid()); 497 ASSERT_EQ(0, view.GetAdvertisingHandle()); 498 ASSERT_EQ(400, view.GetPrimaryAdvertisingIntervalMin()); 499 ASSERT_EQ(450, view.GetPrimaryAdvertisingIntervalMax()); 500 ASSERT_EQ(0x7, view.GetPrimaryAdvertisingChannelMap()); 501 ASSERT_EQ(OwnAddressType::RANDOM_DEVICE_ADDRESS, view.GetOwnAddressType()); 502 ASSERT_EQ(PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, view.GetPeerAddressType()); 503 ASSERT_EQ(Address::kEmpty, view.GetPeerAddress()); 504 ASSERT_EQ(AdvertisingFilterPolicy::ALL_DEVICES, view.GetAdvertisingFilterPolicy()); 505 ASSERT_EQ(1, view.GetAdvertisingSid()); 506 ASSERT_EQ(Enable::DISABLED, view.GetScanRequestNotificationEnable()); 507 } 508 509 std::vector<uint8_t> le_set_extended_advertising_parameters_set_1{ 510 0x36, 0x20, 0x19, 0x01, 0x13, 0x00, 0x90, 0x01, 0x00, 0xc2, 0x01, 0x00, 0x07, 0x01, 511 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf9, 0x01, 0x00, 0x01, 0x01, 0x00, 512 }; 513 TEST(HciPacketsTest, testLeSetExtendedAdvertisingParametersSet1) { 514 std::shared_ptr<std::vector<uint8_t>> packet_bytes = 515 std::make_shared<std::vector<uint8_t>>(le_set_extended_advertising_parameters_set_1); 516 PacketView<kLittleEndian> packet_bytes_view(packet_bytes); 517 auto view = LeSetExtendedAdvertisingLegacyParametersView::Create( 518 LeAdvertisingCommandView::Create(CommandPacketView::Create(packet_bytes_view))); 519 ASSERT_TRUE(view.IsValid()); 520 ASSERT_EQ(1, view.GetAdvertisingHandle()); 521 ASSERT_EQ(400, view.GetPrimaryAdvertisingIntervalMin()); 522 ASSERT_EQ(450, view.GetPrimaryAdvertisingIntervalMax()); 523 ASSERT_EQ(0x7, view.GetPrimaryAdvertisingChannelMap()); 524 ASSERT_EQ(OwnAddressType::RANDOM_DEVICE_ADDRESS, view.GetOwnAddressType()); 525 ASSERT_EQ(PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, view.GetPeerAddressType()); 526 ASSERT_EQ(Address::kEmpty, view.GetPeerAddress()); 527 ASSERT_EQ(AdvertisingFilterPolicy::ALL_DEVICES, view.GetAdvertisingFilterPolicy()); 528 ASSERT_EQ(1, view.GetAdvertisingSid()); 529 ASSERT_EQ(Enable::DISABLED, view.GetScanRequestNotificationEnable()); 530 } 531 532 DEFINE_AND_INSTANTIATE_LeSetExtendedAdvertisingLegacyParametersReflectionTest( 533 le_set_extended_advertising_parameters_set_0, le_set_extended_advertising_parameters_set_1); 534 535 std::vector<uint8_t> le_set_extended_advertising_parameters_complete{0x0e, 0x05, 0x01, 0x36, 0x20, 0x00, 0xf5}; 536 TEST(HciPacketsTest, testLeSetExtendedAdvertisingParametersComplete) { 537 std::shared_ptr<std::vector<uint8_t>> packet_bytes = 538 std::make_shared<std::vector<uint8_t>>(le_set_extended_advertising_parameters_complete); 539 PacketView<kLittleEndian> packet_bytes_view(packet_bytes); 540 auto view = LeSetExtendedAdvertisingParametersCompleteView::Create( 541 CommandCompleteView::Create(EventPacketView::Create(packet_bytes_view))); 542 ASSERT_TRUE(view.IsValid()); 543 ASSERT_EQ(static_cast<uint8_t>(-11), view.GetSelectedTxPower()); 544 } 545 546 DEFINE_AND_INSTANTIATE_LeSetExtendedAdvertisingParametersCompleteReflectionTest( 547 le_set_extended_advertising_parameters_complete); 548 549 std::vector<uint8_t> le_remove_advertising_set_1{ 550 0x3c, 551 0x20, 552 0x01, 553 0x01, 554 }; 555 TEST(HciPacketsTest, testLeRemoveAdvertisingSet1) { 556 std::shared_ptr<std::vector<uint8_t>> packet_bytes = 557 std::make_shared<std::vector<uint8_t>>(le_remove_advertising_set_1); 558 PacketView<kLittleEndian> packet_bytes_view(packet_bytes); 559 auto view = LeRemoveAdvertisingSetView::Create( 560 LeAdvertisingCommandView::Create(CommandPacketView::Create(packet_bytes_view))); 561 ASSERT_TRUE(view.IsValid()); 562 ASSERT_EQ(1, view.GetAdvertisingHandle()); 563 } 564 565 DEFINE_AND_INSTANTIATE_LeRemoveAdvertisingSetReflectionTest(le_remove_advertising_set_1); 566 567 std::vector<uint8_t> le_remove_advertising_set_complete{ 568 0x0e, 0x04, 0x01, 0x3c, 0x20, 0x00, 569 }; 570 DEFINE_AND_INSTANTIATE_LeRemoveAdvertisingSetCompleteReflectionTest(le_remove_advertising_set_complete); 571 572 std::vector<uint8_t> le_set_extended_advertising_disable_1{ 573 0x39, 0x20, 0x06, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 574 }; 575 TEST(HciPacketsTest, testLeSetExtendedAdvertisingDisable1) { 576 std::shared_ptr<std::vector<uint8_t>> packet_bytes = 577 std::make_shared<std::vector<uint8_t>>(le_set_extended_advertising_disable_1); 578 PacketView<kLittleEndian> packet_bytes_view(packet_bytes); 579 auto view = LeSetExtendedAdvertisingDisableView::Create( 580 LeAdvertisingCommandView::Create(CommandPacketView::Create(packet_bytes_view))); 581 ASSERT_TRUE(view.IsValid()); 582 auto disabled_set = view.GetDisabledSets(); 583 ASSERT_EQ(1, disabled_set.size()); 584 ASSERT_EQ(1, disabled_set[0].advertising_handle_); 585 } 586 587 DEFINE_AND_INSTANTIATE_LeSetExtendedAdvertisingDisableReflectionTest(le_set_extended_advertising_disable_1); 588 589 std::vector<uint8_t> le_set_extended_advertising_enable_complete{ 590 0x0e, 0x04, 0x01, 0x39, 0x20, 0x00, 591 }; 592 DEFINE_AND_INSTANTIATE_LeSetExtendedAdvertisingEnableCompleteReflectionTest( 593 le_set_extended_advertising_enable_complete); 594 595 TEST(HciPacketsTest, testLeSetAdvertisingDataBuilderLength) { 596 GapData gap_data; 597 gap_data.data_type_ = GapDataType::COMPLETE_LOCAL_NAME; 598 gap_data.data_ = std::vector<uint8_t>({'A', ' ', 'g', 'o', 'o', 'd', ' ', 'n', 'a', 'm', 'e'}); 599 auto builder = LeSetAdvertisingDataBuilder::Create({gap_data}); 600 ASSERT_EQ(2 /*opcode*/ + 1 /* parameter size */ + 1 /* data_length */ + 31 /* data */, builder->size()); 601 602 auto packet_bytes = std::make_shared<std::vector<uint8_t>>(); 603 packet_bytes->reserve(builder->size()); 604 BitInserter bit_inserter(*packet_bytes); 605 builder->Serialize(bit_inserter); 606 auto command_view = LeAdvertisingCommandView::Create(CommandPacketView::Create(packet_bytes)); 607 ASSERT(command_view.IsValid()); 608 ASSERT_EQ(1 /* data_length */ + 31 /* data */, command_view.GetPayload().size()); 609 auto view = LeSetAdvertisingDataView::Create(command_view); 610 ASSERT(view.IsValid()); 611 } 612 613 TEST(HciPacketsTest, testLeSetScanResponseDataBuilderLength) { 614 GapData gap_data; 615 gap_data.data_type_ = GapDataType::COMPLETE_LOCAL_NAME; 616 gap_data.data_ = std::vector<uint8_t>({'A', ' ', 'g', 'o', 'o', 'd', ' ', 'n', 'a', 'm', 'e'}); 617 auto builder = LeSetScanResponseDataBuilder::Create({gap_data}); 618 ASSERT_EQ(2 /*opcode*/ + 1 /* parameter size */ + 1 /*data_length */ + 31 /* data */, builder->size()); 619 620 auto packet_bytes = std::make_shared<std::vector<uint8_t>>(); 621 packet_bytes->reserve(builder->size()); 622 BitInserter bit_inserter(*packet_bytes); 623 builder->Serialize(bit_inserter); 624 auto command_view = LeAdvertisingCommandView::Create(CommandPacketView::Create(packet_bytes)); 625 ASSERT(command_view.IsValid()); 626 ASSERT_EQ(1 /* data_length */ + 31 /* data */, command_view.GetPayload().size()); 627 auto view = LeSetScanResponseDataView::Create(command_view); 628 ASSERT(view.IsValid()); 629 } 630 631 TEST(HciPacketsTest, testLeMultiAdvSetAdvertisingDataBuilderLength) { 632 GapData gap_data; 633 gap_data.data_type_ = GapDataType::COMPLETE_LOCAL_NAME; 634 gap_data.data_ = std::vector<uint8_t>({'A', ' ', 'g', 'o', 'o', 'd', ' ', 'n', 'a', 'm', 'e'}); 635 uint8_t set = 3; 636 auto builder = LeMultiAdvtSetDataBuilder::Create({gap_data}, set); 637 ASSERT_EQ(2 /*opcode*/ + 1 /* parameter size */ + 1 /* data_length */ + 31 /* data */ + 1 /* set */, builder->size()); 638 639 auto packet_bytes = std::make_shared<std::vector<uint8_t>>(); 640 packet_bytes->reserve(builder->size()); 641 BitInserter bit_inserter(*packet_bytes); 642 builder->Serialize(bit_inserter); 643 auto command_view = 644 LeMultiAdvtView::Create(LeAdvertisingCommandView::Create(CommandPacketView::Create(packet_bytes))); 645 ASSERT(command_view.IsValid()); 646 EXPECT_EQ(1 /* data_length */ + 31 /* data */ + 1 /* set */, command_view.GetPayload().size()); 647 auto view = LeMultiAdvtSetDataView::Create(command_view); 648 ASSERT(view.IsValid()); 649 } 650 651 TEST(HciPacketsTest, testLeMultiAdvSetScanResponseDataBuilderLength) { 652 GapData gap_data; 653 gap_data.data_type_ = GapDataType::COMPLETE_LOCAL_NAME; 654 gap_data.data_ = std::vector<uint8_t>({'A', ' ', 'g', 'o', 'o', 'd', ' ', 'n', 'a', 'm', 'e'}); 655 uint8_t set = 3; 656 auto builder = LeMultiAdvtSetScanRespBuilder::Create({gap_data}, set); 657 EXPECT_EQ(2 /*opcode*/ + 1 /* parameter size */ + 1 /*data_length */ + 31 /* data */ + 1 /* set */, builder->size()); 658 659 auto packet_bytes = std::make_shared<std::vector<uint8_t>>(); 660 packet_bytes->reserve(builder->size()); 661 BitInserter bit_inserter(*packet_bytes); 662 builder->Serialize(bit_inserter); 663 auto command_view = 664 LeMultiAdvtView::Create(LeAdvertisingCommandView::Create(CommandPacketView::Create(packet_bytes))); 665 ASSERT(command_view.IsValid()); 666 ASSERT_EQ(1 /* data_length */ + 31 /* data */ + 1 /* set */, command_view.GetPayload().size()); 667 auto view = LeMultiAdvtSetScanRespView::Create(command_view); 668 ASSERT(view.IsValid()); 669 } 670 671 std::vector<uint8_t> controller_bqr = {0x5e, 0xfd, 0x07, 0x00, 0x1f, 0x00, 0x07, 0x00, 0x88, 0x13}; 672 DEFINE_AND_INSTANTIATE_ControllerBqrReflectionTest(controller_bqr); 673 674 std::vector<uint8_t> controller_bqr_complete = {0x0e, 0x08, 0x01, 0x5e, 0xfd, 0x00, 0x1f, 0x00, 0x07, 0x00}; 675 DEFINE_AND_INSTANTIATE_ControllerBqrCompleteReflectionTest(controller_bqr_complete); 676 677 std::vector<uint8_t> bqr_monitor_mode_event = { 678 0xff, 0x31, 0x58, 0x01, 0x10, 0x02, 0x00, 0x00, 0x07, 0xd5, 0x00, 0x14, 0x00, 0x40, 0x1f, 0xed, 0x41, 679 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x3c, 0x00, 680 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 681 DEFINE_AND_INSTANTIATE_BqrMonitorModeEventReflectionTest(bqr_monitor_mode_event); 682 683 std::vector<uint8_t> bqr_approach_lsto_event = { 684 0xff, 0x48, 0x58, 0x02, 0x10, 0x02, 0x00, 0x01, 0x09, 0xaf, 0x00, 0x2d, 0x00, 0x00, 0x7d, 0x94, 0xe9, 0x03, 0x01, 685 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x30, 0xa8, 0x0f, 0x00, 0x00, 0x00, 0x00, 686 0x00, 0x81, 0x9b, 0xf2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xcc, 0xcc, 0xcc, 0xcc, 0x00, 687 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x4e, 0x11, 0x00, 0x0c, 0x54, 0x10, 0x00}; 688 DEFINE_AND_INSTANTIATE_BqrApproachLstoEventReflectionTest(bqr_approach_lsto_event); 689 690 std::vector<uint8_t> bqr_a2dp_audio_choppy_event = { 691 0xff, 0x41, 0x58, 0x03, 0x19, 0x09, 0x00, 0x00, 0x07, 0xcb, 0x00, 0x3a, 0x01, 0x40, 0x1f, 0x7e, 0xce, 692 0x58, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x7e, 0xce, 0x58, 693 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0xd1, 0x57, 0x00, 0x30, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 694 0x0d, 0xce, 0x58, 0x00, 0x3a, 0xce, 0x58, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x01}; 695 DEFINE_AND_INSTANTIATE_BqrA2dpAudioChoppyEventReflectionTest(bqr_a2dp_audio_choppy_event); 696 697 std::vector<uint8_t> bqr_sco_voice_choppy_event = { 698 0xff, 0x4a, 0x58, 0x04, 0x09, 0x08, 0x00, 0x00, 0x08, 0xbf, 0x00, 0x03, 0x00, 0x40, 0x1f, 0x92, 0x6c, 0x0a, 0x0d, 699 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 700 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x02, 0x02, 0x0b, 701 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x00, 0x00}; 702 DEFINE_AND_INSTANTIATE_BqrScoVoiceChoppyEventReflectionTest(bqr_sco_voice_choppy_event); 703 704 std::vector<uint8_t> bqr_root_inflammation_event = {0xff, 0x04, 0x58, 0x05, 0x00, 0xfe}; 705 DEFINE_AND_INSTANTIATE_BqrRootInflammationEventReflectionTest(bqr_root_inflammation_event); 706 707 std::vector<uint8_t> bqr_lmp_ll_message_trace_event = {0xff, 0x11, 0x58, 0x11, 0x03, 0x00, 0x01, 0xff, 0x11, 0x55, 708 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55}; 709 DEFINE_AND_INSTANTIATE_BqrLmpLlMessageTraceEventReflectionTest(bqr_lmp_ll_message_trace_event); 710 711 std::vector<uint8_t> bqr_bt_scheduling_trace_event = {0xff, 0x1d, 0x58, 0x12, 0x05, 0x00, 0x02, 0xd9, 0xae, 0x08, 0x01, 712 0x05, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 713 0x00, 0x01, 0x0c, 0x00, 0x36, 0x3c, 0x00, 0x00, 0x00}; 714 DEFINE_AND_INSTANTIATE_BqrBtSchedulingTraceEventReflectionTest(bqr_bt_scheduling_trace_event); 715 716 } // namespace hci 717 } // namespace bluetooth 718