• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2023 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 "dhcp_event.h"
16 #include "dhcp_logger.h"
17 
18 DEFINE_DHCPLOG_DHCP_LABEL("DhcpSAEvent");
19 
DhcpClientCallBack()20 DhcpClientCallBack::DhcpClientCallBack() : callbackEvent(nullptr)
21 {
22     DHCP_LOGI("DhcpClientCallBack");
23 }
24 
~DhcpClientCallBack()25 DhcpClientCallBack::~DhcpClientCallBack()
26 {
27     DHCP_LOGI("~DhcpClientCallBack");
28 }
29 
OnIpSuccessChanged(int status,const std::string & ifname,OHOS::Wifi::DhcpResult & result)30 void DhcpClientCallBack::OnIpSuccessChanged(int status, const std::string& ifname, OHOS::Wifi::DhcpResult& result)
31     __attribute__((no_sanitize("cfi")))
32 {
33     DHCP_LOGI("DhcpClientCallBack OnIpSuccessChanged status:%{public}d,ifname:%{public}s", status, ifname.c_str());
34     if ((callbackEvent != nullptr) && (callbackEvent->OnIpSuccessChanged != nullptr)) {
35         DhcpResult dhcpResult;
36         dhcpResult.iptype = result.iptype;
37         dhcpResult.isOptSuc = result.isOptSuc;
38         dhcpResult.uOptLeasetime = result.uLeaseTime;
39         dhcpResult.uAddTime = result.uAddTime;
40         dhcpResult.uGetTime = result.uGetTime;
41         if (strcpy_s(dhcpResult.strOptClientId, DHCP_MAX_FILE_BYTES, result.strYourCli.c_str()) != EOK) {
42             DHCP_LOGE("OnIpSuccessChanged strOptClientId strcpy_s failed!");
43         }
44         if (strcpy_s(dhcpResult.strOptServerId, DHCP_MAX_FILE_BYTES, result.strServer.c_str()) != EOK) {
45             DHCP_LOGE("OnIpSuccessChanged strOptServerId strcpy_s failed!");
46         }
47         if (strcpy_s(dhcpResult.strOptSubnet, DHCP_MAX_FILE_BYTES, result.strSubnet.c_str()) != EOK) {
48             DHCP_LOGE("OnIpSuccessChanged strOptSubnet strcpy_s failed!");
49         }
50         if (strcpy_s(dhcpResult.strOptDns1, DHCP_MAX_FILE_BYTES, result.strDns1.c_str()) != EOK) {
51             DHCP_LOGE("OnIpSuccessChanged strOptDns1 strcpy_s failed!");
52         }
53         if (strcpy_s(dhcpResult.strOptDns2, DHCP_MAX_FILE_BYTES, result.strDns2.c_str()) != EOK) {
54             DHCP_LOGE("OnIpSuccessChanged strOptDns2 strcpy_s failed!");
55         }
56         if (strcpy_s(dhcpResult.strOptRouter1, DHCP_MAX_FILE_BYTES, result.strRouter1.c_str()) != EOK) {
57             DHCP_LOGE("OnIpSuccessChanged strOptRouter1 strcpy_s failed!");
58         }
59         if (strcpy_s(dhcpResult.strOptRouter2, DHCP_MAX_FILE_BYTES, result.strRouter2.c_str()) != EOK) {
60             DHCP_LOGE("OnIpSuccessChanged strOptRouter2 strcpy_s failed!");
61         }
62         if (strcpy_s(dhcpResult.strOptVendor, DHCP_MAX_FILE_BYTES, result.strVendor.c_str()) != EOK) {
63             DHCP_LOGE("OnIpSuccessChanged strOptVendor strcpy_s failed!");
64         }
65         DHCP_LOGI("OnIpSuccessChanged callbackEvent status:%{public}d", status);
66         callbackEvent->OnIpSuccessChanged(status, ifname.c_str(), &dhcpResult);
67     } else {
68         DHCP_LOGE("callbackEvent or OnIpSuccessChanged is null!");
69     }
70 }
71 
OnIpFailChanged(int status,const std::string & ifname,const std::string & reason)72 void DhcpClientCallBack::OnIpFailChanged(int status, const std::string& ifname, const std::string& reason)
73     __attribute__((no_sanitize("cfi")))
74 {
75     DHCP_LOGI("DhcpClientCallBack OnIpFailChanged status:%{public}d, ifname:%{public}s, reason:%{public}s", status,
76         ifname.c_str(), reason.c_str());
77     if ((callbackEvent != nullptr) && (callbackEvent->OnIpFailChanged != nullptr)) {
78         DHCP_LOGI("OnIpFailChanged callbackEvent status:%{public}d", status);
79         callbackEvent->OnIpFailChanged(status, ifname.c_str(), reason.c_str());
80     } else {
81         DHCP_LOGE("callbackEvent or OnIpFailChanged is null!");
82     }
83 }
84 #ifndef OHOS_ARCH_LITE
AsObject()85 OHOS::sptr<OHOS::IRemoteObject> DhcpClientCallBack::AsObject()
86 {
87     DHCP_LOGI("DhcpClientCallBack AsObject!");
88     return nullptr;
89 }
90 #endif
RegisterCallBack(const std::string & ifname,const ClientCallBack * event)91 void DhcpClientCallBack::RegisterCallBack(const std::string& ifname, const ClientCallBack *event)
92 {
93     if (event == nullptr) {
94         DHCP_LOGE("DhcpClientCallBack event is nullptr!");
95         return;
96     }
97     callbackEvent = event;
98 }
99 
DhcpServerCallBack()100 DhcpServerCallBack::DhcpServerCallBack() : callbackEvent(nullptr)
101 {
102     DHCP_LOGI("DhcpServerCallBack");
103 }
104 
~DhcpServerCallBack()105 DhcpServerCallBack::~DhcpServerCallBack()
106 {
107     DHCP_LOGI("~DhcpServerCallBack");
108 }
OnServerStatusChanged(int status)109 void DhcpServerCallBack::OnServerStatusChanged(int status)
110 {
111     DHCP_LOGI("DhcpServerCallBack OnServerStatusChanged status:%{public}d", status);
112 }
OnServerLeasesChanged(const std::string & ifname,std::vector<std::string> & leases)113 void DhcpServerCallBack::OnServerLeasesChanged(const std::string& ifname, std::vector<std::string>& leases)
114 {
115     DHCP_LOGI("DhcpServerCallBack OnServerLeasesChanged ifname:%{public}s", ifname.c_str());
116 }
OnServerSerExitChanged(const std::string & ifname)117 void DhcpServerCallBack::OnServerSerExitChanged(const std::string& ifname)
118 {
119     DHCP_LOGI("DhcpServerCallBack OnServerSerExitChanged ifname:%{public}s", ifname.c_str());
120 }
121 #ifndef OHOS_ARCH_LITE
AsObject()122 OHOS::sptr<OHOS::IRemoteObject> DhcpServerCallBack::AsObject()
123 {
124     DHCP_LOGI("DhcpServerCallBack AsObject!");
125     return nullptr;
126 }
127 #endif
RegisterCallBack(const std::string & ifname,const ServerCallBack * event)128 void DhcpServerCallBack::RegisterCallBack(const std::string& ifname, const ServerCallBack *event)
129 {
130     if (event == nullptr) {
131         DHCP_LOGE("DhcpServerCallBack event is nullptr!");
132         return;
133     }
134     callbackEvent = event;
135 }