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 "dialcall_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_ability_callback.h" 23e1c44949Sopenharmony_ci 24e1c44949Sopenharmony_ciusing namespace OHOS::Telephony; 25e1c44949Sopenharmony_cinamespace OHOS { 26e1c44949Sopenharmony_ciconstexpr int32_t SLOT_NUM = 2; 27e1c44949Sopenharmony_ciconstexpr int32_t ACTIVE_NUM = 2; 28e1c44949Sopenharmony_ciconstexpr int32_t VEDIO_STATE_NUM = 2; 29e1c44949Sopenharmony_ciconstexpr int32_t DIAL_SCENE_NUM = 3; 30e1c44949Sopenharmony_ciconstexpr int32_t DIAL_TYPE_NUM = 3; 31e1c44949Sopenharmony_ciconstexpr int32_t CALL_TYPE_NUM = 3; 32e1c44949Sopenharmony_ciconstexpr int32_t CALL_ID_NUM = 10; 33e1c44949Sopenharmony_ci 34e1c44949Sopenharmony_civoid OnRegisterVoipCallManagerCallback(const uint8_t *data, size_t size) 35e1c44949Sopenharmony_ci{ 36e1c44949Sopenharmony_ci if (!IsServiceInited()) { 37e1c44949Sopenharmony_ci return; 38e1c44949Sopenharmony_ci } 39e1c44949Sopenharmony_ci MessageParcel dataMessageParcel; 40e1c44949Sopenharmony_ci std::unique_ptr<CallAbilityCallback> callbackWrap = std::make_unique<CallAbilityCallback>(); 41e1c44949Sopenharmony_ci if (callbackWrap == nullptr) { 42e1c44949Sopenharmony_ci return; 43e1c44949Sopenharmony_ci } 44e1c44949Sopenharmony_ci dataMessageParcel.WriteRemoteObject(callbackWrap.release()->AsObject().GetRefPtr()); 45e1c44949Sopenharmony_ci MessageParcel reply; 46e1c44949Sopenharmony_ci DelayedSingleton<CallManagerService>::GetInstance()->OnRegisterVoipCallManagerCallback(dataMessageParcel, reply); 47e1c44949Sopenharmony_ci} 48e1c44949Sopenharmony_ci 49e1c44949Sopenharmony_civoid OnRemoteRequest(const uint8_t *data, size_t size) 50e1c44949Sopenharmony_ci{ 51e1c44949Sopenharmony_ci if (!IsServiceInited()) { 52e1c44949Sopenharmony_ci return; 53e1c44949Sopenharmony_ci } 54e1c44949Sopenharmony_ci 55e1c44949Sopenharmony_ci MessageParcel dataMessageParcel; 56e1c44949Sopenharmony_ci if (!dataMessageParcel.WriteInterfaceToken(CallManagerServiceStub::GetDescriptor())) { 57e1c44949Sopenharmony_ci return; 58e1c44949Sopenharmony_ci } 59e1c44949Sopenharmony_ci dataMessageParcel.RewindRead(0); 60e1c44949Sopenharmony_ci uint32_t code = static_cast<uint32_t>(size); 61e1c44949Sopenharmony_ci MessageParcel reply; 62e1c44949Sopenharmony_ci MessageOption option; 63e1c44949Sopenharmony_ci DelayedSingleton<CallManagerService>::GetInstance()->OnRemoteRequest(code, dataMessageParcel, reply, option); 64e1c44949Sopenharmony_ci} 65e1c44949Sopenharmony_ci 66e1c44949Sopenharmony_ciint32_t OnRegisterCallBack(const uint8_t *data, size_t size) 67e1c44949Sopenharmony_ci{ 68e1c44949Sopenharmony_ci if (!IsServiceInited()) { 69e1c44949Sopenharmony_ci return TELEPHONY_ERROR; 70e1c44949Sopenharmony_ci } 71e1c44949Sopenharmony_ci MessageParcel dataMessageParcel; 72e1c44949Sopenharmony_ci std::unique_ptr<CallAbilityCallback> callbackWrap = std::make_unique<CallAbilityCallback>(); 73e1c44949Sopenharmony_ci if (callbackWrap == nullptr) { 74e1c44949Sopenharmony_ci return TELEPHONY_ERR_LOCAL_PTR_NULL; 75e1c44949Sopenharmony_ci } 76e1c44949Sopenharmony_ci dataMessageParcel.WriteRemoteObject(callbackWrap.release()->AsObject().GetRefPtr()); 77e1c44949Sopenharmony_ci MessageParcel reply; 78e1c44949Sopenharmony_ci return DelayedSingleton<CallManagerService>::GetInstance()->OnRegisterCallBack(dataMessageParcel, reply); 79e1c44949Sopenharmony_ci} 80e1c44949Sopenharmony_ci 81e1c44949Sopenharmony_cibool HasCall(const uint8_t *data, size_t size) 82e1c44949Sopenharmony_ci{ 83e1c44949Sopenharmony_ci if (!IsServiceInited()) { 84e1c44949Sopenharmony_ci return TELEPHONY_ERROR; 85e1c44949Sopenharmony_ci } 86e1c44949Sopenharmony_ci MessageParcel dataParcel; 87e1c44949Sopenharmony_ci dataParcel.WriteBuffer(data, size); 88e1c44949Sopenharmony_ci dataParcel.RewindRead(0); 89e1c44949Sopenharmony_ci MessageParcel reply; 90e1c44949Sopenharmony_ci return DelayedSingleton<CallManagerService>::GetInstance()->OnHasCall(dataParcel, reply); 91e1c44949Sopenharmony_ci} 92e1c44949Sopenharmony_ci 93e1c44949Sopenharmony_ciint32_t GetCallState(const uint8_t *data, size_t size) 94e1c44949Sopenharmony_ci{ 95e1c44949Sopenharmony_ci if (!IsServiceInited()) { 96e1c44949Sopenharmony_ci return TELEPHONY_ERROR; 97e1c44949Sopenharmony_ci } 98e1c44949Sopenharmony_ci MessageParcel dataParcel; 99e1c44949Sopenharmony_ci dataParcel.WriteBuffer(data, size); 100e1c44949Sopenharmony_ci dataParcel.RewindRead(0); 101e1c44949Sopenharmony_ci MessageParcel reply; 102e1c44949Sopenharmony_ci return DelayedSingleton<CallManagerService>::GetInstance()->OnGetCallState(dataParcel, reply); 103e1c44949Sopenharmony_ci} 104e1c44949Sopenharmony_ci 105e1c44949Sopenharmony_ciint32_t GetCallWaiting(const uint8_t *data, size_t size) 106e1c44949Sopenharmony_ci{ 107e1c44949Sopenharmony_ci if (!IsServiceInited()) { 108e1c44949Sopenharmony_ci return TELEPHONY_ERROR; 109e1c44949Sopenharmony_ci } 110e1c44949Sopenharmony_ci int32_t slotId = static_cast<int32_t>(size % SLOT_NUM); 111e1c44949Sopenharmony_ci MessageParcel dataParcel; 112e1c44949Sopenharmony_ci dataParcel.WriteInt32(slotId); 113e1c44949Sopenharmony_ci dataParcel.WriteBuffer(data, size); 114e1c44949Sopenharmony_ci dataParcel.RewindRead(0); 115e1c44949Sopenharmony_ci MessageParcel reply; 116e1c44949Sopenharmony_ci return DelayedSingleton<CallManagerService>::GetInstance()->OnGetCallWaiting(dataParcel, reply); 117e1c44949Sopenharmony_ci} 118e1c44949Sopenharmony_ci 119e1c44949Sopenharmony_cibool IsRinging(const uint8_t *data, size_t size) 120e1c44949Sopenharmony_ci{ 121e1c44949Sopenharmony_ci if (!IsServiceInited()) { 122e1c44949Sopenharmony_ci return false; 123e1c44949Sopenharmony_ci } 124e1c44949Sopenharmony_ci MessageParcel dataParcel; 125e1c44949Sopenharmony_ci dataParcel.WriteBuffer(data, size); 126e1c44949Sopenharmony_ci dataParcel.RewindRead(0); 127e1c44949Sopenharmony_ci MessageParcel reply; 128e1c44949Sopenharmony_ci return DelayedSingleton<CallManagerService>::GetInstance()->OnIsRinging(dataParcel, reply); 129e1c44949Sopenharmony_ci} 130e1c44949Sopenharmony_ci 131e1c44949Sopenharmony_cibool IsInEmergencyCall(const uint8_t *data, size_t size) 132e1c44949Sopenharmony_ci{ 133e1c44949Sopenharmony_ci if (!IsServiceInited()) { 134e1c44949Sopenharmony_ci return false; 135e1c44949Sopenharmony_ci } 136e1c44949Sopenharmony_ci MessageParcel dataParcel; 137e1c44949Sopenharmony_ci dataParcel.WriteBuffer(data, size); 138e1c44949Sopenharmony_ci dataParcel.RewindRead(0); 139e1c44949Sopenharmony_ci MessageParcel reply; 140e1c44949Sopenharmony_ci return DelayedSingleton<CallManagerService>::GetInstance()->OnIsInEmergencyCall(dataParcel, reply); 141e1c44949Sopenharmony_ci} 142e1c44949Sopenharmony_ci 143e1c44949Sopenharmony_ciint32_t DialCall(const uint8_t *data, size_t size) 144e1c44949Sopenharmony_ci{ 145e1c44949Sopenharmony_ci if (!IsServiceInited()) { 146e1c44949Sopenharmony_ci return TELEPHONY_ERROR; 147e1c44949Sopenharmony_ci } 148e1c44949Sopenharmony_ci std::string number(reinterpret_cast<const char *>(data), size); 149e1c44949Sopenharmony_ci auto numberU16 = Str8ToStr16(number); 150e1c44949Sopenharmony_ci int32_t accountId = static_cast<int32_t>(size % SLOT_NUM); 151e1c44949Sopenharmony_ci int32_t videoState = static_cast<int32_t>(size % VEDIO_STATE_NUM); 152e1c44949Sopenharmony_ci int32_t dialScene = static_cast<int32_t>(size % DIAL_SCENE_NUM); 153e1c44949Sopenharmony_ci int32_t dialType = static_cast<int32_t>(size % DIAL_TYPE_NUM); 154e1c44949Sopenharmony_ci int32_t callType = static_cast<int32_t>(size % CALL_TYPE_NUM); 155e1c44949Sopenharmony_ci MessageParcel dataParcel; 156e1c44949Sopenharmony_ci dataParcel.WriteString16(numberU16); 157e1c44949Sopenharmony_ci dataParcel.WriteInt32(accountId); 158e1c44949Sopenharmony_ci dataParcel.WriteInt32(videoState); 159e1c44949Sopenharmony_ci dataParcel.WriteInt32(dialScene); 160e1c44949Sopenharmony_ci dataParcel.WriteInt32(dialType); 161e1c44949Sopenharmony_ci dataParcel.WriteInt32(callType); 162e1c44949Sopenharmony_ci dataParcel.RewindRead(0); 163e1c44949Sopenharmony_ci 164e1c44949Sopenharmony_ci MessageParcel reply; 165e1c44949Sopenharmony_ci return DelayedSingleton<CallManagerService>::GetInstance()->OnDialCall(dataParcel, reply); 166e1c44949Sopenharmony_ci} 167e1c44949Sopenharmony_ci 168e1c44949Sopenharmony_civoid RemoveMissedIncomingCallNotification(const uint8_t *data, size_t size) 169e1c44949Sopenharmony_ci{ 170e1c44949Sopenharmony_ci if (!IsServiceInited()) { 171e1c44949Sopenharmony_ci return; 172e1c44949Sopenharmony_ci } 173e1c44949Sopenharmony_ci MessageParcel dataMessageParcel; 174e1c44949Sopenharmony_ci dataMessageParcel.WriteBuffer(data, size); 175e1c44949Sopenharmony_ci dataMessageParcel.RewindRead(0); 176e1c44949Sopenharmony_ci MessageParcel reply; 177e1c44949Sopenharmony_ci DelayedSingleton<CallManagerService>::GetInstance()->OnRemoveMissedIncomingCallNotification( 178e1c44949Sopenharmony_ci dataMessageParcel, reply); 179e1c44949Sopenharmony_ci} 180e1c44949Sopenharmony_ci 181e1c44949Sopenharmony_ciint32_t SetCallWaiting(const uint8_t *data, size_t size) 182e1c44949Sopenharmony_ci{ 183e1c44949Sopenharmony_ci if (!IsServiceInited()) { 184e1c44949Sopenharmony_ci return TELEPHONY_ERROR; 185e1c44949Sopenharmony_ci } 186e1c44949Sopenharmony_ci int32_t slotId = static_cast<int32_t>(size % SLOT_NUM); 187e1c44949Sopenharmony_ci int32_t activate = static_cast<int32_t>(size % ACTIVE_NUM); 188e1c44949Sopenharmony_ci MessageParcel dataParcel; 189e1c44949Sopenharmony_ci dataParcel.WriteInt32(slotId); 190e1c44949Sopenharmony_ci dataParcel.WriteBool(activate); 191e1c44949Sopenharmony_ci dataParcel.RewindRead(0); 192e1c44949Sopenharmony_ci MessageParcel reply; 193e1c44949Sopenharmony_ci return DelayedSingleton<CallManagerService>::GetInstance()->OnSetCallWaiting(dataParcel, reply); 194e1c44949Sopenharmony_ci} 195e1c44949Sopenharmony_ci 196e1c44949Sopenharmony_ciint32_t SetCallRestriction(const uint8_t *data, size_t size) 197e1c44949Sopenharmony_ci{ 198e1c44949Sopenharmony_ci if (!IsServiceInited()) { 199e1c44949Sopenharmony_ci return TELEPHONY_ERROR; 200e1c44949Sopenharmony_ci } 201e1c44949Sopenharmony_ci CallRestrictionInfo info; 202e1c44949Sopenharmony_ci int32_t slotId = static_cast<int32_t>(size % SLOT_NUM); 203e1c44949Sopenharmony_ci std::string msg(reinterpret_cast<const char *>(data), size); 204e1c44949Sopenharmony_ci int32_t length = msg.length() > kMaxNumberLen ? kMaxNumberLen : msg.length(); 205e1c44949Sopenharmony_ci memcpy_s(info.password, kMaxNumberLen, msg.c_str(), length); 206e1c44949Sopenharmony_ci MessageParcel dataParcel; 207e1c44949Sopenharmony_ci dataParcel.WriteInt32(slotId); 208e1c44949Sopenharmony_ci dataParcel.WriteRawData((const void *)&info, sizeof(CallRestrictionInfo)); 209e1c44949Sopenharmony_ci dataParcel.RewindRead(0); 210e1c44949Sopenharmony_ci MessageParcel reply; 211e1c44949Sopenharmony_ci return DelayedSingleton<CallManagerService>::GetInstance()->OnSetCallRestriction(dataParcel, reply); 212e1c44949Sopenharmony_ci} 213e1c44949Sopenharmony_ci 214e1c44949Sopenharmony_ciint32_t JoinConference(const uint8_t *data, size_t size) 215e1c44949Sopenharmony_ci{ 216e1c44949Sopenharmony_ci if (!IsServiceInited()) { 217e1c44949Sopenharmony_ci return TELEPHONY_ERROR; 218e1c44949Sopenharmony_ci } 219e1c44949Sopenharmony_ci int32_t callId = static_cast<int32_t>(size % CALL_ID_NUM); 220e1c44949Sopenharmony_ci std::vector<std::u16string> numberList { u"0000000000" }; 221e1c44949Sopenharmony_ci MessageParcel dataParcel; 222e1c44949Sopenharmony_ci dataParcel.WriteInt32(callId); 223e1c44949Sopenharmony_ci dataParcel.WriteString16Vector(numberList); 224e1c44949Sopenharmony_ci dataParcel.RewindRead(0); 225e1c44949Sopenharmony_ci MessageParcel reply; 226e1c44949Sopenharmony_ci return DelayedSingleton<CallManagerService>::GetInstance()->OnJoinConference(dataParcel, reply); 227e1c44949Sopenharmony_ci} 228e1c44949Sopenharmony_ci 229e1c44949Sopenharmony_ciint32_t StartRtt(const uint8_t *data, size_t size) 230e1c44949Sopenharmony_ci{ 231e1c44949Sopenharmony_ci if (!IsServiceInited()) { 232e1c44949Sopenharmony_ci return TELEPHONY_ERROR; 233e1c44949Sopenharmony_ci } 234e1c44949Sopenharmony_ci 235e1c44949Sopenharmony_ci int32_t callId = static_cast<int32_t>(size % CALL_ID_NUM); 236e1c44949Sopenharmony_ci std::string msg(reinterpret_cast<const char *>(data), size); 237e1c44949Sopenharmony_ci MessageParcel dataParcel; 238e1c44949Sopenharmony_ci dataParcel.WriteInt32(callId); 239e1c44949Sopenharmony_ci dataParcel.WriteString(msg); 240e1c44949Sopenharmony_ci dataParcel.RewindRead(0); 241e1c44949Sopenharmony_ci MessageParcel reply; 242e1c44949Sopenharmony_ci return DelayedSingleton<CallManagerService>::GetInstance()->OnStartRtt(dataParcel, reply); 243e1c44949Sopenharmony_ci} 244e1c44949Sopenharmony_ci 245e1c44949Sopenharmony_ciint32_t InputDialerSpecialCode(const uint8_t *data, size_t size) 246e1c44949Sopenharmony_ci{ 247e1c44949Sopenharmony_ci if (!IsServiceInited()) { 248e1c44949Sopenharmony_ci return TELEPHONY_ERROR; 249e1c44949Sopenharmony_ci } 250e1c44949Sopenharmony_ci std::string specialCode(reinterpret_cast<const char *>(data), size); 251e1c44949Sopenharmony_ci MessageParcel dataParcel; 252e1c44949Sopenharmony_ci dataParcel.WriteString(specialCode); 253e1c44949Sopenharmony_ci dataParcel.RewindRead(0); 254e1c44949Sopenharmony_ci MessageParcel reply; 255e1c44949Sopenharmony_ci return DelayedSingleton<CallManagerService>::GetInstance()->OnInputDialerSpecialCode(dataParcel, reply); 256e1c44949Sopenharmony_ci} 257e1c44949Sopenharmony_ci 258e1c44949Sopenharmony_ciint32_t CancelCallUpgrade(const uint8_t *data, size_t size) 259e1c44949Sopenharmony_ci{ 260e1c44949Sopenharmony_ci if (!IsServiceInited()) { 261e1c44949Sopenharmony_ci return TELEPHONY_ERROR; 262e1c44949Sopenharmony_ci } 263e1c44949Sopenharmony_ci MessageParcel dataParcel; 264e1c44949Sopenharmony_ci MessageParcel replyParcel; 265e1c44949Sopenharmony_ci int32_t callId = static_cast<int32_t>(size % CALL_ID_NUM); 266e1c44949Sopenharmony_ci dataParcel.WriteInt32(callId); 267e1c44949Sopenharmony_ci dataParcel.RewindRead(0); 268e1c44949Sopenharmony_ci return DelayedSingleton<CallManagerService>::GetInstance()->OnCancelCallUpgrade(dataParcel, replyParcel); 269e1c44949Sopenharmony_ci} 270e1c44949Sopenharmony_ci 271e1c44949Sopenharmony_ciint32_t RequestCameraCapabilities(const uint8_t *data, size_t size) 272e1c44949Sopenharmony_ci{ 273e1c44949Sopenharmony_ci if (!IsServiceInited()) { 274e1c44949Sopenharmony_ci return TELEPHONY_ERROR; 275e1c44949Sopenharmony_ci } 276e1c44949Sopenharmony_ci MessageParcel dataParcel; 277e1c44949Sopenharmony_ci MessageParcel replyParcel; 278e1c44949Sopenharmony_ci int32_t callId = static_cast<int32_t>(size % CALL_ID_NUM); 279e1c44949Sopenharmony_ci dataParcel.WriteInt32(callId); 280e1c44949Sopenharmony_ci dataParcel.RewindRead(0); 281e1c44949Sopenharmony_ci return DelayedSingleton<CallManagerService>::GetInstance()->OnRequestCameraCapabilities(dataParcel, replyParcel); 282e1c44949Sopenharmony_ci} 283e1c44949Sopenharmony_ci 284e1c44949Sopenharmony_civoid DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size) 285e1c44949Sopenharmony_ci{ 286e1c44949Sopenharmony_ci if (data == nullptr || size == 0) { 287e1c44949Sopenharmony_ci return; 288e1c44949Sopenharmony_ci } 289e1c44949Sopenharmony_ci OnRegisterVoipCallManagerCallback(data, size); 290e1c44949Sopenharmony_ci OnRemoteRequest(data, size); 291e1c44949Sopenharmony_ci OnRegisterCallBack(data, size); 292e1c44949Sopenharmony_ci HasCall(data, size); 293e1c44949Sopenharmony_ci GetCallState(data, size); 294e1c44949Sopenharmony_ci GetCallWaiting(data, size); 295e1c44949Sopenharmony_ci IsRinging(data, size); 296e1c44949Sopenharmony_ci IsInEmergencyCall(data, size); 297e1c44949Sopenharmony_ci DialCall(data, size); 298e1c44949Sopenharmony_ci RemoveMissedIncomingCallNotification(data, size); 299e1c44949Sopenharmony_ci SetCallWaiting(data, size); 300e1c44949Sopenharmony_ci SetCallRestriction(data, size); 301e1c44949Sopenharmony_ci JoinConference(data, size); 302e1c44949Sopenharmony_ci StartRtt(data, size); 303e1c44949Sopenharmony_ci InputDialerSpecialCode(data, size); 304e1c44949Sopenharmony_ci CancelCallUpgrade(data, size); 305e1c44949Sopenharmony_ci RequestCameraCapabilities(data, size); 306e1c44949Sopenharmony_ci} 307e1c44949Sopenharmony_ci} // namespace OHOS 308e1c44949Sopenharmony_ci 309e1c44949Sopenharmony_ci/* Fuzzer entry point */ 310e1c44949Sopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) 311e1c44949Sopenharmony_ci{ 312e1c44949Sopenharmony_ci OHOS::AddCallTokenFuzzer token; 313e1c44949Sopenharmony_ci /* Run your code on data */ 314e1c44949Sopenharmony_ci OHOS::DoSomethingInterestingWithMyAPI(data, size); 315e1c44949Sopenharmony_ci return 0; 316e1c44949Sopenharmony_ci} 317