1 /******************************************************************************
2  *
3  *  Copyright 2018 The Android Open Source Project
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 #pragma once
19 
20 #include <vector>
21 
22 #include "stack/include/bt_hdr.h"
23 
24 namespace bluetooth {
25 
26 /**
27  * Create L2CAP data packet
28  *
29  * @param lcid
30  * @param data
31  * @return vector of bytes
32  */
33 std::vector<uint8_t> CreateL2capDataPacket(uint16_t lcid, const std::vector<uint8_t>& data);
34 
35 /**
36  * Create ACL data packet
37  *
38  * @param handle ACL connection hanle
39  * @param pb pb byte
40  * @param bc bc byte
41  * @param data frame data
42  * @return vector of bytes
43  */
44 std::vector<uint8_t> CreateAclPacket(uint16_t handle, uint8_t pb, uint8_t bc,
45                                      const std::vector<uint8_t>& data);
46 
47 /**
48  * Given an array of ACL packet bytes from BTSNOOP log, allocate an OSI
49  * allocated BT_HDR pointer to a packet that can be processed by L2CAP
50  * application layer
51  *
52  * Note: BT_HDR offset is configured for incoming packets
53  *
54  * @param acl_packet_bytes pointer to array of ACL packet bytes
55  * @param buffer_length length of the packet buffer
56  * @return BT_HDR pointer to an OSI heap allocated packet
57  */
58 BT_HDR* AllocateWrappedIncomingL2capAclPacket(const uint8_t* acl_packet_bytes,
59                                               size_t buffer_length);
60 BT_HDR* AllocateWrappedIncomingL2capAclPacket(const std::vector<uint8_t>& buffer);
61 
62 /**
63  * Given an array of ACL packet bytes from BTSNOOP log, allocate an OSI
64  * allocated BT_HDR pointer to a packet that can be processed by L2CAP
65  * application layer
66  *
67  * Note: BT_HDR offset is configured for outgoing packets
68  *
69  * @param acl_packet_bytes pointer to array of ACL packet bytes
70  * @param buffer_length length of the packet buffer
71  * @return BT_HDR pointer to an OSI heap allocated packet
72  */
73 BT_HDR* AllocateWrappedOutgoingL2capAclPacket(const uint8_t* acl_packet_bytes,
74                                               size_t buffer_length);
75 BT_HDR* AllocateWrappedOutgoingL2capAclPacket(const std::vector<uint8_t>& buffer);
76 
77 }  // namespace bluetooth
78