• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 #include "pw_bluetooth_sapphire/internal/host/hci/util.h"
16 
17 #include <endian.h>
18 
19 #include "pw_unit_test/framework.h"
20 
21 namespace bt::hci {
22 namespace {
23 
TEST(UtilTest,DeviceAddressFromAdvReportParsesAddress)24 TEST(UtilTest, DeviceAddressFromAdvReportParsesAddress) {
25   StaticByteBuffer<sizeof(hci_spec::LEAdvertisingReportData)> buffer;
26   auto* report = reinterpret_cast<hci_spec::LEAdvertisingReportData*>(
27       buffer.mutable_data());
28   report->address = DeviceAddressBytes({0, 1, 2, 3, 4, 5});
29   report->address_type = hci_spec::LEAddressType::kPublicIdentity;
30 
31   DeviceAddress address;
32   bool resolved;
33 
34   EXPECT_TRUE(DeviceAddressFromAdvReport(*report, &address, &resolved));
35   EXPECT_EQ(DeviceAddress::Type::kLEPublic, address.type());
36   EXPECT_TRUE(resolved);
37 
38   report->address_type = hci_spec::LEAddressType::kPublic;
39   EXPECT_TRUE(DeviceAddressFromAdvReport(*report, &address, &resolved));
40   EXPECT_EQ(DeviceAddress::Type::kLEPublic, address.type());
41   EXPECT_FALSE(resolved);
42 
43   report->address_type = hci_spec::LEAddressType::kRandomIdentity;
44   EXPECT_TRUE(DeviceAddressFromAdvReport(*report, &address, &resolved));
45   EXPECT_EQ(DeviceAddress::Type::kLERandom, address.type());
46   EXPECT_TRUE(resolved);
47 
48   report->address_type = hci_spec::LEAddressType::kRandom;
49   EXPECT_TRUE(DeviceAddressFromAdvReport(*report, &address, &resolved));
50   EXPECT_EQ(DeviceAddress::Type::kLERandom, address.type());
51   EXPECT_FALSE(resolved);
52 }
53 
54 }  // namespace
55 }  // namespace bt::hci
56