1d95e75fdSopenharmony_ci/*
2d95e75fdSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3d95e75fdSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4d95e75fdSopenharmony_ci * you may not use this file except in compliance with the License.
5d95e75fdSopenharmony_ci * You may obtain a copy of the License at
6d95e75fdSopenharmony_ci *
7d95e75fdSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8d95e75fdSopenharmony_ci *
9d95e75fdSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10d95e75fdSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11d95e75fdSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12d95e75fdSopenharmony_ci * See the License for the specific language governing permissions and
13d95e75fdSopenharmony_ci * limitations under the License.
14d95e75fdSopenharmony_ci */
15d95e75fdSopenharmony_ci
16d95e75fdSopenharmony_ci#include "dialrequest_fuzzer.h"
17d95e75fdSopenharmony_ci
18d95e75fdSopenharmony_ci#include <cstddef>
19d95e75fdSopenharmony_ci#include <cstdint>
20d95e75fdSopenharmony_ci
21d95e75fdSopenharmony_ci#include "addcellularcalltoken_fuzzer.h"
22d95e75fdSopenharmony_ci#include "cellular_call_connection_cs.h"
23d95e75fdSopenharmony_ci#include "system_ability_definition.h"
24d95e75fdSopenharmony_ci
25d95e75fdSopenharmony_ciusing namespace OHOS::Telephony;
26d95e75fdSopenharmony_cinamespace OHOS {
27d95e75fdSopenharmony_ciconstexpr int32_t SLOT_NUM = 2;
28d95e75fdSopenharmony_ci
29d95e75fdSopenharmony_civoid DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size)
30d95e75fdSopenharmony_ci{
31d95e75fdSopenharmony_ci    if (data == nullptr || size == 0) {
32d95e75fdSopenharmony_ci        return;
33d95e75fdSopenharmony_ci    }
34d95e75fdSopenharmony_ci
35d95e75fdSopenharmony_ci    auto cellularCallConnectionCS = std::shared_ptr<CellularCallConnectionCS>();
36d95e75fdSopenharmony_ci    int32_t slotId = static_cast<int32_t>(size % SLOT_NUM);
37d95e75fdSopenharmony_ci    int32_t index = static_cast<int32_t>(size % SLOT_NUM);
38d95e75fdSopenharmony_ci    std::string phoneNum(reinterpret_cast<const char *>(data), size);
39d95e75fdSopenharmony_ci    DialRequestStruct dialRequest;
40d95e75fdSopenharmony_ci    dialRequest.phoneNum = phoneNum;
41d95e75fdSopenharmony_ci    cellularCallConnectionCS->HangUpRequest(slotId);
42d95e75fdSopenharmony_ci    cellularCallConnectionCS->AnswerRequest(slotId);
43d95e75fdSopenharmony_ci    cellularCallConnectionCS->RejectRequest(slotId);
44d95e75fdSopenharmony_ci    cellularCallConnectionCS->HoldRequest(slotId);
45d95e75fdSopenharmony_ci    cellularCallConnectionCS->UnHoldCallRequest(slotId);
46d95e75fdSopenharmony_ci    cellularCallConnectionCS->SwitchCallRequest(slotId);
47d95e75fdSopenharmony_ci    cellularCallConnectionCS->DialRequest(slotId, dialRequest);
48d95e75fdSopenharmony_ci    cellularCallConnectionCS->StopDtmfRequest(slotId, index);
49d95e75fdSopenharmony_ci    return;
50d95e75fdSopenharmony_ci}
51d95e75fdSopenharmony_ci} // namespace OHOS
52d95e75fdSopenharmony_ci
53d95e75fdSopenharmony_ci/* Fuzzer entry point */
54d95e75fdSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
55d95e75fdSopenharmony_ci{
56d95e75fdSopenharmony_ci    OHOS::AddCellularCallTokenFuzzer token;
57d95e75fdSopenharmony_ci    /* Run your code on data */
58d95e75fdSopenharmony_ci    OHOS::DoSomethingInterestingWithMyAPI(data, size);
59d95e75fdSopenharmony_ci    return 0;
60d95e75fdSopenharmony_ci}
61