Myles Watson | fc57a96 | 2019-08-22 16:11:01 -0700 | [diff] [blame] | 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 | |
Chris Manton | 16d2001 | 2019-10-14 13:11:55 -0700 | [diff] [blame] | 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 | |
Chris Manton | 499fb1d | 2019-10-15 16:02:42 -0700 | [diff] [blame] | 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 | |
Chris Manton | 16d2001 | 2019-10-14 13:11:55 -0700 | [diff] [blame] | 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 | |
Myles Watson | 7a0dc39 | 2019-07-09 15:24:54 -0700 | [diff] [blame] | 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) { |
Myles Watson | fb2fec7 | 2019-10-22 16:21:44 -0700 | [diff] [blame] | 232 | std::shared_ptr<std::vector<uint8_t>> view_bytes = |
Myles Watson | 7a0dc39 | 2019-07-09 15:24:54 -0700 | [diff] [blame] | 233 | std::make_shared<std::vector<uint8_t>>(pixel_3_xl_write_extended_inquiry_response); |
| 234 | |
Myles Watson | fb2fec7 | 2019-10-22 16:21:44 -0700 | [diff] [blame] | 235 | PacketView<kLittleEndian> packet_bytes_view(view_bytes); |
Myles Watson | 7a0dc39 | 2019-07-09 15:24:54 -0700 | [diff] [blame] | 236 | auto view = WriteExtendedInquiryResponseView::Create(CommandPacketView::Create(packet_bytes_view)); |
| 237 | ASSERT_TRUE(view.IsValid()); |
| 238 | auto gap_data = view.GetExtendedInquiryResponse(); |
Myles Watson | fb2fec7 | 2019-10-22 16:21:44 -0700 | [diff] [blame] | 239 | ASSERT_GE(gap_data.size(), 4); |
Myles Watson | 7a0dc39 | 2019-07-09 15:24:54 -0700 | [diff] [blame] | 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); |
Myles Watson | fb2fec7 | 2019-10-22 16:21:44 -0700 | [diff] [blame] | 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 | } |
Myles Watson | 7a0dc39 | 2019-07-09 15:24:54 -0700 | [diff] [blame] | 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); |
Myles Watson | 331743f | 2019-11-21 04:07:32 -0800 | [diff] [blame] | 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 | |
Myles Watson | fc57a96 | 2019-08-22 16:11:01 -0700 | [diff] [blame] | 421 | } // namespace hci |
| 422 | } // namespace bluetooth |