2 * Copyright 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 #include "base/macros.h"
26 #include "hci_packet.h"
27 #include "l2cap_sdu.h"
29 namespace test_vendor_lib {
31 const int kSduHeaderLength = 4;
33 class L2capPacket : public HciPacket {
35 // Returns an assembled L2cap object if successful, nullptr if failure.
36 static std::shared_ptr<L2capPacket> assemble(
37 const std::vector<std::shared_ptr<L2capSdu> >& sdu_packet);
39 // Returns a fragmented vector of L2capSdu objects if successful
40 // Returns an empty vector of L2capSdu objects if unsuccessful
41 std::vector<std::shared_ptr<L2capSdu> > fragment(uint16_t maximum_sdu_size,
45 uint16_t get_l2cap_cid() const;
47 // HciPacket Functions
49 uint8_t& get_at_index(size_t index);
52 L2capPacket() = default;
54 // Entire L2CAP packet: length, CID, and payload in that order.
55 std::vector<uint8_t> l2cap_packet_;
57 DISALLOW_COPY_AND_ASSIGN(L2capPacket);
59 // Helper functions for fragmenting.
60 static void set_sdu_header_length(std::vector<uint8_t>& sdu, uint16_t length);
62 static void set_total_sdu_length(std::vector<uint8_t>& sdu,
63 uint16_t total_sdu_length);
65 static void set_sdu_cid(std::vector<uint8_t>& sdu, uint16_t cid);
67 static void set_sdu_control_bytes(std::vector<uint8_t>& sdu, uint8_t txseq,
70 bool check_l2cap_packet() const;
74 } // namespace test_vendor_lib