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/scheduler.h" 27 #include "l2cap/l2cap_packets.h" 28 #include "l2cap/mtu.h" 29 #include "os/queue.h" 30 #include "packet/base_packet_builder.h" 31 #include "packet/packet_view.h" 32 33 namespace bluetooth { 34 namespace l2cap { 35 namespace internal { 36 37 class DataPipelineManager; 38 39 /** 40 * Handle receiving L2CAP PDUs from link queue and distribute them into into channel data controllers. 41 * Dequeue incoming packets from LinkQueueUpEnd, and enqueue it to ChannelQueueDownEnd. Note: If a channel 42 * cannot dequeue from ChannelQueueDownEnd so that the buffer for incoming packet is full, further incoming packets will 43 * be dropped. 44 * The Reassembler keeps the reference to ChannelImpl objects, because it needs to check channel mode and parameters. 45 * The Reassembler also keeps the reference to Scheduler, to get Segmenter and send signals (Tx, Rx seq) to it. 46 */ 47 class Receiver { 48 public: 49 using UpperEnqueue = packet::PacketView<packet::kLittleEndian>; 50 using UpperDequeue = packet::BasePacketBuilder; 51 using UpperQueueDownEnd = common::BidiQueueEnd<UpperEnqueue, UpperDequeue>; 52 using LowerEnqueue = UpperDequeue; 53 using LowerDequeue = UpperEnqueue; 54 using LowerQueueUpEnd = common::BidiQueueEnd<LowerEnqueue, LowerDequeue>; 55 56 Receiver(LowerQueueUpEnd* link_queue_up_end, os::Handler* handler, DataPipelineManager* data_pipeline_manager); 57 ~Receiver(); 58 59 private: 60 LowerQueueUpEnd* link_queue_up_end_; 61 os::Handler* handler_; 62 DataPipelineManager* data_pipeline_manager_; 63 64 void link_queue_dequeue_callback(); 65 }; 66 67 } // namespace internal 68 } // namespace l2cap 69 } // namespace bluetooth 70