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 "bt_types.h" 21 22 namespace bluetooth { 23 24 /** 25 * Create L2CAP data packet 26 * 27 * @param lcid 28 * @param data 29 * @return vector of bytes 30 */ 31 std::vector<uint8_t> CreateL2capDataPacket(uint16_t lcid, 32 const std::vector<uint8_t>& data); 33 34 /** 35 * Create ACL data packet 36 * 37 * @param handle ACL connection hanle 38 * @param pb pb byte 39 * @param bc bc byte 40 * @param data frame data 41 * @return vector of bytes 42 */ 43 std::vector<uint8_t> CreateAclPacket(uint16_t handle, uint8_t pb, uint8_t bc, 44 const std::vector<uint8_t>& data); 45 46 /** 47 * Given an array of ACL packet bytes from BTSNOOP log, allocate an OSI 48 * allocated BT_HDR pointer to a packet that can be processed by L2CAP 49 * application layer 50 * 51 * Note: BT_HDR offset is configured for incoming packets 52 * 53 * @param acl_packet_bytes pointer to array of ACL packet bytes 54 * @param buffer_length length of the packet buffer 55 * @return BT_HDR pointer to an OSI heap allocated packet 56 */ 57 BT_HDR* AllocateWrappedIncomingL2capAclPacket(const uint8_t* acl_packet_bytes, 58 size_t buffer_length); 59 BT_HDR* AllocateWrappedIncomingL2capAclPacket( 60 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( 76 const std::vector<uint8_t>& buffer); 77 78 } // namespace bluetooth 79