1518678f8Sopenharmony_ci/*
2518678f8Sopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd.
3518678f8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4518678f8Sopenharmony_ci * you may not use this file except in compliance with the License.
5518678f8Sopenharmony_ci * You may obtain a copy of the License at
6518678f8Sopenharmony_ci *
7518678f8Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8518678f8Sopenharmony_ci *
9518678f8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10518678f8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11518678f8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12518678f8Sopenharmony_ci * See the License for the specific language governing permissions and
13518678f8Sopenharmony_ci * limitations under the License.
14518678f8Sopenharmony_ci */
15518678f8Sopenharmony_ci
16518678f8Sopenharmony_ci#include "dhcpclient_fuzzer.h"
17518678f8Sopenharmony_ci#include "dhcp_client.h"
18518678f8Sopenharmony_ci#include "dhcp_event.h"
19518678f8Sopenharmony_ci
20518678f8Sopenharmony_cinamespace OHOS {
21518678f8Sopenharmony_cinamespace DHCP {
22518678f8Sopenharmony_ci    std::shared_ptr<DhcpClient> dhcpClient = DhcpClient::GetInstance(DHCP_CLIENT_ABILITY_ID);
23518678f8Sopenharmony_ci    static OHOS::sptr<DhcpClientCallBack> dhcpClientCallBack =
24518678f8Sopenharmony_ci        OHOS::sptr<DhcpClientCallBack>(new (std::nothrow)DhcpClientCallBack());
25518678f8Sopenharmony_ci    static OHOS::sptr<DhcpServerCallBack> dhcpServerCallBack =
26518678f8Sopenharmony_ci        OHOS::sptr<DhcpServerCallBack>(new (std::nothrow)DhcpServerCallBack());
27518678f8Sopenharmony_ci    bool DhcpClientFuzzerTest(const uint8_t* data, size_t size)
28518678f8Sopenharmony_ci    {
29518678f8Sopenharmony_ci        if (dhcpClient == nullptr) {
30518678f8Sopenharmony_ci            return false;
31518678f8Sopenharmony_ci        }
32518678f8Sopenharmony_ci        std::string ifname = std::string(reinterpret_cast<const char*>(data), size);
33518678f8Sopenharmony_ci        RouterConfig routerConfig;
34518678f8Sopenharmony_ci        routerConfig.bssid = std::string(reinterpret_cast<const char*>(data), size);
35518678f8Sopenharmony_ci        dhcpClient->SetConfiguration(ifname, routerConfig);
36518678f8Sopenharmony_ci        dhcpClient->StartDhcpClient(ifname, true);
37518678f8Sopenharmony_ci        dhcpClient->StopDhcpClient(ifname, true);
38518678f8Sopenharmony_ci        dhcpClient->RegisterDhcpClientCallBack(ifname, dhcpClientCallBack);
39518678f8Sopenharmony_ci
40518678f8Sopenharmony_ci        return true;
41518678f8Sopenharmony_ci    }
42518678f8Sopenharmony_ci}  // namespace DHCP
43518678f8Sopenharmony_ci}  // namespace OHOS
44518678f8Sopenharmony_ci
45518678f8Sopenharmony_ci/* Fuzzer entry point */
46518678f8Sopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
47518678f8Sopenharmony_ci{
48518678f8Sopenharmony_ci    OHOS::DHCP::DhcpClientFuzzerTest(data, size);
49518678f8Sopenharmony_ci    return 0;
50518678f8Sopenharmony_ci}
51