blob: 6eb0d1373f2226f6cf4a16bb6ccfa5f538b8fc99 [file] [log] [blame]
Myles Watsonfc57a962019-08-22 16:11:01 -07001/*
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
28using bluetooth::packet::BitInserter;
29using bluetooth::packet::RawBuilder;
30using std::vector;
31
32namespace bluetooth {
33namespace hci {
34
35std::vector<uint8_t> reset = {0x03, 0x0c, 0x00};
36DEFINE_AND_INSTANTIATE_ResetReflectionTest(reset);
37
38std::vector<uint8_t> reset_complete = {0x0e, 0x04, 0x01, 0x03, 0x0c, 0x00};
39DEFINE_AND_INSTANTIATE_ResetCompleteReflectionTest(reset_complete);
40
41std::vector<uint8_t> read_buffer_size = {0x05, 0x10, 0x00};
42DEFINE_AND_INSTANTIATE_ReadBufferSizeReflectionTest(read_buffer_size);
43
44std::vector<uint8_t> read_buffer_size_complete = {0x0e, 0x0b, 0x01, 0x05, 0x10, 0x00, 0x00,
45 0x04, 0x3c, 0x07, 0x00, 0x08, 0x00};
46DEFINE_AND_INSTANTIATE_ReadBufferSizeCompleteReflectionTest(read_buffer_size_complete);
47
48std::vector<uint8_t> host_buffer_size = {0x33, 0x0c, 0x07, 0x9b, 0x06, 0xff, 0x14, 0x00, 0x0a, 0x00};
49DEFINE_AND_INSTANTIATE_HostBufferSizeReflectionTest(host_buffer_size);
50
51std::vector<uint8_t> host_buffer_size_complete = {0x0e, 0x04, 0x01, 0x33, 0x0c, 0x00};
52DEFINE_AND_INSTANTIATE_HostBufferSizeCompleteReflectionTest(host_buffer_size_complete);
53
54std::vector<uint8_t> read_local_version_information = {0x01, 0x10, 0x00};
55DEFINE_AND_INSTANTIATE_ReadLocalVersionInformationReflectionTest(read_local_version_information);
56
57std::vector<uint8_t> read_local_version_information_complete = {0x0e, 0x0c, 0x01, 0x01, 0x10, 0x00, 0x09,
58 0x00, 0x00, 0x09, 0x1d, 0x00, 0xbe, 0x02};
59DEFINE_AND_INSTANTIATE_ReadLocalVersionInformationCompleteReflectionTest(read_local_version_information_complete);
60
61std::vector<uint8_t> read_bd_addr = {0x09, 0x10, 0x00};
62DEFINE_AND_INSTANTIATE_ReadBdAddrReflectionTest(read_bd_addr);
63
64std::vector<uint8_t> read_bd_addr_complete = {0x0e, 0x0a, 0x01, 0x09, 0x10, 0x00, 0x14, 0x8e, 0x61, 0x5f, 0x36, 0x88};
65DEFINE_AND_INSTANTIATE_ReadBdAddrCompleteReflectionTest(read_bd_addr_complete);
66
67std::vector<uint8_t> read_local_supported_commands = {0x02, 0x10, 0x00};
68DEFINE_AND_INSTANTIATE_ReadLocalSupportedCommandsReflectionTest(read_local_supported_commands);
69
70std::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};
76DEFINE_AND_INSTANTIATE_ReadLocalSupportedCommandsCompleteReflectionTest(read_local_supported_commands_complete);
77
78std::vector<uint8_t> read_local_extended_features_0 = {0x04, 0x10, 0x01, 0x00};
79
80std::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
83std::vector<uint8_t> write_simple_paring_mode = {0x56, 0x0c, 0x01, 0x01};
84DEFINE_AND_INSTANTIATE_WriteSimplePairingModeReflectionTest(write_simple_paring_mode);
85
86std::vector<uint8_t> write_simple_paring_mode_complete = {0x0e, 0x04, 0x01, 0x56, 0x0c, 0x00};
87DEFINE_AND_INSTANTIATE_WriteSimplePairingModeCompleteReflectionTest(write_simple_paring_mode_complete);
88
89std::vector<uint8_t> write_le_host_supported = {0x6d, 0x0c, 0x02, 0x01, 0x01};
90DEFINE_AND_INSTANTIATE_WriteLeHostSupportReflectionTest(write_le_host_supported);
91
92std::vector<uint8_t> write_le_host_supported_complete = {0x0e, 0x04, 0x01, 0x6d, 0x0c, 0x00};
93DEFINE_AND_INSTANTIATE_WriteLeHostSupportCompleteReflectionTest(write_le_host_supported_complete);
94
95std::vector<uint8_t> read_local_extended_features_1 = {0x04, 0x10, 0x01, 0x01};
96
97std::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
100std::vector<uint8_t> read_local_extended_features_2 = {0x04, 0x10, 0x01, 0x02};
101DEFINE_AND_INSTANTIATE_ReadLocalExtendedFeaturesReflectionTest(read_local_extended_features_0,
102 read_local_extended_features_1,
103 read_local_extended_features_2);
104
105std::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};
107DEFINE_AND_INSTANTIATE_ReadLocalExtendedFeaturesCompleteReflectionTest(read_local_extended_features_complete_0,
108 read_local_extended_features_complete_1,
109 read_local_extended_features_complete_2);
110
111std::vector<uint8_t> write_secure_connections_host_support = {0x7a, 0x0c, 0x01, 0x01};
112DEFINE_AND_INSTANTIATE_WriteSecureConnectionsHostSupportReflectionTest(write_secure_connections_host_support);
113
114std::vector<uint8_t> write_secure_connections_host_support_complete = {0x0e, 0x04, 0x01, 0x7a, 0x0c, 0x00};
115DEFINE_AND_INSTANTIATE_WriteSecureConnectionsHostSupportCompleteReflectionTest(
116 write_secure_connections_host_support_complete);
117
118std::vector<uint8_t> le_read_white_list_size = {0x0f, 0x20, 0x00};
119DEFINE_AND_INSTANTIATE_LeReadWhiteListSizeReflectionTest(le_read_white_list_size);
120
121std::vector<uint8_t> le_read_white_list_size_complete = {0x0e, 0x05, 0x01, 0x0f, 0x20, 0x00, 0x80};
122DEFINE_AND_INSTANTIATE_LeReadWhiteListSizeCompleteReflectionTest(le_read_white_list_size_complete);
123
124std::vector<uint8_t> le_read_buffer_size = {0x02, 0x20, 0x00};
125DEFINE_AND_INSTANTIATE_LeReadBufferSizeReflectionTest(le_read_buffer_size);
126
127std::vector<uint8_t> le_read_buffer_size_complete = {0x0e, 0x07, 0x01, 0x02, 0x20, 0x00, 0xfb, 0x00, 0x10};
128DEFINE_AND_INSTANTIATE_LeReadBufferSizeCompleteReflectionTest(le_read_buffer_size_complete);
129
Chris Manton16d20012019-10-14 13:11:55 -0700130std::vector<uint8_t> write_current_iac_laps = {0x3a, 0x0c, 0x07, 0x02, 0x11, 0x8b, 0x9e, 0x22, 0x8b, 0x9e};
131DEFINE_AND_INSTANTIATE_WriteCurrentIacLapReflectionTest(write_current_iac_laps);
132
133std::vector<uint8_t> write_current_iac_laps_complete = {0x0e, 0x04, 0x01, 0x3a, 0x0c, 0x00};
134DEFINE_AND_INSTANTIATE_WriteCurrentIacLapCompleteReflectionTest(write_current_iac_laps_complete);
135
136std::vector<uint8_t> write_inquiry_scan_activity = {0x1e, 0x0c, 0x04, 0x00, 0x08, 0x12, 0x00};
137DEFINE_AND_INSTANTIATE_WriteInquiryScanActivityReflectionTest(write_inquiry_scan_activity);
138
139std::vector<uint8_t> write_inquiry_scan_activity_complete = {0x0e, 0x04, 0x01, 0x1e, 0x0c, 0x00};
140DEFINE_AND_INSTANTIATE_WriteInquiryScanActivityCompleteReflectionTest(write_inquiry_scan_activity_complete);
141
142std::vector<uint8_t> read_inquiry_scan_activity = {0x1d, 0x0c, 0x00};
143DEFINE_AND_INSTANTIATE_ReadInquiryScanActivityReflectionTest(read_inquiry_scan_activity);
144
145std::vector<uint8_t> read_inquiry_scan_activity_complete = {0x0e, 0x08, 0x01, 0x1d, 0x0c, 0x00, 0xaa, 0xbb, 0xcc, 0xdd};
146DEFINE_AND_INSTANTIATE_ReadInquiryScanActivityCompleteReflectionTest(read_inquiry_scan_activity_complete);
147
148std::vector<uint8_t> read_current_iac_lap = {0x39, 0x0c, 0x00};
149DEFINE_AND_INSTANTIATE_ReadCurrentIacLapReflectionTest(read_current_iac_lap);
150
151std::vector<uint8_t> read_current_iac_lap_complete = {0x0e, 0x0b, 0x01, 0x39, 0x0c, 0x00, 0x02,
152 0x11, 0x8b, 0x9e, 0x22, 0x8b, 0x9e};
153DEFINE_AND_INSTANTIATE_ReadCurrentIacLapCompleteReflectionTest(read_current_iac_lap_complete);
154
155std::vector<uint8_t> read_number_of_supported_iac = {0x38, 0x0c, 0x00};
156DEFINE_AND_INSTANTIATE_ReadNumberOfSupportedIacReflectionTest(read_number_of_supported_iac);
157
158std::vector<uint8_t> read_number_of_supported_iac_complete = {0x0e, 0x05, 0x01, 0x38, 0x0c, 0x00, 0x99};
159DEFINE_AND_INSTANTIATE_ReadNumberOfSupportedIacCompleteReflectionTest(read_number_of_supported_iac_complete);
160
161std::vector<uint8_t> read_page_timeout = {0x17, 0x0c, 0x00};
162DEFINE_AND_INSTANTIATE_ReadPageTimeoutReflectionTest(read_page_timeout);
163
164std::vector<uint8_t> read_page_timeout_complete = {0x0e, 0x06, 0x01, 0x17, 0x0c, 0x00, 0x11, 0x22};
165DEFINE_AND_INSTANTIATE_ReadPageTimeoutCompleteReflectionTest(read_page_timeout_complete);
166
Chris Manton499fb1d2019-10-15 16:02:42 -0700167std::vector<uint8_t> write_page_timeout = {0x18, 0x0c, 0x02, 0x00, 0x20};
168DEFINE_AND_INSTANTIATE_WritePageTimeoutReflectionTest(write_page_timeout);
169
170std::vector<uint8_t> write_page_timeout_complete = {0x0e, 0x04, 0x01, 0x18, 0x0c, 0x00};
171DEFINE_AND_INSTANTIATE_WritePageTimeoutCompleteReflectionTest(write_page_timeout_complete);
172
Chris Manton16d20012019-10-14 13:11:55 -0700173std::vector<uint8_t> inquiry = {0x01, 0x04, 0x05, 0x33, 0x8b, 0x9e, 0xaa, 0xbb};
174DEFINE_AND_INSTANTIATE_InquiryReflectionTest(inquiry);
175
176std::vector<uint8_t> inquiry_status = {0x0f, 0x04, 0x00, 0x01, 0x01, 0x04};
177DEFINE_AND_INSTANTIATE_InquiryStatusReflectionTest(inquiry_status);
178
179std::vector<uint8_t> inquiry_cancel = {0x02, 0x04, 0x00};
180DEFINE_AND_INSTANTIATE_InquiryCancelReflectionTest(inquiry_cancel);
181
182std::vector<uint8_t> inquiry_cancel_complete = {0x0e, 0x04, 0x01, 0x02, 0x04, 0x00};
183DEFINE_AND_INSTANTIATE_InquiryCancelCompleteReflectionTest(inquiry_cancel_complete);
184
185std::vector<uint8_t> periodic_inquiry_mode = {0x03, 0x04, 0x09, 0x12, 0x34, 0x56, 0x78, 0x11, 0x8b, 0x9e, 0x9a, 0xbc};
186DEFINE_AND_INSTANTIATE_PeriodicInquiryModeReflectionTest(periodic_inquiry_mode);
187
188std::vector<uint8_t> periodic_inquiry_mode_complete = {0x0e, 0x04, 0x01, 0x03, 0x04, 0x00};
189DEFINE_AND_INSTANTIATE_PeriodicInquiryModeCompleteReflectionTest(periodic_inquiry_mode_complete);
190
191std::vector<uint8_t> exit_periodic_inquiry_mode = {0x04, 0x04, 0x00};
192DEFINE_AND_INSTANTIATE_ExitPeriodicInquiryModeReflectionTest(exit_periodic_inquiry_mode);
193
194std::vector<uint8_t> exit_periodic_inquiry_mode_complete = {0x0e, 0x04, 0x01, 0x04, 0x04, 0x00};
195DEFINE_AND_INSTANTIATE_ExitPeriodicInquiryModeCompleteReflectionTest(exit_periodic_inquiry_mode_complete);
196
Myles Watson7a0dc392019-07-09 15:24:54 -0700197std::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
212std::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
227std::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
231TEST(HciPacketsTest, testWriteExtendedInquiryResponse) {
Myles Watsonfb2fec72019-10-22 16:21:44 -0700232 std::shared_ptr<std::vector<uint8_t>> view_bytes =
Myles Watson7a0dc392019-07-09 15:24:54 -0700233 std::make_shared<std::vector<uint8_t>>(pixel_3_xl_write_extended_inquiry_response);
234
Myles Watsonfb2fec72019-10-22 16:21:44 -0700235 PacketView<kLittleEndian> packet_bytes_view(view_bytes);
Myles Watson7a0dc392019-07-09 15:24:54 -0700236 auto view = WriteExtendedInquiryResponseView::Create(CommandPacketView::Create(packet_bytes_view));
237 ASSERT_TRUE(view.IsValid());
238 auto gap_data = view.GetExtendedInquiryResponse();
Myles Watsonfb2fec72019-10-22 16:21:44 -0700239 ASSERT_GE(gap_data.size(), 4);
Myles Watson7a0dc392019-07-09 15:24:54 -0700240 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 Watsonfb2fec72019-10-22 16:21:44 -0700248
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 Watson7a0dc392019-07-09 15:24:54 -0700260}
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 Watson331743f2019-11-21 04:07:32 -0800265
266std::vector<uint8_t> le_set_scan_parameters{
267 0x0b, 0x20, 0x07, 0x01, 0x12, 0x00, 0x12, 0x00, 0x01, 0x00,
268};
269TEST(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
282DEFINE_AND_INSTANTIATE_LeSetScanParametersReflectionTest(le_set_scan_parameters);
283
284std::vector<uint8_t> le_set_scan_enable{
285 0x0c, 0x20, 0x02, 0x01, 0x00,
286};
287TEST(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
296DEFINE_AND_INSTANTIATE_LeSetScanEnableReflectionTest(le_set_scan_enable);
297
298std::vector<uint8_t> le_get_vendor_capabilities{
299 0x53,
300 0xfd,
301 0x00,
302};
303TEST(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
311DEFINE_AND_INSTANTIATE_LeGetVendorCapabilitiesReflectionTest(le_get_vendor_capabilities);
312
313std::vector<uint8_t> le_get_vendor_capabilities_complete{
314 0x0e, 0x0c, 0x01, 0x53, 0xfd, 0x00, 0x05, 0x01, 0x00, 0x04, 0x80, 0x01, 0x10, 0x01,
315};
316TEST(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
333DEFINE_AND_INSTANTIATE_LeGetVendorCapabilitiesCompleteReflectionTest(le_get_vendor_capabilities_complete);
334
335std::vector<uint8_t> le_set_extended_scan_parameters{
336 0x41, 0x20, 0x08, 0x01, 0x00, 0x01, 0x01, 0x12, 0x00, 0x12, 0x00,
337};
338
339TEST(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
353std::vector<uint8_t> le_set_extended_scan_parameters_6553{
354 0x41, 0x20, 0x08, 0x01, 0x00, 0x01, 0x01, 0x99, 0x19, 0x99, 0x19,
355};
356
357TEST(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
372DEFINE_AND_INSTANTIATE_LeSetExtendedScanParametersReflectionTest(le_set_extended_scan_parameters,
373 le_set_extended_scan_parameters_6553);
374
375std::vector<uint8_t> le_set_extended_scan_parameters_complete{
376 0x0e, 0x04, 0x01, 0x41, 0x20, 0x00,
377};
378DEFINE_AND_INSTANTIATE_LeSetExtendedScanParametersCompleteReflectionTest(le_set_extended_scan_parameters_complete);
379
380std::vector<uint8_t> le_set_extended_scan_enable{
381 0x42, 0x20, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
382};
383
384TEST(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
396std::vector<uint8_t> le_set_extended_scan_enable_disable{
397 0x42, 0x20, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
398};
399
400TEST(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
413DEFINE_AND_INSTANTIATE_LeSetExtendedScanEnableReflectionTest(le_set_extended_scan_enable,
414 le_set_extended_scan_enable_disable);
415
416std::vector<uint8_t> le_set_extended_scan_enable_complete{
417 0x0e, 0x04, 0x01, 0x42, 0x20, 0x00,
418};
419DEFINE_AND_INSTANTIATE_LeSetExtendedScanEnableCompleteReflectionTest(le_set_extended_scan_enable_complete);
420
Myles Watsonfc57a962019-08-22 16:11:01 -0700421} // namespace hci
422} // namespace bluetooth