1e1c44949Sopenharmony_ci/* 2e1c44949Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3e1c44949Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e1c44949Sopenharmony_ci * you may not use this file except in compliance with the License. 5e1c44949Sopenharmony_ci * You may obtain a copy of the License at 6e1c44949Sopenharmony_ci * 7e1c44949Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e1c44949Sopenharmony_ci * 9e1c44949Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e1c44949Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e1c44949Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e1c44949Sopenharmony_ci * See the License for the specific language governing permissions and 13e1c44949Sopenharmony_ci * limitations under the License. 14e1c44949Sopenharmony_ci */ 15e1c44949Sopenharmony_ci 16e1c44949Sopenharmony_ci#include "setcalltransferinfo_fuzzer.h" 17e1c44949Sopenharmony_ci 18e1c44949Sopenharmony_ci#include <cstddef> 19e1c44949Sopenharmony_ci#include <cstdint> 20e1c44949Sopenharmony_ci#define private public 21e1c44949Sopenharmony_ci#include "addcalltoken_fuzzer.h" 22e1c44949Sopenharmony_ci#include "call_manager_service_stub.h" 23e1c44949Sopenharmony_ci 24e1c44949Sopenharmony_ciusing namespace OHOS::Telephony; 25e1c44949Sopenharmony_cinamespace OHOS { 26e1c44949Sopenharmony_ciconstexpr int32_t SLOT_NUM = 2; 27e1c44949Sopenharmony_ciconstexpr int32_t IMS_CONFIG_ITEM_NUM = 2; 28e1c44949Sopenharmony_ciconstexpr int32_t FEATURE_TYPE_NUM = 3; 29e1c44949Sopenharmony_ci 30e1c44949Sopenharmony_civoid IsImsSwitchEnabled(const uint8_t *data, size_t size) 31e1c44949Sopenharmony_ci{ 32e1c44949Sopenharmony_ci if (!IsServiceInited()) { 33e1c44949Sopenharmony_ci return; 34e1c44949Sopenharmony_ci } 35e1c44949Sopenharmony_ci 36e1c44949Sopenharmony_ci int32_t slotId = static_cast<int32_t>(size % SLOT_NUM); 37e1c44949Sopenharmony_ci MessageParcel dataMessageParcel; 38e1c44949Sopenharmony_ci dataMessageParcel.WriteInt32(slotId); 39e1c44949Sopenharmony_ci dataMessageParcel.WriteBuffer(data, size); 40e1c44949Sopenharmony_ci dataMessageParcel.RewindRead(0); 41e1c44949Sopenharmony_ci MessageParcel reply; 42e1c44949Sopenharmony_ci DelayedSingleton<CallManagerService>::GetInstance()->OnIsVoLteEnabled(dataMessageParcel, reply); 43e1c44949Sopenharmony_ci} 44e1c44949Sopenharmony_ci 45e1c44949Sopenharmony_civoid GetVoNRState(const uint8_t *data, size_t size) 46e1c44949Sopenharmony_ci{ 47e1c44949Sopenharmony_ci if (!IsServiceInited()) { 48e1c44949Sopenharmony_ci return; 49e1c44949Sopenharmony_ci } 50e1c44949Sopenharmony_ci 51e1c44949Sopenharmony_ci MessageParcel dataMessageParcel; 52e1c44949Sopenharmony_ci dataMessageParcel.WriteInt32(static_cast<int32_t>(size % SLOT_NUM)); 53e1c44949Sopenharmony_ci dataMessageParcel.WriteBuffer(data, size); 54e1c44949Sopenharmony_ci dataMessageParcel.RewindRead(0); 55e1c44949Sopenharmony_ci MessageParcel reply; 56e1c44949Sopenharmony_ci DelayedSingleton<CallManagerService>::GetInstance()->OnGetVoNRState(dataMessageParcel, reply); 57e1c44949Sopenharmony_ci} 58e1c44949Sopenharmony_ci 59e1c44949Sopenharmony_civoid GetImsConfig(const uint8_t *data, size_t size) 60e1c44949Sopenharmony_ci{ 61e1c44949Sopenharmony_ci if (!IsServiceInited()) { 62e1c44949Sopenharmony_ci return; 63e1c44949Sopenharmony_ci } 64e1c44949Sopenharmony_ci 65e1c44949Sopenharmony_ci int32_t slotId = static_cast<int32_t>(size % SLOT_NUM); 66e1c44949Sopenharmony_ci int32_t item = static_cast<int32_t>(size % IMS_CONFIG_ITEM_NUM); 67e1c44949Sopenharmony_ci MessageParcel dataMessageParcel; 68e1c44949Sopenharmony_ci dataMessageParcel.WriteInt32(slotId); 69e1c44949Sopenharmony_ci dataMessageParcel.WriteInt32(static_cast<ImsConfigItem>(item)); 70e1c44949Sopenharmony_ci dataMessageParcel.WriteBuffer(data, size); 71e1c44949Sopenharmony_ci dataMessageParcel.RewindRead(0); 72e1c44949Sopenharmony_ci MessageParcel reply; 73e1c44949Sopenharmony_ci DelayedSingleton<CallManagerService>::GetInstance()->OnGetImsConfig(dataMessageParcel, reply); 74e1c44949Sopenharmony_ci} 75e1c44949Sopenharmony_ci 76e1c44949Sopenharmony_civoid GetImsFeatureValue(const uint8_t *data, size_t size) 77e1c44949Sopenharmony_ci{ 78e1c44949Sopenharmony_ci if (!IsServiceInited()) { 79e1c44949Sopenharmony_ci return; 80e1c44949Sopenharmony_ci } 81e1c44949Sopenharmony_ci 82e1c44949Sopenharmony_ci int32_t slotId = static_cast<int32_t>(size % SLOT_NUM); 83e1c44949Sopenharmony_ci int32_t type = static_cast<int32_t>(size % FEATURE_TYPE_NUM); 84e1c44949Sopenharmony_ci MessageParcel dataMessageParcel; 85e1c44949Sopenharmony_ci dataMessageParcel.WriteInt32(slotId); 86e1c44949Sopenharmony_ci dataMessageParcel.WriteInt32(static_cast<FeatureType>(type)); 87e1c44949Sopenharmony_ci dataMessageParcel.WriteBuffer(data, size); 88e1c44949Sopenharmony_ci dataMessageParcel.RewindRead(0); 89e1c44949Sopenharmony_ci MessageParcel reply; 90e1c44949Sopenharmony_ci DelayedSingleton<CallManagerService>::GetInstance()->OnGetImsFeatureValue(dataMessageParcel, reply); 91e1c44949Sopenharmony_ci} 92e1c44949Sopenharmony_ci 93e1c44949Sopenharmony_civoid GetCallTransferInfo(const uint8_t *data, size_t size) 94e1c44949Sopenharmony_ci{ 95e1c44949Sopenharmony_ci if (!IsServiceInited()) { 96e1c44949Sopenharmony_ci return; 97e1c44949Sopenharmony_ci } 98e1c44949Sopenharmony_ci 99e1c44949Sopenharmony_ci int32_t slotId = static_cast<int32_t>(size % SLOT_NUM); 100e1c44949Sopenharmony_ci MessageParcel dataMessageParcel; 101e1c44949Sopenharmony_ci dataMessageParcel.WriteInt32(slotId); 102e1c44949Sopenharmony_ci dataMessageParcel.WriteInt32(static_cast<int32_t>(size)); 103e1c44949Sopenharmony_ci dataMessageParcel.WriteBuffer(data, size); 104e1c44949Sopenharmony_ci dataMessageParcel.RewindRead(0); 105e1c44949Sopenharmony_ci MessageParcel reply; 106e1c44949Sopenharmony_ci DelayedSingleton<CallManagerService>::GetInstance()->OnGetTransferNumber(dataMessageParcel, reply); 107e1c44949Sopenharmony_ci} 108e1c44949Sopenharmony_ci 109e1c44949Sopenharmony_civoid SetCallTransferInfo(const uint8_t *data, size_t size) 110e1c44949Sopenharmony_ci{ 111e1c44949Sopenharmony_ci if (!IsServiceInited()) { 112e1c44949Sopenharmony_ci return; 113e1c44949Sopenharmony_ci } 114e1c44949Sopenharmony_ci 115e1c44949Sopenharmony_ci int32_t slotId = static_cast<int32_t>(size % SLOT_NUM); 116e1c44949Sopenharmony_ci MessageParcel dataMessageParcel; 117e1c44949Sopenharmony_ci CallTransferInfo info; 118e1c44949Sopenharmony_ci (void)memcpy_s(info.transferNum, kMaxNumberLen, reinterpret_cast<const char *>(data), size); 119e1c44949Sopenharmony_ci info.settingType = CallTransferSettingType::CALL_TRANSFER_ENABLE; 120e1c44949Sopenharmony_ci info.type = CallTransferType::TRANSFER_TYPE_BUSY; 121e1c44949Sopenharmony_ci dataMessageParcel.WriteInt32(slotId); 122e1c44949Sopenharmony_ci dataMessageParcel.WriteRawData((const void *)&info, sizeof(CallTransferInfo)); 123e1c44949Sopenharmony_ci dataMessageParcel.RewindRead(0); 124e1c44949Sopenharmony_ci MessageParcel reply; 125e1c44949Sopenharmony_ci DelayedSingleton<CallManagerService>::GetInstance()->OnSetTransferNumber(dataMessageParcel, reply); 126e1c44949Sopenharmony_ci} 127e1c44949Sopenharmony_ci 128e1c44949Sopenharmony_civoid DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size) 129e1c44949Sopenharmony_ci{ 130e1c44949Sopenharmony_ci if (data == nullptr || size == 0) { 131e1c44949Sopenharmony_ci return; 132e1c44949Sopenharmony_ci } 133e1c44949Sopenharmony_ci 134e1c44949Sopenharmony_ci IsImsSwitchEnabled(data, size); 135e1c44949Sopenharmony_ci GetVoNRState(data, size); 136e1c44949Sopenharmony_ci GetImsConfig(data, size); 137e1c44949Sopenharmony_ci GetImsFeatureValue(data, size); 138e1c44949Sopenharmony_ci GetCallTransferInfo(data, size); 139e1c44949Sopenharmony_ci SetCallTransferInfo(data, size); 140e1c44949Sopenharmony_ci} 141e1c44949Sopenharmony_ci} // namespace OHOS 142e1c44949Sopenharmony_ci 143e1c44949Sopenharmony_ci/* Fuzzer entry point */ 144e1c44949Sopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) 145e1c44949Sopenharmony_ci{ 146e1c44949Sopenharmony_ci OHOS::AddCallTokenFuzzer token; 147e1c44949Sopenharmony_ci /* Run your code on data */ 148e1c44949Sopenharmony_ci OHOS::DoSomethingInterestingWithMyAPI(data, size); 149e1c44949Sopenharmony_ci return 0; 150e1c44949Sopenharmony_ci} 151