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 #pragma once 16 17 #include "pw_bluetooth_sapphire/internal/host/common/byte_buffer.h" 18 #include "pw_bluetooth_sapphire/internal/host/l2cap/rx_engine.h" 19 20 namespace bt::l2cap::internal { 21 22 // Implements the receiver state and logic for an L2CAP channel operating in 23 // either Enhanced or LE Credit-Based Flow Control Mode. 24 class CreditBasedFlowControlRxEngine final : public RxEngine { 25 public: 26 // Callback to invoke on a failure condition. In actual operation the 27 // callback must disconnect the channel to remain compliant with the spec. 28 // See Core Spec Ver 5.4, Vol 3, Part A, Sec 3.4.3. 29 using FailureCallback = fit::callback<void()>; 30 31 explicit CreditBasedFlowControlRxEngine(FailureCallback failure_callback); 32 ~CreditBasedFlowControlRxEngine() override = default; 33 34 ByteBufferPtr ProcessPdu(PDU pdu) override; 35 36 private: 37 FailureCallback failure_callback_; 38 39 MutableByteBufferPtr next_sdu_ = nullptr; 40 size_t valid_bytes_ = 0; 41 42 // Call the failure callback and reset. 43 void OnFailure(); 44 45 BT_DISALLOW_COPY_AND_ASSIGN_ALLOW_MOVE(CreditBasedFlowControlRxEngine); 46 }; 47 48 } // namespace bt::l2cap::internal 49