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 packet)33   void sendAclData(HciPacket packet) override {}
sendScoData(HciPacket packet)34   void sendScoData(HciPacket packet) override {}
sendIsoData(HciPacket packet)35   void sendIsoData(HciPacket packet) override {}
36 
37   void injectArbitrary(FuzzedDataProvider& fdp);
38 
ToString()39   std::string ToString() const override {
40     return "HciHalFuzz";
41   }
42 
43   static const ModuleFactory Factory;
44 
45  protected:
ListDependencies(ModuleList * list)46   void ListDependencies(ModuleList* list) override {}
Start()47   void Start() override {}
Stop()48   void Stop() override {}
49 
50  private:
51   void injectAclData(std::vector<uint8_t> data);
52   void injectHciEvent(std::vector<uint8_t> data);
53   void injectScoData(std::vector<uint8_t> data);
54   void injectIsoData(std::vector<uint8_t> data);
55 
56   HciHalCallbacks* callbacks_;
57   hci::OpCode waiting_opcode_;
58   bool waiting_for_status_;
59 };
60 
61 }  // namespace fuzz
62 }  // namespace hal
63 }  // namespace bluetooth
64