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