1 /*
2 * Copyright (c) 2025 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 "net_eap_callback_proxy.h"
17 #include "net_manager_constants.h"
18 #include "netmgr_ext_log_wrapper.h"
19
20 namespace OHOS {
21 namespace NetManagerStandard {
NetEapPostbackCallbackProxy(const sptr<IRemoteObject> & impl)22 NetEapPostbackCallbackProxy::NetEapPostbackCallbackProxy(const sptr<IRemoteObject> &impl)
23 : IRemoteProxy<INetEapPostbackCallback>(impl)
24 {}
25
~NetEapPostbackCallbackProxy()26 NetEapPostbackCallbackProxy::~NetEapPostbackCallbackProxy() {}
27
OnEapSupplicantPostback(NetType netType,const sptr<EapData> & eapData)28 int32_t NetEapPostbackCallbackProxy::OnEapSupplicantPostback(NetType netType, const sptr<EapData> &eapData)
29 {
30 MessageParcel dataParcel;
31 if (!WriteInterfaceToken(dataParcel)) {
32 NETMGR_EXT_LOG_E("WriteInterfaceToken failed");
33 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
34 }
35
36 if (eapData == nullptr) {
37 return NETMANAGER_ERR_LOCAL_PTR_NULL;
38 }
39
40 if (!dataParcel.WriteInt32(static_cast<int32_t>(netType))) {
41 return NETMANAGER_ERR_WRITE_DATA_FAIL;
42 }
43
44 if (!eapData->Marshalling(dataParcel)) {
45 return NETMANAGER_ERR_WRITE_DATA_FAIL;
46 }
47
48 if (eapData->eapBuffer.size() == 0) {
49 NETMGR_EXT_LOG_E("%{public}s, eapBuffer size is 0, %{public}s", __func__, eapData->PrintLogInfo().c_str());
50 return NETMANAGER_ERR_WRITE_DATA_FAIL;
51 }
52
53 sptr<IRemoteObject> remote = Remote();
54 if (remote == nullptr) {
55 NETMGR_EXT_LOG_E("Remote is null");
56 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
57 }
58 MessageParcel replyParcel;
59 MessageOption option;
60 int32_t retCode = remote->SendRequest(static_cast<uint32_t>(NetEapIpcCode::NET_EAP_POSTBACK),
61 dataParcel, replyParcel, option);
62 if (retCode != ERR_NONE) {
63 NETMGR_EXT_LOG_E("proxy SendRequest failed, retCode: [%{public}d]", retCode);
64 return retCode;
65 }
66
67 return replyParcel.ReadInt32();
68 }
69
WriteInterfaceToken(MessageParcel & data)70 bool NetEapPostbackCallbackProxy::WriteInterfaceToken(MessageParcel &data)
71 {
72 if (!data.WriteInterfaceToken(NetEapPostbackCallbackProxy::GetDescriptor())) {
73 NETMGR_EXT_LOG_E("WriteInterfaceToken failed");
74 return false;
75 }
76 return true;
77 }
78
NetRegisterEapCallbackProxy(const sptr<IRemoteObject> & impl)79 NetRegisterEapCallbackProxy::NetRegisterEapCallbackProxy(const sptr<IRemoteObject> &impl)
80 : IRemoteProxy<INetRegisterEapCallback>(impl)
81 {}
82
~NetRegisterEapCallbackProxy()83 NetRegisterEapCallbackProxy::~NetRegisterEapCallbackProxy() {}
84
OnRegisterCustomEapCallback(const std::string & regCmd)85 int32_t NetRegisterEapCallbackProxy::OnRegisterCustomEapCallback(const std::string ®Cmd)
86 {
87 MessageParcel dataParcel;
88 if (!WriteInterfaceToken(dataParcel)) {
89 NETMGR_EXT_LOG_E("WriteInterfaceToken failed");
90 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
91 }
92
93 if (!dataParcel.WriteString(regCmd)) {
94 return NETMANAGER_ERR_WRITE_DATA_FAIL;
95 }
96
97 sptr<IRemoteObject> remote = Remote();
98 if (remote == nullptr) {
99 NETMGR_EXT_LOG_E("Remote is null");
100 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
101 }
102 MessageParcel replyParcel;
103 MessageOption option;
104 int32_t retCode = remote->SendRequest(static_cast<uint32_t>(NetEapIpcCode::NET_REGISTER_CUSTOM_EAP_CALLBACK),
105 dataParcel, replyParcel, option);
106 if (retCode != ERR_NONE) {
107 NETMGR_EXT_LOG_E("proxy SendRequest failed, retCode: [%{public}d]", retCode);
108 return retCode;
109 }
110
111 return replyParcel.ReadInt32();
112 }
113
OnReplyCustomEapDataEvent(int result,const sptr<EapData> & eapData)114 int32_t NetRegisterEapCallbackProxy::OnReplyCustomEapDataEvent(int result, const sptr<EapData> &eapData)
115 {
116 MessageParcel dataParcel;
117 if (eapData == nullptr) {
118 NETMGR_EXT_LOG_E("%{public}s, eapData is nullptr", __func__);
119 return NETMANAGER_ERR_LOCAL_PTR_NULL;
120 }
121 if (!WriteInterfaceToken(dataParcel)) {
122 NETMGR_EXT_LOG_E("%{public}s, WriteInterfaceToken failed, %{public}s", __func__,
123 eapData->PrintLogInfo().c_str());
124 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
125 }
126
127 if (!dataParcel.WriteInt32(result)) {
128 NETMGR_EXT_LOG_E("%{public}s, WriteInt32 result failed, %{public}s", __func__, eapData->PrintLogInfo().c_str());
129 return NETMANAGER_ERR_WRITE_DATA_FAIL;
130 }
131
132 if (!eapData->Marshalling(dataParcel)) {
133 return NETMANAGER_ERR_WRITE_DATA_FAIL;
134 }
135
136 sptr<IRemoteObject> remote = Remote();
137 if (remote == nullptr) {
138 NETMGR_EXT_LOG_E("%{public}s, remote is nullptr, %{public}s", __func__, eapData->PrintLogInfo().c_str());
139 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
140 }
141 MessageParcel replyParcel;
142 MessageOption option;
143 int32_t retCode = remote->SendRequest(static_cast<uint32_t>(NetEapIpcCode::NET_REPLY_CUSTOM_EAPDATA),
144 dataParcel, replyParcel, option);
145 if (retCode != ERR_NONE) {
146 NETMGR_EXT_LOG_E("%{public}s, SendRequest failed, retCode: [%{public}d]", __func__, retCode);
147 return retCode;
148 }
149
150 return replyParcel.ReadInt32();
151 }
152
WriteInterfaceToken(MessageParcel & data)153 bool NetRegisterEapCallbackProxy::WriteInterfaceToken(MessageParcel &data)
154 {
155 if (!data.WriteInterfaceToken(NetRegisterEapCallbackProxy::GetDescriptor())) {
156 NETMGR_EXT_LOG_E("WriteInterfaceToken failed");
157 return false;
158 }
159 return true;
160 }
161
162 } // namespace NetManagerStandard
163 } // namespace OHOS