• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2024 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_proxy/internal/l2cap_aclu_signaling_channel.h"
16 
17 #include "pw_assert/check.h"
18 #include "pw_bluetooth/emboss_util.h"
19 #include "pw_bluetooth/l2cap_frames.emb.h"
20 #include "pw_log/log.h"
21 
22 namespace pw::bluetooth::proxy {
23 
L2capAclUSignalingChannel(L2capChannelManager & l2cap_channel_manager,uint16_t connection_handle)24 L2capAclUSignalingChannel::L2capAclUSignalingChannel(
25     L2capChannelManager& l2cap_channel_manager, uint16_t connection_handle)
26     : L2capSignalingChannel(
27           /*l2cap_channel_manager=*/l2cap_channel_manager,
28           /*connection_handle=*/connection_handle,
29           /*transport=*/AclTransportType::kBrEdr,
30           /*fixed_cid=*/
31           cpp23::to_underlying(emboss::L2capFixedCid::ACL_U_SIGNALING)) {}
32 
OnCFramePayload(Direction direction,pw::span<const uint8_t> cframe_payload)33 bool L2capAclUSignalingChannel::OnCFramePayload(
34     Direction direction, pw::span<const uint8_t> cframe_payload) {
35   bool all_consumed = false;
36 
37   do {
38     auto cmd = emboss::MakeL2capSignalingCommandView(cframe_payload.data(),
39                                                      cframe_payload.size());
40     if (!cmd.Ok()) {
41       PW_LOG_ERROR(
42           "Remaining buffer is too small for L2CAP command. So will forward "
43           "without processing.");
44 
45       // TODO: https://pwbug.dev/379172336 - Handle partially consumed ACL-U
46       // signaling command packets.
47       PW_CHECK(!all_consumed, "Consumed some commands.");
48       return false;
49     }
50     bool current_consumed = HandleL2capSignalingCommand(direction, cmd);
51 
52     // TODO: https://pwbug.dev/379172336 - Handle partially consumed ACL-U
53     // signaling command packets.
54     PW_CHECK(all_consumed == current_consumed,
55              "Wasn't able to consume all commands, but don't yet support "
56              "passing on some of them");
57     all_consumed |= current_consumed;
58     cframe_payload = cframe_payload.subspan(cmd.SizeInBytes());
59   } while (!cframe_payload.empty());
60 
61   return all_consumed;
62 }
63 
64 }  // namespace pw::bluetooth::proxy
65