• 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 #pragma once
16 #include "pw_bluetooth_sapphire/internal/host/common/byte_buffer.h"
17 #include "pw_bluetooth_sapphire/internal/host/common/device_address.h"
18 #include "pw_bluetooth_sapphire/internal/host/hci-spec/protocol.h"
19 #include "pw_bluetooth_sapphire/internal/host/l2cap/channel.h"
20 #include "pw_bluetooth_sapphire/internal/host/l2cap/l2cap_defs.h"
21 #include "pw_bluetooth_sapphire/internal/host/l2cap/types.h"
22 #include "pw_bluetooth_sapphire/internal/host/transport/emboss_control_packets.h"
23 
24 namespace bt::testing {
25 
26 // This module contains functionality to create arbitrary HCI packets defining
27 // common behaviors with respect to expected devices and connections.
28 // This allows easily defining expected packets to be sent or received for
29 // given transactions such as connection establishment or discovery
30 
31 DynamicByteBuffer EmptyCommandPacket(hci_spec::OpCode opcode);
32 
33 DynamicByteBuffer CommandCompletePacket(hci_spec::OpCode opcode,
34                                         pw::bluetooth::emboss::StatusCode);
35 
36 DynamicByteBuffer AcceptConnectionRequestPacket(DeviceAddress address);
37 
38 DynamicByteBuffer RejectConnectionRequestPacket(
39     DeviceAddress address, pw::bluetooth::emboss::StatusCode reason);
40 
41 DynamicByteBuffer AuthenticationRequestedPacket(
42     hci_spec::ConnectionHandle conn);
43 
44 DynamicByteBuffer ConnectionRequestPacket(
45     DeviceAddress address,
46     hci_spec::LinkType link_type = hci_spec::LinkType::kACL);
47 DynamicByteBuffer CreateConnectionPacket(DeviceAddress address);
48 DynamicByteBuffer ConnectionCompletePacket(
49     DeviceAddress address,
50     hci_spec::ConnectionHandle conn,
51     pw::bluetooth::emboss::StatusCode status =
52         pw::bluetooth::emboss::StatusCode::SUCCESS);
53 
54 DynamicByteBuffer DisconnectPacket(
55     hci_spec::ConnectionHandle conn,
56     pw::bluetooth::emboss::StatusCode reason =
57         pw::bluetooth::emboss::StatusCode::REMOTE_USER_TERMINATED_CONNECTION);
58 DynamicByteBuffer DisconnectStatusResponsePacket();
59 DynamicByteBuffer DisconnectionCompletePacket(
60     hci_spec::ConnectionHandle conn,
61     pw::bluetooth::emboss::StatusCode reason =
62         pw::bluetooth::emboss::StatusCode::REMOTE_USER_TERMINATED_CONNECTION);
63 
64 DynamicByteBuffer EncryptionChangeEventPacket(
65     pw::bluetooth::emboss::StatusCode status_code,
66     hci_spec::ConnectionHandle conn,
67     hci_spec::EncryptionStatus encryption_enabled);
68 
69 DynamicByteBuffer EnhancedAcceptSynchronousConnectionRequestPacket(
70     DeviceAddress peer_address,
71     bt::StaticPacket<
72         pw::bluetooth::emboss::SynchronousConnectionParametersWriter> params);
73 
74 DynamicByteBuffer EnhancedSetupSynchronousConnectionPacket(
75     hci_spec::ConnectionHandle conn,
76     bt::StaticPacket<
77         pw::bluetooth::emboss::SynchronousConnectionParametersWriter> params);
78 
79 DynamicByteBuffer NumberOfCompletedPacketsPacket(
80     hci_spec::ConnectionHandle conn, uint16_t num_packets);
81 
82 DynamicByteBuffer CommandStatusPacket(
83     hci_spec::OpCode op_code, pw::bluetooth::emboss::StatusCode status_code);
84 
85 DynamicByteBuffer RemoteNameRequestPacket(DeviceAddress address);
86 DynamicByteBuffer RemoteNameRequestCompletePacket(
87     DeviceAddress address, const std::string& name = "Fuchsia��");
88 
89 DynamicByteBuffer ReadRemoteVersionInfoPacket(hci_spec::ConnectionHandle conn);
90 DynamicByteBuffer ReadRemoteVersionInfoCompletePacket(
91     hci_spec::ConnectionHandle conn);
92 
93 DynamicByteBuffer ReadRemoteSupportedFeaturesPacket(
94     hci_spec::ConnectionHandle conn);
95 DynamicByteBuffer ReadRemoteSupportedFeaturesCompletePacket(
96     hci_spec::ConnectionHandle conn, bool extended_features);
97 
98 DynamicByteBuffer RejectSynchronousConnectionRequest(
99     DeviceAddress address, pw::bluetooth::emboss::StatusCode status_code);
100 
101 DynamicByteBuffer RoleChangePacket(
102     DeviceAddress address,
103     pw::bluetooth::emboss::ConnectionRole role,
104     pw::bluetooth::emboss::StatusCode status =
105         pw::bluetooth::emboss::StatusCode::SUCCESS);
106 
107 DynamicByteBuffer SetConnectionEncryption(hci_spec::ConnectionHandle conn,
108                                           bool enable);
109 
110 DynamicByteBuffer SynchronousConnectionCompletePacket(
111     hci_spec::ConnectionHandle conn,
112     DeviceAddress address,
113     hci_spec::LinkType link_type,
114     pw::bluetooth::emboss::StatusCode status);
115 
116 DynamicByteBuffer LEReadRemoteFeaturesPacket(hci_spec::ConnectionHandle conn);
117 DynamicByteBuffer LEReadRemoteFeaturesCompletePacket(
118     hci_spec::ConnectionHandle conn, hci_spec::LESupportedFeatures le_features);
119 
120 DynamicByteBuffer LEStartEncryptionPacket(hci_spec::ConnectionHandle,
121                                           uint64_t random_number,
122                                           uint16_t encrypted_diversifier,
123                                           UInt128 ltk);
124 
125 // The ReadRemoteExtended*CompletePacket packets report a max page number of 3,
126 // even though there are only 2 pages, in order to test this behavior seen in
127 // real devices.
128 DynamicByteBuffer ReadRemoteExtended1Packet(hci_spec::ConnectionHandle conn);
129 DynamicByteBuffer ReadRemoteExtended1CompletePacket(
130     hci_spec::ConnectionHandle conn);
131 DynamicByteBuffer ReadRemoteExtended2Packet(hci_spec::ConnectionHandle conn);
132 DynamicByteBuffer ReadRemoteExtended2CompletePacket(
133     hci_spec::ConnectionHandle conn);
134 
135 DynamicByteBuffer WriteAutomaticFlushTimeoutPacket(
136     hci_spec::ConnectionHandle conn, uint16_t flush_timeout);
137 
138 DynamicByteBuffer WritePageTimeoutPacket(uint16_t page_timeout);
139 
140 DynamicByteBuffer ScoDataPacket(
141     hci_spec::ConnectionHandle conn,
142     hci_spec::SynchronousDataPacketStatusFlag flag,
143     const BufferView& payload,
144     std::optional<uint8_t> payload_length_override = std::nullopt);
145 
146 DynamicByteBuffer StartA2dpOffloadRequest(
147     const l2cap::A2dpOffloadManager::Configuration& config,
148     hci_spec::ConnectionHandle connection_handle,
149     l2cap::ChannelId l2cap_channel_id,
150     uint16_t l2cap_mtu_size);
151 
152 DynamicByteBuffer StopA2dpOffloadRequest();
153 
154 }  // namespace bt::testing
155