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