1 /*
2 * Copyright (C) 2021 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 <fuzzer/FuzzedDataProvider.h>
18
19 #include <string>
20
21 #include "esco_parameters.h"
22 #include "interop.h"
23
24 using namespace std;
25 constexpr size_t kNumAddressOctets = 6;
26 constexpr size_t kMaxStringLength = 10;
27 constexpr interop_feature_t kInteropFeature[] = {
28 interop_feature_t::INTEROP_DISABLE_LE_SECURE_CONNECTIONS,
29 interop_feature_t::INTEROP_AUTO_RETRY_PAIRING,
30 interop_feature_t::INTEROP_DISABLE_ABSOLUTE_VOLUME,
31 interop_feature_t::INTEROP_DISABLE_AUTO_PAIRING,
32 interop_feature_t::INTEROP_KEYBOARD_REQUIRES_FIXED_PIN,
33 interop_feature_t::INTEROP_2MBPS_LINK_ONLY,
34 interop_feature_t::INTEROP_HID_PREF_CONN_SUP_TIMEOUT_3S,
35 interop_feature_t::INTEROP_GATTC_NO_SERVICE_CHANGED_IND,
36 interop_feature_t::INTEROP_DISABLE_AVDTP_RECONFIGURE,
37 interop_feature_t::INTEROP_DYNAMIC_ROLE_SWITCH,
38 interop_feature_t::INTEROP_DISABLE_ROLE_SWITCH,
39 interop_feature_t::INTEROP_HID_HOST_LIMIT_SNIFF_INTERVAL,
40 interop_feature_t::INTEROP_DISABLE_NAME_REQUEST,
41 interop_feature_t::INTEROP_AVRCP_1_4_ONLY,
42 interop_feature_t::INTEROP_DISABLE_SNIFF,
43 interop_feature_t::INTEROP_DISABLE_AVDTP_SUSPEND,
44 interop_feature_t::INTEROP_SLC_SKIP_BIND_COMMAND,
45 interop_feature_t::INTEROP_AVRCP_1_3_ONLY,
46 };
47 constexpr esco_codec_t kEscoCodec[] = {
48 esco_codec_t::SCO_CODEC_CVSD_D1, esco_codec_t::ESCO_CODEC_CVSD_S3,
49 esco_codec_t::ESCO_CODEC_CVSD_S4, esco_codec_t::ESCO_CODEC_MSBC_T1,
50 esco_codec_t::ESCO_CODEC_MSBC_T2,
51 };
52
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)53 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
54 FuzzedDataProvider mFuzzedDataProvider = FuzzedDataProvider(data, size);
55 RawAddress fuzzAddress;
56 string addressString;
57 for (size_t i = 0; i < kNumAddressOctets; ++i) {
58 addressString.append(
59 mFuzzedDataProvider.ConsumeBytesAsString(sizeof(uint8_t)));
60 if (i != kNumAddressOctets - 1) {
61 addressString.append(":");
62 }
63 }
64 RawAddress::FromString(addressString, fuzzAddress);
65 interop_feature_t interopFeature =
66 mFuzzedDataProvider.PickValueInArray(kInteropFeature);
67 interop_match_addr(interopFeature, &fuzzAddress);
68 interop_database_add(interopFeature, &fuzzAddress,
69 mFuzzedDataProvider.ConsumeIntegralInRange<int32_t>(
70 1, RawAddress::kLength - 1));
71 interop_database_clear();
72 interop_match_name(
73 interopFeature,
74 mFuzzedDataProvider.ConsumeRandomLengthString(kMaxStringLength).c_str());
75 esco_codec_t escoCodec = mFuzzedDataProvider.PickValueInArray(kEscoCodec);
76 esco_parameters_for_codec(escoCodec);
77 return 0;
78 }
79