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/hci-spec/protocol.h"
18 #include "pw_bluetooth_sapphire/internal/host/l2cap/frame_headers.h"
19 #include "pw_bluetooth_sapphire/internal/host/l2cap/l2cap_defs.h"
20 #include "pw_bluetooth_sapphire/internal/host/l2cap/types.h"
21
22 namespace bt::l2cap::testing {
23
24 // Signaling Packets
25
26 DynamicByteBuffer AclCommandRejectNotUnderstoodRsp(
27 l2cap::CommandId id,
28 hci_spec::ConnectionHandle handle,
29 ChannelId chan_id = kSignalingChannelId);
30 DynamicByteBuffer AclExtFeaturesInfoReq(l2cap::CommandId id,
31 hci_spec::ConnectionHandle handle);
32 DynamicByteBuffer AclExtFeaturesInfoRsp(l2cap::CommandId id,
33 hci_spec::ConnectionHandle handle,
34 l2cap::ExtendedFeatures features);
35 DynamicByteBuffer AclFixedChannelsSupportedInfoReq(
36 l2cap::CommandId id, hci_spec::ConnectionHandle handle);
37 DynamicByteBuffer AclFixedChannelsSupportedInfoRsp(
38 l2cap::CommandId id,
39 hci_spec::ConnectionHandle handle,
40 l2cap::FixedChannelsSupported chan_mask);
41 DynamicByteBuffer AclNotSupportedInformationResponse(
42 l2cap::CommandId id, hci_spec::ConnectionHandle handle);
43 DynamicByteBuffer AclConfigReq(l2cap::CommandId id,
44 hci_spec::ConnectionHandle handle,
45 l2cap::ChannelId dst_id,
46 l2cap::ChannelParameters params);
47 DynamicByteBuffer AclConfigRsp(l2cap::CommandId id,
48 hci_spec::ConnectionHandle link_handle,
49 l2cap::ChannelId src_id,
50 l2cap::ChannelParameters params);
51 DynamicByteBuffer AclConnectionReq(l2cap::CommandId id,
52 hci_spec::ConnectionHandle link_handle,
53 l2cap::ChannelId src_id,
54 l2cap::Psm psm);
55 DynamicByteBuffer AclConnectionRsp(
56 l2cap::CommandId id,
57 hci_spec::ConnectionHandle link_handle,
58 l2cap::ChannelId src_id,
59 l2cap::ChannelId dst_id,
60 ConnectionResult result = ConnectionResult::kSuccess);
61 DynamicByteBuffer AclDisconnectionReq(l2cap::CommandId id,
62 hci_spec::ConnectionHandle link_handle,
63 l2cap::ChannelId src_id,
64 l2cap::ChannelId dst_id);
65 DynamicByteBuffer AclDisconnectionRsp(l2cap::CommandId id,
66 hci_spec::ConnectionHandle link_handle,
67 l2cap::ChannelId src_id,
68 l2cap::ChannelId dst_id);
69 DynamicByteBuffer AclConnectionParameterUpdateReq(
70 l2cap::CommandId id,
71 hci_spec::ConnectionHandle link_handle,
72 uint16_t interval_min,
73 uint16_t interval_max,
74 uint16_t peripheral_latency,
75 uint16_t timeout_multiplier);
76 DynamicByteBuffer AclConnectionParameterUpdateRsp(
77 l2cap::CommandId id,
78 hci_spec::ConnectionHandle link_handle,
79 ConnectionParameterUpdateResult result);
80
81 DynamicByteBuffer AclLeCreditBasedConnectionReq(
82 l2cap::CommandId id,
83 hci_spec::ConnectionHandle link_handle,
84 l2cap::Psm psm,
85 l2cap::ChannelId cid,
86 uint16_t mtu,
87 uint16_t mps,
88 uint16_t credits);
89
90 DynamicByteBuffer AclLeCreditBasedConnectionRsp(
91 l2cap::CommandId id,
92 hci_spec::ConnectionHandle link_handle,
93 l2cap::ChannelId cid,
94 uint16_t mtu,
95 uint16_t mps,
96 uint16_t credits,
97 LECreditBasedConnectionResult result);
98
99 // S-Frame Packets
100
101 DynamicByteBuffer AclSFrame(hci_spec::ConnectionHandle link_handle,
102 l2cap::ChannelId channel_id,
103 internal::SupervisoryFunction function,
104 uint8_t receive_seq_num,
105 bool is_poll_request,
106 bool is_poll_response);
107
AclSFrameReceiverReady(hci_spec::ConnectionHandle link_handle,l2cap::ChannelId channel_id,uint8_t receive_seq_num,bool is_poll_request,bool is_poll_response)108 inline DynamicByteBuffer AclSFrameReceiverReady(
109 hci_spec::ConnectionHandle link_handle,
110 l2cap::ChannelId channel_id,
111 uint8_t receive_seq_num,
112 bool is_poll_request,
113 bool is_poll_response) {
114 return AclSFrame(link_handle,
115 channel_id,
116 internal::SupervisoryFunction::ReceiverReady,
117 receive_seq_num,
118 is_poll_request,
119 is_poll_response);
120 }
121
AclSFrameReceiverNotReady(hci_spec::ConnectionHandle link_handle,l2cap::ChannelId channel_id,uint8_t receive_seq_num,bool is_poll_request,bool is_poll_response)122 inline DynamicByteBuffer AclSFrameReceiverNotReady(
123 hci_spec::ConnectionHandle link_handle,
124 l2cap::ChannelId channel_id,
125 uint8_t receive_seq_num,
126 bool is_poll_request,
127 bool is_poll_response) {
128 return AclSFrame(link_handle,
129 channel_id,
130 internal::SupervisoryFunction::ReceiverNotReady,
131 receive_seq_num,
132 is_poll_request,
133 is_poll_response);
134 }
135
136 // I-Frame Packets
137
138 DynamicByteBuffer AclIFrame(hci_spec::ConnectionHandle link_handle,
139 l2cap::ChannelId channel_id,
140 uint8_t receive_seq_num,
141 uint8_t tx_seq,
142 bool is_poll_response,
143 const ByteBuffer& payload);
144
145 } // namespace bt::l2cap::testing
146