1 /* 2 * Copyright 2023 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 #include "utils.h" 18 19 namespace bluetooth { 20 namespace shim { parse_gap_data(const std::vector<uint8_t> & raw_data,std::vector<hci::GapData> & output)21void parse_gap_data(const std::vector<uint8_t> &raw_data, 22 std::vector<hci::GapData> &output) { 23 size_t offset = 0; 24 while (offset < raw_data.size()) { 25 hci::GapData gap_data; 26 uint8_t len = raw_data[offset]; 27 28 if (offset + len + 1 > raw_data.size()) { 29 break; 30 } 31 32 auto begin = raw_data.begin() + offset; 33 auto end = begin + len + 1; // 1 byte for len 34 auto data_copy = std::make_shared<std::vector<uint8_t>>(begin, end); 35 bluetooth::packet::PacketView<bluetooth::packet::kLittleEndian> packet( 36 data_copy); 37 hci::GapData::Parse(&gap_data, packet.begin()); 38 output.push_back(gap_data); 39 offset += len + 1; // 1 byte for len 40 } 41 } 42 43 } // namespace shim 44 } // namespace bluetooth 45