• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-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 #include "dhcp_client_callback_proxy.h"
16 #include "dhcp_logger.h"
17 #include "dhcp_manager_service_ipc_interface_code.h"
18 
19 DEFINE_DHCPLOG_DHCP_LABEL("DhcpClientCallbackProxy");
20 
21 namespace OHOS {
22 namespace Wifi {
DhcpClientCallbackProxy(const sptr<IRemoteObject> & impl)23 DhcpClientCallbackProxy::DhcpClientCallbackProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IDhcpClientCallBack>(impl)
24 {}
25 
~DhcpClientCallbackProxy()26 DhcpClientCallbackProxy::~DhcpClientCallbackProxy()
27 {}
28 
OnIpSuccessChanged(int status,const std::string & ifname,DhcpResult & result)29 void DhcpClientCallbackProxy::OnIpSuccessChanged(int status, const std::string& ifname, DhcpResult& result)
30 {
31     DHCP_LOGI("WifiDeviceCallBackProxy::OnIpSuccessChanged");
32     MessageOption option;
33     MessageParcel data;
34     MessageParcel reply;
35     if (!data.WriteInterfaceToken(GetDescriptor())) {
36         DHCP_LOGE("Write interface token error: %{public}s", __func__);
37         return;
38     }
39     data.WriteInt32(0);
40     data.WriteInt32(status);
41     data.WriteString(ifname);
42     data.WriteInt32(result.iptype);
43     data.WriteBool(result.isOptSuc);
44     data.WriteInt32(result.uLeaseTime);
45     data.WriteInt32(result.uAddTime);
46     data.WriteInt32(result.uGetTime);
47     data.WriteString(result.strYourCli);
48     data.WriteString(result.strServer);
49     data.WriteString(result.strSubnet);
50     data.WriteString(result.strDns1);
51     data.WriteString(result.strDns2);
52     data.WriteString(result.strRouter1);
53     data.WriteString(result.strRouter2);
54     data.WriteString(result.strVendor);
55     DHCP_LOGI("start send client request");
56     int error = Remote()->SendRequest(static_cast<uint32_t>(DhcpClientInterfaceCode::DHCP_CLIENT_CBK_CMD_IP_SUCCESS_CHANGE), data, reply, option);
57     if (error != ERR_NONE) {
58         DHCP_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
59             static_cast<int32_t>(DhcpClientInterfaceCode::DHCP_CLIENT_CBK_CMD_IP_SUCCESS_CHANGE), error);
60         return;
61     }
62     int exception = reply.ReadInt32();
63     if (exception) {
64         DHCP_LOGE("notify wifi state change failed!");
65     }
66     DHCP_LOGI("send client request success");
67 
68     return;
69 }
70 
OnIpFailChanged(int status,const std::string & ifname,const std::string & reason)71 void DhcpClientCallbackProxy::OnIpFailChanged(int status, const std::string& ifname, const std::string& reason)
72 {
73     DHCP_LOGI("DhcpClientCallbackProxy OnIpFailChanged status:%{public}d ifname:%{public}s", status, ifname.c_str());
74     MessageOption option;
75     MessageParcel data;
76     MessageParcel reply;
77     if (!data.WriteInterfaceToken(GetDescriptor())) {
78         DHCP_LOGE("Write interface token error: %{public}s", __func__);
79         return;
80     }
81     data.WriteInt32(0);
82     data.WriteInt32(status);
83     data.WriteString(ifname);
84     data.WriteString(reason);
85     int error = Remote()->SendRequest(static_cast<uint32_t>(DhcpClientInterfaceCode::DHCP_CLIENT_CBK_CMD_IP_FAIL_CHANGE), data, reply, option);
86     if (error != ERR_NONE) {
87         DHCP_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
88             static_cast<int32_t>(DhcpClientInterfaceCode::DHCP_CLIENT_CBK_CMD_IP_FAIL_CHANGE), error);
89         return;
90     }
91     int exception = reply.ReadInt32();
92     if (exception) {
93         DHCP_LOGE("notify wifi state change failed!");
94         return;
95     }
96     DHCP_LOGI("DhcpClientCallbackProxy OnIpFailChanged send client request success");
97     return;
98 }
99 
100 }  // namespace Wifi
101 }  // namespace OHOS
102