summaryrefslogtreecommitdiff
path: root/system/packet/tests/fuzzers/avrcp_packet_fuzzer.cc
blob: a63ac7049b0255d0d28bbd9e7e3cad0218f55280 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Adapted from avrcp_packet_test.cc
#include <stddef.h>
#include <stdint.h>
#include "avrcp_packet.h"
#include "avrcp_test_packets.h"
#include "packet_test_helper.h"

namespace bluetooth {

// A helper class that has public accessors to protected methods
class TestPacketBuilder : public PacketBuilder {
 public:
  static std::unique_ptr<TestPacketBuilder> MakeBuilder(
      std::vector<uint8_t> data) {
    std::unique_ptr<TestPacketBuilder> builder(new TestPacketBuilder(data));
    return builder;
  }

  // Make all the utility functions public
  using PacketBuilder::AddPayloadOctets1;
  using PacketBuilder::AddPayloadOctets2;
  using PacketBuilder::AddPayloadOctets3;
  using PacketBuilder::AddPayloadOctets4;
  using PacketBuilder::AddPayloadOctets6;
  using PacketBuilder::AddPayloadOctets8;
  using PacketBuilder::ReserveSpace;

  size_t size() const override { return data_.size(); };

  bool Serialize(const std::shared_ptr<Packet>& pkt) override {
    ReserveSpace(pkt, size());

    for (uint8_t byte : data_) {
      AddPayloadOctets1(pkt, byte);
    }

    return true;
  }

  explicit TestPacketBuilder(std::vector<uint8_t> data) : data_(data) {}

  std::vector<uint8_t> data_;
};

namespace avrcp {

using TestAvrcpPacket = TestPacketType<Packet>;

extern "C" int LLVMFuzzerTestOneInput(const char* data, size_t size) {
  std::vector<uint8_t> get_capabilities_request_payload;

  if (size >= 8) {
    get_capabilities_request.push_back(0);
    for (int x = 0; x < 6; x++) {
      get_capabilities_request_payload.push_back(data[x]);
    }

    auto cap_req_builder =
        TestPacketBuilder::MakeBuilder(get_capabilities_request_payload);

    auto builder = PacketBuilder::MakeBuilder(
        CType::STATUS, 0x09, 0x00, Opcode::VENDOR, std::move(cap_req_builder));

    auto test_packet = TestAvrcpPacket::Make();
  }

  return 0;
}

}  // namespace avrcp
}  // namespace bluetooth