1/*
2 * Copyright (c) 2023 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 "securec.h"
17#include <cstdint>
18#include <cstdlib>
19#include <memory>
20#include "v1_0/chip_controller_stub.h"
21#include "../../../chip/hdi_service/wifi.h"
22
23using namespace OHOS::HDI::Wlan::Chip::V1_0;
24using namespace std;
25
26namespace OHOS {
27namespace HDI {
28namespace Wlan {
29namespace Chip {
30namespace V1_0 {
31
32namespace {
33const int32_t REWIND_READ_DATA = 0;
34shared_ptr<ChipControllerStub> g_WifiChipController = nullptr;
35}
36
37static void WifiChipStubFuzzTest(const uint8_t *data, size_t size)
38{
39    uint32_t code;
40    if (size < sizeof(code)) {
41        return;
42    }
43    if (memcpy_s(&code, sizeof(code), data, sizeof(code)) != EOK) {
44        return;
45    }
46
47    MessageParcel datas;
48    datas.WriteInterfaceToken(IChipController::GetDescriptor());
49    datas.WriteBuffer(data, size);
50    datas.RewindRead(REWIND_READ_DATA);
51    MessageParcel reply;
52    MessageOption option;
53    if (g_WifiChipController == nullptr) {
54        sptr<Wifi> impl = new Wifi();
55        impl->Init();
56        g_WifiChipController = make_shared<ChipControllerStub>(impl);
57    }
58    g_WifiChipController->OnRemoteRequest(code, datas, reply, option);
59}
60} // namespace V1_1
61} // namespace Chip
62} // namespace Wlan
63} // namespace HDI
64} // namespace OHOS
65
66/* Fuzzer entry point */
67extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
68{
69    /* Run your code on data */
70    OHOS::HDI::Wlan::Chip::V1_0::WifiChipStubFuzzTest(data, size);
71    return 0;
72}
73