1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "audio_hdi_common.h"
17 #include "audio_adm_common.h"
18
19 using namespace HMOS::Audio;
20
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)21 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
22 {
23 struct HdfIoService *service = nullptr;
24 struct HdfSBuf *writeBuf = nullptr;
25 struct HdfSBuf *writeReply = nullptr;
26
27 struct AudioCtlElemValue writeElemValue = {
28 .id.cardServiceName = "hdf_audio_codec_dev0",
29 .id.iface = AUDIODRV_CTL_ELEM_IFACE_GAIN,
30 .id.itemName = "Mic Left Gain",
31 .value[0] = 5,
32 };
33
34 service = HdfIoServiceBind(HDF_CONTROL_SERVICE.c_str());
35 if (service == nullptr || service->dispatcher == nullptr) {
36 return 0;
37 }
38
39 writeBuf = HdfSbufObtainDefaultSize();
40 if (writeBuf == nullptr) {
41 HdfIoServiceRecycle(service);
42 return 0;
43 }
44 int32_t ret = WriteEleValueToBuf(writeBuf, writeElemValue);
45 if (ret < 0) {
46 return 0;
47 }
48
49 service->dispatcher->Dispatch(&service->object, size, writeBuf, writeReply);
50 HdfSbufRecycle(writeBuf);
51 HdfIoServiceRecycle(service);
52 return 0;
53 }
54