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 "getcscalldata_fuzzer.h" 17d95e75fdSopenharmony_ci 18d95e75fdSopenharmony_ci#include <cstddef> 19d95e75fdSopenharmony_ci#include <cstdint> 20d95e75fdSopenharmony_ci#define private public 21d95e75fdSopenharmony_ci#include "addcellularcalltoken_fuzzer.h" 22d95e75fdSopenharmony_ci#include "cellular_call_handler.h" 23d95e75fdSopenharmony_ci#include "cellular_call_service.h" 24d95e75fdSopenharmony_ci#include "tel_ril_call_parcel.h" 25d95e75fdSopenharmony_ci#include "radio_event.h" 26d95e75fdSopenharmony_ci#include "securec.h" 27d95e75fdSopenharmony_ci#include "system_ability_definition.h" 28d95e75fdSopenharmony_ci 29d95e75fdSopenharmony_ciusing namespace OHOS::Telephony; 30d95e75fdSopenharmony_cinamespace OHOS { 31d95e75fdSopenharmony_cistatic bool g_isInited = false; 32d95e75fdSopenharmony_ciconstexpr int32_t SLOT_NUM = 2; 33d95e75fdSopenharmony_ciconstexpr int32_t STATE_NUM = 9; 34d95e75fdSopenharmony_ci 35d95e75fdSopenharmony_cibool IsServiceInited() 36d95e75fdSopenharmony_ci{ 37d95e75fdSopenharmony_ci if (!g_isInited) { 38d95e75fdSopenharmony_ci DelayedSingleton<CellularCallService>::GetInstance()->OnStart(); 39d95e75fdSopenharmony_ci } 40d95e75fdSopenharmony_ci if (!g_isInited && (static_cast<int32_t>(DelayedSingleton<CellularCallService>::GetInstance()->state_) == 41d95e75fdSopenharmony_ci static_cast<int32_t>(ServiceRunningState::STATE_RUNNING))) { 42d95e75fdSopenharmony_ci g_isInited = true; 43d95e75fdSopenharmony_ci } 44d95e75fdSopenharmony_ci return g_isInited; 45d95e75fdSopenharmony_ci} 46d95e75fdSopenharmony_ci 47d95e75fdSopenharmony_civoid GetCsCallData(std::shared_ptr<CellularCallHandler> handle, AppExecFwk::InnerEvent::Pointer event, 48d95e75fdSopenharmony_ci const uint8_t *data, size_t size) 49d95e75fdSopenharmony_ci{ 50d95e75fdSopenharmony_ci if (!IsServiceInited()) { 51d95e75fdSopenharmony_ci return; 52d95e75fdSopenharmony_ci } 53d95e75fdSopenharmony_ci 54d95e75fdSopenharmony_ci std::string number(reinterpret_cast<const char *>(data), size); 55d95e75fdSopenharmony_ci CallInfo info; 56d95e75fdSopenharmony_ci CallInfoList infoList; 57d95e75fdSopenharmony_ci info.number = number; 58d95e75fdSopenharmony_ci infoList.calls.push_back(info); 59d95e75fdSopenharmony_ci int32_t state = static_cast<int32_t>(size % STATE_NUM); 60d95e75fdSopenharmony_ci int32_t slotId = static_cast<int32_t>(size % SLOT_NUM); 61d95e75fdSopenharmony_ci 62d95e75fdSopenharmony_ci handle->GetCsCallData(event); 63d95e75fdSopenharmony_ci handle->GetImsCallData(event); 64d95e75fdSopenharmony_ci handle->GetSatelliteCallData(event); 65d95e75fdSopenharmony_ci handle->ImsCallStatusInfoReport(event); 66d95e75fdSopenharmony_ci handle->SatelliteCallStatusInfoReport(event); 67d95e75fdSopenharmony_ci handle->CellularCallIncomingStartTrace(state); 68d95e75fdSopenharmony_ci handle->GetCsCallsDataResponse(event); 69d95e75fdSopenharmony_ci handle->GetImsCallsDataResponse(event); 70d95e75fdSopenharmony_ci handle->GetSatelliteCallsDataResponse(event); 71d95e75fdSopenharmony_ci handle->DialResponse(event); 72d95e75fdSopenharmony_ci handle->DialSatelliteResponse(event); 73d95e75fdSopenharmony_ci handle->SendDtmfResponse(event); 74d95e75fdSopenharmony_ci handle->StartDtmfResponse(event); 75d95e75fdSopenharmony_ci handle->SimStateChangeReport(event); 76d95e75fdSopenharmony_ci handle->SimRecordsLoadedReport(event); 77d95e75fdSopenharmony_ci handle->StopDtmfResponse(event); 78d95e75fdSopenharmony_ci handle->SetSlotId(slotId); 79d95e75fdSopenharmony_ci handle->GetSlotId(); 80d95e75fdSopenharmony_ci handle->CurrentTimeMillis(); 81d95e75fdSopenharmony_ci handle->GetCsCallsDataRequest(event); 82d95e75fdSopenharmony_ci handle->GetImsCallsDataRequest(event); 83d95e75fdSopenharmony_ci handle->GetSatelliteCallsDataRequest(event); 84d95e75fdSopenharmony_ci handle->ReportCsCallsData(infoList); 85d95e75fdSopenharmony_ci} 86d95e75fdSopenharmony_ci 87d95e75fdSopenharmony_civoid RegisterHandler(std::shared_ptr<CellularCallHandler> handle, AppExecFwk::InnerEvent::Pointer event, 88d95e75fdSopenharmony_ci const uint8_t *data, size_t size) 89d95e75fdSopenharmony_ci{ 90d95e75fdSopenharmony_ci if (!IsServiceInited()) { 91d95e75fdSopenharmony_ci return; 92d95e75fdSopenharmony_ci } 93d95e75fdSopenharmony_ci 94d95e75fdSopenharmony_ci std::string number(reinterpret_cast<const char *>(data), size); 95d95e75fdSopenharmony_ci ImsCurrentCall info; 96d95e75fdSopenharmony_ci ImsCurrentCallList infoList; 97d95e75fdSopenharmony_ci info.number = number; 98d95e75fdSopenharmony_ci info.name = number; 99d95e75fdSopenharmony_ci infoList.calls.push_back(info); 100d95e75fdSopenharmony_ci 101d95e75fdSopenharmony_ci SatelliteCurrentCall satelliteInfo; 102d95e75fdSopenharmony_ci SatelliteCurrentCallList satelliteInfoList; 103d95e75fdSopenharmony_ci satelliteInfo.number = number; 104d95e75fdSopenharmony_ci satelliteInfoList.calls.push_back(satelliteInfo); 105d95e75fdSopenharmony_ci 106d95e75fdSopenharmony_ci handle->RegisterHandler(event); 107d95e75fdSopenharmony_ci handle->SetDomainPreferenceModeResponse(event); 108d95e75fdSopenharmony_ci handle->GetDomainPreferenceModeResponse(event); 109d95e75fdSopenharmony_ci handle->SetImsSwitchStatusResponse(event); 110d95e75fdSopenharmony_ci handle->GetImsSwitchStatusResponse(event); 111d95e75fdSopenharmony_ci handle->UssdNotifyResponse(event); 112d95e75fdSopenharmony_ci handle->SetMuteResponse(event); 113d95e75fdSopenharmony_ci handle->GetMuteResponse(event); 114d95e75fdSopenharmony_ci handle->GetEmergencyCallListResponse(event); 115d95e75fdSopenharmony_ci handle->SetEmergencyCallListResponse(event); 116d95e75fdSopenharmony_ci handle->CallRingBackVoiceResponse(event); 117d95e75fdSopenharmony_ci handle->GetCallFailReasonResponse(event); 118d95e75fdSopenharmony_ci handle->UpdateSrvccStateReport(event); 119d95e75fdSopenharmony_ci handle->ReportEccChanged(event); 120d95e75fdSopenharmony_ci handle->SrvccStateCompleted(); 121d95e75fdSopenharmony_ci handle->GetMMIResponse(event); 122d95e75fdSopenharmony_ci handle->GetCallWaitingResponse(event); 123d95e75fdSopenharmony_ci handle->GetClirResponse(event); 124d95e75fdSopenharmony_ci handle->ReportImsCallsData(infoList); 125d95e75fdSopenharmony_ci handle->ReportSatelliteCallsData(satelliteInfoList); 126d95e75fdSopenharmony_ci handle->SetClirResponse(event); 127d95e75fdSopenharmony_ci handle->GetClipResponse(event); 128d95e75fdSopenharmony_ci handle->SetCallTransferInfoResponse(event); 129d95e75fdSopenharmony_ci handle->GetCallRestrictionResponse(event); 130d95e75fdSopenharmony_ci handle->SetCallRestrictionResponse(event); 131d95e75fdSopenharmony_ci handle->SetBarringPasswordResponse(event); 132d95e75fdSopenharmony_ci handle->SendUssdResponse(event); 133d95e75fdSopenharmony_ci handle->SendUnlockPinPukResponse(event); 134d95e75fdSopenharmony_ci handle->HandleOperatorConfigChanged(event); 135d95e75fdSopenharmony_ci handle->UpdateRsrvccStateReport(event); 136d95e75fdSopenharmony_ci handle->SetVoNRSwitchStatusResponse(event); 137d95e75fdSopenharmony_ci} 138d95e75fdSopenharmony_ci 139d95e75fdSopenharmony_civoid DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size) 140d95e75fdSopenharmony_ci{ 141d95e75fdSopenharmony_ci if (data == nullptr || size == 0) { 142d95e75fdSopenharmony_ci return; 143d95e75fdSopenharmony_ci } 144d95e75fdSopenharmony_ci 145d95e75fdSopenharmony_ci if (!IsServiceInited()) { 146d95e75fdSopenharmony_ci return; 147d95e75fdSopenharmony_ci } 148d95e75fdSopenharmony_ci 149d95e75fdSopenharmony_ci int32_t slotId = static_cast<int32_t>(size % SLOT_NUM); 150d95e75fdSopenharmony_ci RadioEvent radioEvent = static_cast<RadioEvent>(size); 151d95e75fdSopenharmony_ci std::shared_ptr<CellularCallHandler> handle = 152d95e75fdSopenharmony_ci DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId); 153d95e75fdSopenharmony_ci if (handle == nullptr) { 154d95e75fdSopenharmony_ci return; 155d95e75fdSopenharmony_ci } 156d95e75fdSopenharmony_ci AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(radioEvent); 157d95e75fdSopenharmony_ci GetCsCallData(handle, std::move(event), data, size); 158d95e75fdSopenharmony_ci event = AppExecFwk::InnerEvent::Get(radioEvent); 159d95e75fdSopenharmony_ci RegisterHandler(handle, std::move(event), data, size); 160d95e75fdSopenharmony_ci} 161d95e75fdSopenharmony_ci} // namespace OHOS 162d95e75fdSopenharmony_ci 163d95e75fdSopenharmony_ci/* Fuzzer entry point */ 164d95e75fdSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) 165d95e75fdSopenharmony_ci{ 166d95e75fdSopenharmony_ci OHOS::AddCellularCallTokenFuzzer token; 167d95e75fdSopenharmony_ci /* Run your code on data */ 168d95e75fdSopenharmony_ci OHOS::DoSomethingInterestingWithMyAPI(data, size); 169d95e75fdSopenharmony_ci return 0; 170d95e75fdSopenharmony_ci} 171