1 /*
2 * Copyright (C) 2021 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 #include "mock_dhcp_service.h"
16 #include "wifi_logger.h"
17
18 DEFINE_WIFILOG_DHCP_LABEL("MockDhcpService");
19
20 using namespace OHOS::Wifi;
21
22
GetInstance()23 MockDhcpService &MockDhcpService::GetInstance()
24 {
25 static MockDhcpService gMockDhcpService;
26 return gMockDhcpService;
27 };
28
MockDhcpService()29 MockDhcpService::MockDhcpService() {}
30
~MockDhcpService()31 MockDhcpService::~MockDhcpService() {}
32
33
34 extern "C" {
35 DhcpErrorCode __real_RegisterDhcpClientCallBack(const char *ifname, const ClientCallBack *event);
__wrap_RegisterDhcpClientCallBack(const char * ifname,const ClientCallBack * event)36 DhcpErrorCode __wrap_RegisterDhcpClientCallBack(const char *ifname, const ClientCallBack *event)
37 {
38 WIFI_LOGI("SUN MockDhcpService::RegisterDhcpClientCallBackl");
39 return MockDhcpService::GetInstance().RegisterDhcpClientCallBack(ifname, event);
40 }
41
42 DhcpErrorCode __real_StartDhcpClient(const char *ifname, bool bIpv6);
__wrap_StartDhcpClient(const char * ifname,bool bIpv6)43 DhcpErrorCode __wrap_StartDhcpClient(const char *ifname, bool bIpv6)
44 {
45 WIFI_LOGI("SUN MockDhcpService::StartDhcpClient");
46 return MockDhcpService::GetInstance().StartDhcpClient(ifname, bIpv6);
47 }
48
49 DhcpErrorCode __real_StopDhcpClient(const char *ifname, bool bIpv6);
__wrap_StopDhcpClient(const char * ifname,bool bIpv6)50 DhcpErrorCode __wrap_StopDhcpClient(const char *ifname, bool bIpv6)
51 {
52 WIFI_LOGI("SUN MockDhcpService::StopDhcpClient");
53 return MockDhcpService::GetInstance().StopDhcpClient(ifname, bIpv6);
54 }
55
56 DhcpErrorCode __real_RegisterDhcpServerCallBack(const char *ifname, const ServerCallBack *event);
__wrap_RegisterDhcpServerCallBack(const char * ifname,const ServerCallBack * event)57 DhcpErrorCode __wrap_RegisterDhcpServerCallBack(const char *ifname, const ServerCallBack *event)
58 {
59 WIFI_LOGI("SUN MockDhcpService::RegisterDhcpServerCallBack");
60 return MockDhcpService::GetInstance().RegisterDhcpServerCallBack(ifname, event);
61 }
62
63 DhcpErrorCode __real_StartDhcpServer(const char *ifname);
__wrap_StartDhcpServer(const char * ifname)64 DhcpErrorCode __wrap_StartDhcpServer(const char *ifname)
65 {
66 WIFI_LOGI("SUN MockDhcpService::StartDhcpServer");
67 return MockDhcpService::GetInstance().StartDhcpServer(ifname);
68 }
69
70 DhcpErrorCode __real_StopDhcpServer(const char *ifname);
__wrap_StopDhcpServer(const char * ifname)71 DhcpErrorCode __wrap_StopDhcpServer(const char *ifname)
72 {
73 WIFI_LOGI("SUN MockDhcpService::StopDhcpServer");
74 return MockDhcpService::GetInstance().StopDhcpServer(ifname);
75 }
76
77 DhcpErrorCode __real_SetDhcpRange(const char *ifname, const DhcpRange *range);
__wrap_SetDhcpRange(const char * ifname,const DhcpRange * range)78 DhcpErrorCode __wrap_SetDhcpRange(const char *ifname, const DhcpRange *range)
79 {
80 WIFI_LOGI("SUN MockDhcpService::SetDhcpRange");
81 return MockDhcpService::GetInstance().SetDhcpRange(ifname, range);
82 }
83
84 DhcpErrorCode __real_SetDhcpName(const char *ifname, const char *tagName);
__wrap_SetDhcpName(const char * ifname,const char * tagName)85 DhcpErrorCode __wrap_SetDhcpName(const char *ifname, const char *tagName)
86 {
87 WIFI_LOGI("SUN MockDhcpService::SetDhcpName");
88 return MockDhcpService::GetInstance().SetDhcpName(ifname, tagName);
89 }
90
91 DhcpErrorCode __real_PutDhcpRange(const char *tagName, const DhcpRange *range);
__wrap_PutDhcpRange(const char * tagName,const DhcpRange * range)92 DhcpErrorCode __wrap_PutDhcpRange(const char *tagName, const DhcpRange *range)
93 {
94 WIFI_LOGI("SUN MockDhcpService::PutDhcpRange");
95 return MockDhcpService::GetInstance().PutDhcpRange(tagName, range);
96 }
97
98 DhcpErrorCode __real_RemoveAllDhcpRange(const char *tagName);
__wrap_RemoveAllDhcpRange(const char * tagName)99 DhcpErrorCode __wrap_RemoveAllDhcpRange(const char *tagName)
100 {
101 WIFI_LOGI("SUN MockDhcpService::RemoveAllDhcpRange");
102 return MockDhcpService::GetInstance().RemoveAllDhcpRange(tagName);
103 }
104
105 DhcpErrorCode __real_RemoveDhcpRange(const char *tagName, const void *range);
__wrap_RemoveDhcpRange(const char * tagName,const void * range)106 DhcpErrorCode __wrap_RemoveDhcpRange(const char *tagName, const void *range)
107 {
108 WIFI_LOGI("SUN MockDhcpService::RemoveDhcpRange");
109 return MockDhcpService::GetInstance().RemoveDhcpRange(tagName, range);
110 }
111
112 DhcpErrorCode __real_GetDhcpClientInfos(const char *ifname, int staNumber, DhcpStationInfo *staInfo, int *staSize);
__wrap_GetDhcpClientInfos(const char * ifname,int staNumber,DhcpStationInfo * staInfo,int * staSize)113 DhcpErrorCode __wrap_GetDhcpClientInfos(const char *ifname, int staNumber, DhcpStationInfo *staInfo, int *staSize)
114 {
115 WIFI_LOGI("SUN MockDhcpService::GetDhcpClientInfos");
116 return MockDhcpService::GetInstance().GetDhcpClientInfos(ifname, staNumber, staInfo, staSize);
117 }
118
119 DhcpErrorCode __real_UpdateLeasesTime(const char *leaseTime);
__wrap_UpdateLeasesTime(const char * leaseTime)120 DhcpErrorCode __wrap_UpdateLeasesTime(const char *leaseTime)
121 {
122 WIFI_LOGI("SUN MockDhcpService::UpdateLeasesTime");
123 return MockDhcpService::GetInstance().UpdateLeasesTime(leaseTime);
124 }
125 }