1 /*
2  * Copyright 2020 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 #pragma once
18 
19 #include "fuzz/helpers.h"
20 #include "hal/hci_hal.h"
21 #include "hci/hci_packets.h"
22 
23 namespace bluetooth {
24 namespace hal {
25 namespace fuzz {
26 
27 class FuzzHciHal : public HciHal {
28 public:
29   void registerIncomingPacketCallback(HciHalCallbacks* callbacks) override;
30   void unregisterIncomingPacketCallback() override;
31 
32   void sendHciCommand(HciPacket command) override;
sendAclData(HciPacket)33   void sendAclData(HciPacket /* packet */) override {}
sendScoData(HciPacket)34   void sendScoData(HciPacket /* packet */) override {}
sendIsoData(HciPacket)35   void sendIsoData(HciPacket /* packet */) override {}
36 
37   void injectArbitrary(FuzzedDataProvider& fdp);
38 
ToString()39   std::string ToString() const override { return "HciHalFuzz"; }
40 
41   static const ModuleFactory Factory;
42 
43 protected:
ListDependencies(ModuleList *)44   void ListDependencies(ModuleList* /* list */) const override {}
Start()45   void Start() override {}
Stop()46   void Stop() override {}
47 
48 private:
49   void injectAclData(std::vector<uint8_t> data);
50   void injectHciEvent(std::vector<uint8_t> data);
51   void injectScoData(std::vector<uint8_t> data);
52   void injectIsoData(std::vector<uint8_t> data);
53 
54   HciHalCallbacks* callbacks_;
55   hci::OpCode waiting_opcode_{};
56   bool waiting_for_complete_{};
57   bool waiting_for_status_{};
58 };
59 
60 }  // namespace fuzz
61 }  // namespace hal
62 }  // namespace bluetooth
63