1 /*
2  * Copyright 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <memory>
20 #include <unordered_map>
21 #include <utility>
22 
23 #include "common/bidi_queue.h"
24 #include "l2cap/cid.h"
25 #include "l2cap/internal/channel_impl.h"
26 #include "l2cap/internal/data_controller.h"
27 #include "l2cap/internal/scheduler.h"
28 #include "l2cap/l2cap_packets.h"
29 #include "l2cap/mtu.h"
30 #include "os/handler.h"
31 #include "os/queue.h"
32 #include "packet/base_packet_builder.h"
33 #include "packet/packet_view.h"
34 
35 namespace bluetooth {
36 namespace l2cap {
37 namespace internal {
38 
39 class BasicModeDataController : public DataController {
40  public:
41   using UpperEnqueue = packet::PacketView<packet::kLittleEndian>;
42   using UpperDequeue = packet::BasePacketBuilder;
43   using UpperQueueDownEnd = common::BidiQueueEnd<UpperEnqueue, UpperDequeue>;
44   BasicModeDataController(Cid cid, Cid remote_cid, UpperQueueDownEnd* channel_queue_end, os::Handler* handler,
45                           Scheduler* scheduler);
46 
47   ~BasicModeDataController() override;
48 
49   void OnSdu(std::unique_ptr<packet::BasePacketBuilder> sdu) override;
50 
51   void OnPdu(packet::PacketView<true> pdu) override;
52 
53   std::unique_ptr<packet::BasePacketBuilder> GetNextPacket() override;
54 
EnableFcs(bool enabled)55   void EnableFcs(bool enabled) override {}
SetRetransmissionAndFlowControlOptions(const RetransmissionAndFlowControlConfigurationOption & option)56   void SetRetransmissionAndFlowControlOptions(const RetransmissionAndFlowControlConfigurationOption& option) override {}
57 
58  private:
59   Cid cid_;
60   Cid remote_cid_;
61   os::EnqueueBuffer<UpperEnqueue> enqueue_buffer_;
62   os::Handler* handler_;
63   std::queue<std::unique_ptr<packet::BasePacketBuilder>> pdu_queue_;
64   Scheduler* scheduler_;
65 };
66 
67 }  // namespace internal
68 }  // namespace l2cap
69 }  // namespace bluetooth
70