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 #include "stack/include/bt_hdr.h" 22 23 namespace bluetooth { 24 25 /** 26 * Create L2CAP data packet 27 * 28 * @param lcid 29 * @param data 30 * @return vector of bytes 31 */ 32 std::vector<uint8_t> CreateL2capDataPacket(uint16_t lcid, 33 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( 61 const std::vector<uint8_t>& buffer); 62 63 /** 64 * Given an array of ACL packet bytes from BTSNOOP log, allocate an OSI 65 * allocated BT_HDR pointer to a packet that can be processed by L2CAP 66 * application layer 67 * 68 * Note: BT_HDR offset is configured for outgoing packets 69 * 70 * @param acl_packet_bytes pointer to array of ACL packet bytes 71 * @param buffer_length length of the packet buffer 72 * @return BT_HDR pointer to an OSI heap allocated packet 73 */ 74 BT_HDR* AllocateWrappedOutgoingL2capAclPacket(const uint8_t* acl_packet_bytes, 75 size_t buffer_length); 76 BT_HDR* AllocateWrappedOutgoingL2capAclPacket( 77 const std::vector<uint8_t>& buffer); 78 79 } // namespace bluetooth 80