1 /*
2 * Copyright (c) 2021-2024 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_conn_service_stub.h"
17 #include "ipc_skeleton.h"
18 #include "net_conn_constants.h"
19 #include "net_conn_types.h"
20 #include "net_manager_constants.h"
21 #include "net_mgr_log_wrapper.h"
22 #include "netmanager_base_permission.h"
23
24 namespace OHOS {
25 namespace NetManagerStandard {
26 namespace {
27 constexpr int32_t MAX_VNIC_UID_ARRAY_SIZE = 20;
28 constexpr uint32_t MAX_IFACE_NUM = 16;
29 constexpr uint32_t MAX_NET_CAP_NUM = 32;
30 constexpr uint32_t UID_FOUNDATION = 5523;
31 const std::vector<uint32_t> SYSTEM_CODE{static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_AIRPLANE_MODE),
32 static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_GLOBAL_HTTP_PROXY),
33 static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_GLOBAL_HTTP_PROXY),
34 static_cast<uint32_t>(ConnInterfaceCode::CMD_GET_IFACENAME_IDENT_MAPS),
35 static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_FACTORYRESET_NETWORK)};
36 const std::vector<uint32_t> PERMISSION_NEED_CACHE_CODES{
37 static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GETDEFAULTNETWORK),
38 static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_HASDEFAULTNET)};
39 } // namespace
40
InitNetSupplierFuncToInterfaceMap()41 void NetConnServiceStub::InitNetSupplierFuncToInterfaceMap()
42 {
43 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REG_NET_SUPPLIER)] = {
44 &NetConnServiceStub::OnRegisterNetSupplier, {Permission::CONNECTIVITY_INTERNAL}};
45 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREG_NETWORK)] = {
46 &NetConnServiceStub::OnUnregisterNetSupplier, {Permission::CONNECTIVITY_INTERNAL}};
47 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UPDATE_NET_CAPS)] = {
48 &NetConnServiceStub::OnUpdateNetCaps, {Permission::CONNECTIVITY_INTERNAL}};
49 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_NET_SUPPLIER_INFO)] = {
50 &NetConnServiceStub::OnUpdateNetSupplierInfo, {Permission::CONNECTIVITY_INTERNAL}};
51 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_NET_LINK_INFO)] = {
52 &NetConnServiceStub::OnUpdateNetLinkInfo, {Permission::CONNECTIVITY_INTERNAL}};
53 }
54
NetConnServiceStub()55 NetConnServiceStub::NetConnServiceStub()
56 {
57 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SYSTEM_READY)] = {
58 &NetConnServiceStub::OnSystemReady, {}};
59 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_CONN_CALLBACK)] = {
60 &NetConnServiceStub::OnRegisterNetConnCallback, {Permission::GET_NETWORK_INFO}};
61 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_CONN_CALLBACK_BY_SPECIFIER)] = {
62 &NetConnServiceStub::OnRegisterNetConnCallbackBySpecifier, {Permission::GET_NETWORK_INFO}};
63 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REQUEST_NET_CONNECTION)] = {
64 &NetConnServiceStub::OnRequestNetConnectionBySpecifier, {}};
65 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREGISTER_NET_CONN_CALLBACK)] = {
66 &NetConnServiceStub::OnUnregisterNetConnCallback, {Permission::GET_NETWORK_INFO}};
67 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UPDATE_NET_STATE_FOR_TEST)] = {
68 &NetConnServiceStub::OnUpdateNetStateForTest, {}};
69 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_DETECTION_RET_CALLBACK)] = {
70 &NetConnServiceStub::OnRegisterNetDetectionCallback, {}};
71 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREGISTER_NET_DETECTION_RET_CALLBACK)] = {
72 &NetConnServiceStub::OnUnRegisterNetDetectionCallback, {}};
73 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_NET_DETECTION)] = {
74 &NetConnServiceStub::OnNetDetection, {Permission::GET_NETWORK_INFO, Permission::INTERNET}};
75 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_BIND_SOCKET)] = {&NetConnServiceStub::OnBindSocket,
76 {}};
77 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_SUPPLIER_CALLBACK)] = {
78 &NetConnServiceStub::OnRegisterNetSupplierCallback, {Permission::CONNECTIVITY_INTERNAL}};
79 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_AIRPLANE_MODE)] = {
80 &NetConnServiceStub::OnSetAirplaneMode, {Permission::CONNECTIVITY_INTERNAL}};
81 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_GLOBAL_HTTP_PROXY)] = {
82 &NetConnServiceStub::OnSetGlobalHttpProxy, {Permission::CONNECTIVITY_INTERNAL}};
83 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_APP_NET)] = {&NetConnServiceStub::OnSetAppNet,
84 {Permission::INTERNET}};
85 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_INTERNET_PERMISSION)] = {
86 &NetConnServiceStub::OnSetInternetPermission, {Permission::CONNECTIVITY_INTERNAL}};
87 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_INTERFACE_CALLBACK)] = {
88 &NetConnServiceStub::OnRegisterNetInterfaceCallback, {Permission::CONNECTIVITY_INTERNAL}};
89 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREGISTER_NET_INTERFACE_CALLBACK)] = {
90 &NetConnServiceStub::OnUnregisterNetInterfaceCallback, {Permission::CONNECTIVITY_INTERNAL}};
91 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ADD_NET_ROUTE)] = {
92 &NetConnServiceStub::OnAddNetworkRoute, {Permission::CONNECTIVITY_INTERNAL}};
93 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REMOVE_NET_ROUTE)] = {
94 &NetConnServiceStub::OnRemoveNetworkRoute, {Permission::CONNECTIVITY_INTERNAL}};
95 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_IS_PREFER_CELLULAR_URL)] = {
96 &NetConnServiceStub::OnIsPreferCellularUrl, {Permission::GET_NETWORK_INFO}};
97 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_REUSE_SUPPLIER_ID)] = {
98 &NetConnServiceStub::OnSetReuseSupplierId, {Permission::CONNECTIVITY_INTERNAL}};
99 InitNetSupplierFuncToInterfaceMap();
100 InitAll();
101 }
102
InitAll()103 void NetConnServiceStub::InitAll()
104 {
105 InitInterfaceFuncToInterfaceMap();
106 InitResetNetFuncToInterfaceMap();
107 InitStaticArpToInterfaceMap();
108 InitQueryFuncToInterfaceMap();
109 InitQueryFuncToInterfaceMapExt();
110 InitVnicFuncToInterfaceMap();
111 InitVirnicFuncToInterfaceMap();
112 InitStaticIpv6ToInterfaceMap();
113 }
114
InitInterfaceFuncToInterfaceMap()115 void NetConnServiceStub::InitInterfaceFuncToInterfaceMap()
116 {
117 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ADD_NET_ADDRESS)] = {
118 &NetConnServiceStub::OnAddInterfaceAddress, {Permission::CONNECTIVITY_INTERNAL}};
119 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REMOVE_NET_ADDRESS)] = {
120 &NetConnServiceStub::OnDelInterfaceAddress, {Permission::CONNECTIVITY_INTERNAL}};
121 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_PREAIRPLANE_CALLBACK)] = {
122 &NetConnServiceStub::OnRegisterPreAirplaneCallback, {Permission::CONNECTIVITY_INTERNAL}};
123 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREGISTER_PREAIRPLANE_CALLBACK)] = {
124 &NetConnServiceStub::OnUnregisterPreAirplaneCallback, {Permission::CONNECTIVITY_INTERNAL}};
125 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UPDATE_SUPPLIER_SCORE)] = {
126 &NetConnServiceStub::OnUpdateSupplierScore, {Permission::CONNECTIVITY_INTERNAL}};
127 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_SPECIFIC_SUPPLIER_ID)] = {
128 &NetConnServiceStub::OnGetDefaultSupplierId, {Permission::CONNECTIVITY_INTERNAL}};
129 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_CLOSE_SOCKETS_UID)] = {
130 &NetConnServiceStub::OnCloseSocketsUid, {Permission::CONNECTIVITY_INTERNAL}};
131 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_APP_IS_FROZENED)] = {
132 &NetConnServiceStub::OnSetAppIsFrozened, {Permission::CONNECTIVITY_INTERNAL}};
133 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ENABLE_APP_FROZENED_CALLBACK_LIMITATION)] = {
134 &NetConnServiceStub::OnEnableAppFrozenedCallbackLimitation, {Permission::CONNECTIVITY_INTERNAL}};
135 }
136
InitResetNetFuncToInterfaceMap()137 void NetConnServiceStub::InitResetNetFuncToInterfaceMap()
138 {
139 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_FACTORYRESET_NETWORK)] = {
140 &NetConnServiceStub::OnFactoryResetNetwork, {Permission::CONNECTIVITY_INTERNAL}};
141 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_FACTORYRESET_CALLBACK)] = {
142 &NetConnServiceStub::OnRegisterNetFactoryResetCallback, {Permission::CONNECTIVITY_INTERNAL}};
143 }
144
InitStaticArpToInterfaceMap()145 void NetConnServiceStub::InitStaticArpToInterfaceMap()
146 {
147 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ADD_STATIC_ARP)] = {
148 &NetConnServiceStub::OnAddStaticArp, {Permission::CONNECTIVITY_INTERNAL}};
149 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_DEL_STATIC_ARP)] = {
150 &NetConnServiceStub::OnDelStaticArp, {Permission::CONNECTIVITY_INTERNAL}};
151 }
152
InitStaticIpv6ToInterfaceMap()153 void NetConnServiceStub::InitStaticIpv6ToInterfaceMap()
154 {
155 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ADD_STATIC_IPV6)] = {
156 &NetConnServiceStub::OnAddStaticIpv6Addr, {Permission::CONNECTIVITY_INTERNAL}};
157 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_DEL_STATIC_IPV6)] = {
158 &NetConnServiceStub::OnDelStaticIpv6Addr, {Permission::CONNECTIVITY_INTERNAL}};
159 }
160
InitProxyFuncToInterfaceMap()161 void NetConnServiceStub::InitProxyFuncToInterfaceMap()
162 {
163 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_PROXY_MODE)] = {
164 &NetConnServiceStub::OnSetProxyMode, {}};
165 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_PAC_FILE_URL)] = {
166 &NetConnServiceStub::OnSetPacFileUrl, {Permission::SET_PAC_URL}};
167 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_PAC_FILE_URL)] = {
168 &NetConnServiceStub::OnGetPacFileUrl, {}};
169 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_PROXY_MODE)] = {
170 &NetConnServiceStub::OnGetProxyMode, {}};
171 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_FIND_PAC_PROXY_FOR_URL)] = {
172 &NetConnServiceStub::OnFindProxyForURL, {}};
173 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_PAC_URL)] = {&NetConnServiceStub::OnSetPacUrl,
174 {Permission::SET_PAC_URL}};
175 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_PAC_URL)] = {&NetConnServiceStub::OnGetPacUrl,
176 {}};
177 }
178
InitQueryFuncToInterfaceMap()179 void NetConnServiceStub::InitQueryFuncToInterfaceMap()
180 {
181 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_IFACE_NAMES)] = {
182 &NetConnServiceStub::OnGetIfaceNames, {}};
183 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_IFACENAME_BY_TYPE)] = {
184 &NetConnServiceStub::OnGetIfaceNameByType, {}};
185 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_GET_IFACENAME_IDENT_MAPS)] = {
186 &NetConnServiceStub::OnGetIfaceNameIdentMaps, {Permission::GET_NETWORK_INFO}};
187 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GETDEFAULTNETWORK)] = {
188 &NetConnServiceStub::OnGetDefaultNet, {Permission::GET_NETWORK_INFO}};
189 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_HASDEFAULTNET)] = {
190 &NetConnServiceStub::OnHasDefaultNet, {Permission::GET_NETWORK_INFO}};
191 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_SPECIFIC_NET)] = {
192 &NetConnServiceStub::OnGetSpecificNet, {}};
193 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_ALL_NETS)] = {&NetConnServiceStub::OnGetAllNets,
194 {Permission::GET_NETWORK_INFO}};
195 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_SPECIFIC_UID_NET)] = {
196 &NetConnServiceStub::OnGetSpecificUidNet, {}};
197 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_CONNECTION_PROPERTIES)] = {
198 &NetConnServiceStub::OnGetConnectionProperties, {Permission::GET_NETWORK_INFO}};
199 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_NET_CAPABILITIES)] = {
200 &NetConnServiceStub::OnGetNetCapabilities, {Permission::GET_NETWORK_INFO}};
201 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_ADDRESSES_BY_NAME)] = {
202 &NetConnServiceStub::OnGetAddressesByName, {Permission::INTERNET}};
203 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_ADDRESS_BY_NAME)] = {
204 &NetConnServiceStub::OnGetAddressByName, {Permission::INTERNET}};
205 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_IS_DEFAULT_NET_METERED)] = {
206 &NetConnServiceStub::OnIsDefaultNetMetered, {Permission::GET_NETWORK_INFO}};
207 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_GLOBAL_HTTP_PROXY)] = {
208 &NetConnServiceStub::OnGetGlobalHttpProxy, {}};
209 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_DEFAULT_HTTP_PROXY)] = {
210 &NetConnServiceStub::OnGetDefaultHttpProxy, {}};
211 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_NET_ID_BY_IDENTIFIER)] = {
212 &NetConnServiceStub::OnGetNetIdByIdentifier, {}};
213 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_INTERFACE_CONFIGURATION)] = {
214 &NetConnServiceStub::OnGetNetInterfaceConfiguration, {Permission::CONNECTIVITY_INTERNAL}};
215 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_INTERFACE_IP_ADDRESS)] = {
216 &NetConnServiceStub::OnSetNetInterfaceIpAddress, {Permission::CONNECTIVITY_INTERNAL}};
217 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_INTERFACE_UP)] = {
218 &NetConnServiceStub::OnSetInterfaceUp, {Permission::CONNECTIVITY_INTERNAL}};
219 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_INTERFACE_DOWN)] = {
220 &NetConnServiceStub::OnSetInterfaceDown, {Permission::CONNECTIVITY_INTERNAL}};
221 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_SLOT_TYPE)] = {
222 &NetConnServiceStub::OnRegisterSlotType, {Permission::CONNECTIVITY_INTERNAL}};
223 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_SLOT_TYPE)] = {
224 &NetConnServiceStub::OnGetSlotType, {Permission::GET_NETWORK_INFO}};
225 InitProxyFuncToInterfaceMap();
226 }
227
InitQueryFuncToInterfaceMapExt()228 void NetConnServiceStub::InitQueryFuncToInterfaceMapExt()
229 {
230 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_SPECIFIC_NET_BY_IDENT)] = {
231 &NetConnServiceStub::OnGetSpecificNetByIdent, {}};
232 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_NET_EXT_ATTRIBUTE)] = {
233 &NetConnServiceStub::OnSetNetExtAttribute, {Permission::SET_NET_EXT_ATTRIBUTE}};
234 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_NET_EXT_ATTRIBUTE)] = {
235 &NetConnServiceStub::OnGetNetExtAttribute, {Permission::GET_NETWORK_INFO}};
236 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_QUERY_TRACEROUTE)] = {
237 &NetConnServiceStub::OnQueryTraceRoute,
238 {Permission::INTERNET, Permission::GET_NETWORK_LOCATION, Permission::ACCESS_NET_TRACE_INFO}};
239 }
240
InitVnicFuncToInterfaceMap()241 void NetConnServiceStub::InitVnicFuncToInterfaceMap()
242 {
243 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ENABLE_VNIC_NET_WORK)] = {
244 &NetConnServiceStub::OnEnableVnicNetwork, {Permission::CONNECTIVITY_INTERNAL}};
245 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_DISABLE_VNIC_NET_WORK)] = {
246 &NetConnServiceStub::OnDisableVnicNetwork, {Permission::CONNECTIVITY_INTERNAL}};
247 }
248
InitVirnicFuncToInterfaceMap()249 void NetConnServiceStub::InitVirnicFuncToInterfaceMap()
250 {
251 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ENABLE_DISTRIBUTE_CLIENT_NET)] = {
252 &NetConnServiceStub::OnEnableDistributedClientNet, {Permission::CONNECTIVITY_INTERNAL}};
253 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ENABLE_DISTRIBUTE_SERVER_NET)] = {
254 &NetConnServiceStub::OnEnableDistributedServerNet, {Permission::CONNECTIVITY_INTERNAL}};
255 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_DISABLE_DISTRIBUTE_NET)] = {
256 &NetConnServiceStub::OnDisableDistributedNet, {Permission::CONNECTIVITY_INTERNAL}};
257 }
258
~NetConnServiceStub()259 NetConnServiceStub::~NetConnServiceStub() {}
260
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)261 int32_t NetConnServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
262 MessageOption &option)
263 {
264 NETMGR_LOG_D("stub call start, code = [%{public}d]", code);
265
266 std::u16string myDescripter = NetConnServiceStub::GetDescriptor();
267 std::u16string remoteDescripter = data.ReadInterfaceToken();
268 if (myDescripter != remoteDescripter) {
269 NETMGR_LOG_E("descriptor checked fail.");
270 if (!reply.WriteInt32(NETMANAGER_ERR_DESCRIPTOR_MISMATCH)) {
271 return IPC_STUB_WRITE_PARCEL_ERR;
272 }
273 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
274 }
275
276 auto itFunc = memberFuncMap_.find(code);
277 if (itFunc == memberFuncMap_.end()) {
278 NETMGR_LOG_E("memberFuncMap not found this code! code: [%{public}d]", code);
279 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
280 }
281 auto requestFunc = itFunc->second.first;
282 if (requestFunc == nullptr) {
283 NETMGR_LOG_E("requestFunc is nullptr. code:[%{public}d]", code);
284 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
285 }
286 if (code == static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_INTERNET_PERMISSION)) {
287 // get uid should be called in this function
288 auto uid = IPCSkeleton::GetCallingUid();
289 if (uid != UID_FOUNDATION && !CheckPermission({Permission::CONNECTIVITY_INTERNAL})) {
290 if (!reply.WriteInt32(NETMANAGER_ERR_PERMISSION_DENIED)) {
291 return IPC_STUB_WRITE_PARCEL_ERR;
292 }
293 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
294 }
295 }
296
297 int32_t ret = OnRequestCheck(code, itFunc->second.second);
298 if (ret == NETMANAGER_SUCCESS) {
299 ret =(this->*requestFunc)(data, reply);
300 NETMGR_LOG_D("stub call end, code = [%{public}d]", code);
301 return ret;
302 }
303 if (!reply.WriteInt32(ret)) {
304 return IPC_STUB_WRITE_PARCEL_ERR;
305 }
306 NETMGR_LOG_D("stub default case, need check");
307 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
308 }
309
OnRequestCheck(uint32_t code,const std::set<std::string> & permissions)310 int32_t NetConnServiceStub::OnRequestCheck(uint32_t code, const std::set<std::string> &permissions)
311 {
312 if (std::find(SYSTEM_CODE.begin(), SYSTEM_CODE.end(), code) != SYSTEM_CODE.end()) {
313 if (!NetManagerPermission::IsSystemCaller()) {
314 NETMGR_LOG_E("Non-system applications use system APIs.");
315 return NETMANAGER_ERR_NOT_SYSTEM_CALL;
316 }
317 }
318
319 if (std::find(PERMISSION_NEED_CACHE_CODES.begin(), PERMISSION_NEED_CACHE_CODES.end(), code) !=
320 PERMISSION_NEED_CACHE_CODES.end()) {
321 if (CheckPermissionWithCache(permissions)) {
322 return NETMANAGER_SUCCESS;
323 }
324 } else {
325 if (CheckPermission(permissions)) {
326 return NETMANAGER_SUCCESS;
327 }
328 }
329 return NETMANAGER_ERR_PERMISSION_DENIED;
330 }
331
CheckPermission(const std::set<std::string> & permissions)332 bool NetConnServiceStub::CheckPermission(const std::set<std::string> &permissions)
333 {
334 for (const auto &permission : permissions) {
335 if (!NetManagerPermission::CheckPermission(permission)) {
336 return false;
337 }
338 }
339 return true;
340 }
341
CheckPermissionWithCache(const std::set<std::string> & permissions)342 bool NetConnServiceStub::CheckPermissionWithCache(const std::set<std::string> &permissions)
343 {
344 for (const auto &permission : permissions) {
345 if (!NetManagerPermission::CheckPermissionWithCache(permission)) {
346 return false;
347 }
348 }
349 return true;
350 }
351
OnSystemReady(MessageParcel & data,MessageParcel & reply)352 int32_t NetConnServiceStub::OnSystemReady(MessageParcel &data, MessageParcel &reply)
353 {
354 int32_t ret = SystemReady();
355 if (!reply.WriteInt32(ret)) {
356 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
357 }
358
359 return NETMANAGER_SUCCESS;
360 }
361
OnSetInternetPermission(MessageParcel & data,MessageParcel & reply)362 int32_t NetConnServiceStub::OnSetInternetPermission(MessageParcel &data, MessageParcel &reply)
363 {
364 uint32_t uid;
365 if (!data.ReadUint32(uid)) {
366 return NETMANAGER_ERR_READ_DATA_FAIL;
367 }
368
369 uint8_t allow;
370 if (!data.ReadUint8(allow)) {
371 return NETMANAGER_ERR_READ_DATA_FAIL;
372 }
373
374 int32_t ret = SetInternetPermission(uid, allow);
375 if (!reply.WriteInt32(ret)) {
376 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
377 }
378
379 return NETMANAGER_SUCCESS;
380 }
381
OnEnableVnicNetwork(MessageParcel & data,MessageParcel & reply)382 int32_t NetConnServiceStub::OnEnableVnicNetwork(MessageParcel &data, MessageParcel &reply)
383 {
384 std::set<int32_t> uids;
385 int32_t size = 0;
386 int32_t uid = 0;
387 if (!data.ReadInt32(size)) {
388 return NETMANAGER_ERR_READ_DATA_FAIL;
389 }
390
391 if (size < 0 || size > MAX_VNIC_UID_ARRAY_SIZE) {
392 NETMGR_LOG_E("vnic uids size is invalid");
393 return NETMANAGER_ERR_READ_DATA_FAIL;
394 }
395
396 for (int32_t index = 0; index < size; index++) {
397 if (!data.ReadInt32(uid)) {
398 return NETMANAGER_ERR_READ_DATA_FAIL;
399 }
400 uids.insert(uid);
401 }
402
403 sptr<NetLinkInfo> netLinkInfo = NetLinkInfo::Unmarshalling(data);
404 if (netLinkInfo == nullptr) {
405 NETMGR_LOG_E("netLinkInfo ptr is nullptr.");
406 if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
407 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
408 }
409 return NETMANAGER_ERR_LOCAL_PTR_NULL;
410 }
411
412 int32_t ret = EnableVnicNetwork(netLinkInfo, uids);
413 if (!reply.WriteInt32(ret)) {
414 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
415 }
416 return NETMANAGER_SUCCESS;
417 }
418
OnDisableVnicNetwork(MessageParcel & data,MessageParcel & reply)419 int32_t NetConnServiceStub::OnDisableVnicNetwork(MessageParcel &data, MessageParcel &reply)
420 {
421 int32_t ret = DisableVnicNetwork();
422 if (!reply.WriteInt32(ret)) {
423 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
424 }
425 return NETMANAGER_SUCCESS;
426 }
427
OnEnableDistributedClientNet(MessageParcel & data,MessageParcel & reply)428 int32_t NetConnServiceStub::OnEnableDistributedClientNet(MessageParcel &data, MessageParcel &reply)
429 {
430 std::string virnicAddr = "";
431 if (!data.ReadString(virnicAddr)) {
432 return NETMANAGER_ERR_READ_DATA_FAIL;
433 }
434 std::string iif = "";
435 if (!data.ReadString(iif)) {
436 return NETMANAGER_ERR_READ_DATA_FAIL;
437 }
438
439 int32_t ret = EnableDistributedClientNet(virnicAddr, iif);
440 if (!reply.WriteInt32(ret)) {
441 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
442 }
443 return NETMANAGER_SUCCESS;
444 }
445
OnEnableDistributedServerNet(MessageParcel & data,MessageParcel & reply)446 int32_t NetConnServiceStub::OnEnableDistributedServerNet(MessageParcel &data, MessageParcel &reply)
447 {
448 std::string iif = "";
449 if (!data.ReadString(iif)) {
450 return NETMANAGER_ERR_READ_DATA_FAIL;
451 }
452 std::string devIface = "";
453 if (!data.ReadString(devIface)) {
454 return NETMANAGER_ERR_READ_DATA_FAIL;
455 }
456 std::string dstAddr = "";
457 if (!data.ReadString(dstAddr)) {
458 return NETMANAGER_ERR_READ_DATA_FAIL;
459 }
460
461 int32_t ret = EnableDistributedServerNet(iif, devIface, dstAddr);
462 if (!reply.WriteInt32(ret)) {
463 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
464 }
465 return NETMANAGER_SUCCESS;
466 }
467
OnDisableDistributedNet(MessageParcel & data,MessageParcel & reply)468 int32_t NetConnServiceStub::OnDisableDistributedNet(MessageParcel &data, MessageParcel &reply)
469 {
470 bool isServer = false;
471 if (!data.ReadBool(isServer)) {
472 return NETMANAGER_ERR_READ_DATA_FAIL;
473 }
474
475 int32_t ret = DisableDistributedNet(isServer);
476 if (!reply.WriteInt32(ret)) {
477 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
478 }
479 return NETMANAGER_SUCCESS;
480 }
481
OnRegisterNetSupplier(MessageParcel & data,MessageParcel & reply)482 int32_t NetConnServiceStub::OnRegisterNetSupplier(MessageParcel &data, MessageParcel &reply)
483 {
484 NETMGR_LOG_D("stub processing");
485 NetBearType bearerType;
486 std::string ident;
487 std::set<NetCap> netCaps;
488
489 uint32_t type = 0;
490 if (!data.ReadUint32(type)) {
491 return NETMANAGER_ERR_READ_DATA_FAIL;
492 }
493 if (type > static_cast<uint32_t>(NetBearType::BEARER_DEFAULT)) {
494 return NETMANAGER_ERR_INTERNAL;
495 }
496 bearerType = static_cast<NetBearType>(type);
497
498 if (!data.ReadString(ident)) {
499 return NETMANAGER_ERR_READ_DATA_FAIL;
500 }
501 uint32_t size = 0;
502 uint32_t value = 0;
503 if (!data.ReadUint32(size)) {
504 return NETMANAGER_ERR_READ_DATA_FAIL;
505 }
506 size = size > MAX_NET_CAP_NUM ? MAX_NET_CAP_NUM : size;
507 for (uint32_t i = 0; i < size; ++i) {
508 if (!data.ReadUint32(value)) {
509 return NETMANAGER_ERR_READ_DATA_FAIL;
510 }
511 if (value < NET_CAPABILITY_END) {
512 netCaps.insert(static_cast<NetCap>(value));
513 }
514 }
515
516 uint32_t supplierId = 0;
517 int32_t ret = RegisterNetSupplier(bearerType, ident, netCaps, supplierId);
518 if (!reply.WriteInt32(ret)) {
519 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
520 }
521 if (ret == NETMANAGER_SUCCESS) {
522 NETMGR_LOG_D("supplierId[%{public}d].", supplierId);
523 if (!reply.WriteUint32(supplierId)) {
524 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
525 }
526 }
527 return NETMANAGER_SUCCESS;
528 }
529
OnUpdateNetCaps(MessageParcel & data,MessageParcel & reply)530 int32_t NetConnServiceStub::OnUpdateNetCaps(MessageParcel &data, MessageParcel &reply)
531 {
532 NETMGR_LOG_D("On update net caps.");
533 std::set<NetCap> netCaps;
534 uint32_t netCapsSize = 0;
535 uint32_t netCapVal = 0;
536
537 if (!data.ReadUint32(netCapsSize)) {
538 return NETMANAGER_ERR_READ_DATA_FAIL;
539 }
540 if (netCapsSize > MAX_NET_CAP_NUM) {
541 return NETMANAGER_EXT_ERR_IPC_CONNECT_STUB_FAIL;
542 }
543 for (uint32_t netCapIndex = 0; netCapIndex < netCapsSize; ++netCapIndex) {
544 if (!data.ReadUint32(netCapVal)) {
545 return NETMANAGER_ERR_READ_DATA_FAIL;
546 }
547 if (netCapVal < NET_CAPABILITY_END) {
548 netCaps.insert(static_cast<NetCap>(netCapVal));
549 }
550 }
551
552 uint32_t supplierId = 0;
553 if (!data.ReadUint32(supplierId)) {
554 return NETMANAGER_ERR_READ_DATA_FAIL;
555 }
556 int32_t ret = UpdateNetCaps(netCaps, supplierId);
557 if (!reply.WriteInt32(ret)) {
558 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
559 }
560 return NETMANAGER_SUCCESS;
561 }
562
OnUnregisterNetSupplier(MessageParcel & data,MessageParcel & reply)563 int32_t NetConnServiceStub::OnUnregisterNetSupplier(MessageParcel &data, MessageParcel &reply)
564 {
565 uint32_t supplierId;
566 if (!data.ReadUint32(supplierId)) {
567 return NETMANAGER_ERR_READ_DATA_FAIL;
568 }
569
570 int32_t ret = UnregisterNetSupplier(supplierId);
571 if (!reply.WriteInt32(ret)) {
572 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
573 }
574
575 return NETMANAGER_SUCCESS;
576 }
577
OnRegisterNetSupplierCallback(MessageParcel & data,MessageParcel & reply)578 int32_t NetConnServiceStub::OnRegisterNetSupplierCallback(MessageParcel &data, MessageParcel &reply)
579 {
580 uint32_t supplierId;
581 data.ReadUint32(supplierId);
582 sptr<IRemoteObject> remote = data.ReadRemoteObject();
583 if (remote == nullptr) {
584 NETMGR_LOG_E("Remote ptr is nullptr.");
585 if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
586 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
587 }
588 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
589 }
590
591 sptr<INetSupplierCallback> callback = iface_cast<INetSupplierCallback>(remote);
592 if (callback == nullptr) {
593 NETMGR_LOG_E("Callback ptr is nullptr.");
594 if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
595 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
596 }
597 return NETMANAGER_ERR_LOCAL_PTR_NULL;
598 }
599
600 int32_t result = RegisterNetSupplierCallback(supplierId, callback);
601 if (!reply.WriteInt32(result)) {
602 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
603 }
604 return NETMANAGER_SUCCESS;
605 }
606
OnRegisterNetConnCallback(MessageParcel & data,MessageParcel & reply)607 int32_t NetConnServiceStub::OnRegisterNetConnCallback(MessageParcel &data, MessageParcel &reply)
608 {
609 sptr<IRemoteObject> remote = data.ReadRemoteObject();
610 if (remote == nullptr) {
611 NETMGR_LOG_E("Remote ptr is nullptr.");
612 if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
613 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
614 }
615 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
616 }
617
618 sptr<INetConnCallback> callback = iface_cast<INetConnCallback>(remote);
619 if (callback == nullptr) {
620 NETMGR_LOG_E("Callback ptr is nullptr.");
621 if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
622 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
623 }
624 return NETMANAGER_ERR_LOCAL_PTR_NULL;
625 }
626
627 int32_t result = RegisterNetConnCallback(callback);
628 if (!reply.WriteInt32(result)) {
629 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
630 }
631 return NETMANAGER_SUCCESS;
632 }
633
OnRegisterNetConnCallbackBySpecifier(MessageParcel & data,MessageParcel & reply)634 int32_t NetConnServiceStub::OnRegisterNetConnCallbackBySpecifier(MessageParcel &data, MessageParcel &reply)
635 {
636 sptr<NetSpecifier> netSpecifier = NetSpecifier::Unmarshalling(data);
637 uint32_t timeoutMS = data.ReadUint32();
638 sptr<IRemoteObject> remote = data.ReadRemoteObject();
639 if (remote == nullptr) {
640 NETMGR_LOG_E("callback ptr is nullptr.");
641 if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
642 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
643 }
644 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
645 }
646
647 sptr<INetConnCallback> callback = iface_cast<INetConnCallback>(remote);
648 if (callback == nullptr) {
649 NETMGR_LOG_E("Callback ptr is nullptr.");
650 if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
651 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
652 }
653 return NETMANAGER_ERR_LOCAL_PTR_NULL;
654 }
655
656 int32_t result = RegisterNetConnCallback(netSpecifier, callback, timeoutMS);
657 if (!reply.WriteInt32(result)) {
658 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
659 }
660 return NETMANAGER_SUCCESS;
661 }
662
OnRequestNetConnectionBySpecifier(MessageParcel & data,MessageParcel & reply)663 int32_t NetConnServiceStub::OnRequestNetConnectionBySpecifier(MessageParcel &data, MessageParcel &reply)
664 {
665 sptr<NetSpecifier> netSpecifier = NetSpecifier::Unmarshalling(data);
666 uint32_t timeoutMS = data.ReadUint32();
667 sptr<IRemoteObject> remote = data.ReadRemoteObject();
668 if (remote == nullptr) {
669 NETMGR_LOG_E("Remote ptr is nullptr.");
670 if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
671 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
672 }
673 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
674 }
675
676 sptr<INetConnCallback> callback = iface_cast<INetConnCallback>(remote);
677 if (callback == nullptr) {
678 NETMGR_LOG_E("Callback ptr is nullptr.");
679 if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
680 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
681 }
682 return NETMANAGER_ERR_LOCAL_PTR_NULL;
683 }
684
685 int32_t result = RequestNetConnection(netSpecifier, callback, timeoutMS);
686 if (!reply.WriteInt32(result)) {
687 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
688 }
689 return NETMANAGER_SUCCESS;
690 }
691
OnUnregisterNetConnCallback(MessageParcel & data,MessageParcel & reply)692 int32_t NetConnServiceStub::OnUnregisterNetConnCallback(MessageParcel &data, MessageParcel &reply)
693 {
694 sptr<IRemoteObject> remote = data.ReadRemoteObject();
695 if (remote == nullptr) {
696 NETMGR_LOG_E("Remote ptr is nullptr.");
697 if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
698 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
699 }
700 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
701 }
702
703 sptr<INetConnCallback> callback = iface_cast<INetConnCallback>(remote);
704 if (callback == nullptr) {
705 NETMGR_LOG_E("Callback ptr is nullptr.");
706 if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
707 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
708 }
709 return NETMANAGER_ERR_LOCAL_PTR_NULL;
710 }
711
712 int32_t result = UnregisterNetConnCallback(callback);
713 if (!reply.WriteInt32(result)) {
714 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
715 }
716 return NETMANAGER_SUCCESS;
717 }
718
OnUpdateNetStateForTest(MessageParcel & data,MessageParcel & reply)719 int32_t NetConnServiceStub::OnUpdateNetStateForTest(MessageParcel &data, MessageParcel &reply)
720 {
721 NETMGR_LOG_D("Test NetConnServiceStub::OnUpdateNetStateForTest(), begin");
722 sptr<NetSpecifier> netSpecifier = NetSpecifier::Unmarshalling(data);
723
724 int32_t netState;
725 if (!data.ReadInt32(netState)) {
726 return NETMANAGER_ERR_READ_DATA_FAIL;
727 }
728
729 NETMGR_LOG_D("Test NetConnServiceStub::OnUpdateNetStateForTest(), netState[%{public}d]", netState);
730 int32_t result = UpdateNetStateForTest(netSpecifier, netState);
731 NETMGR_LOG_D("Test NetConnServiceStub::OnUpdateNetStateForTest(), result[%{public}d]", result);
732 if (!reply.WriteInt32(result)) {
733 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
734 }
735 return NETMANAGER_SUCCESS;
736 }
737
OnUpdateNetSupplierInfo(MessageParcel & data,MessageParcel & reply)738 int32_t NetConnServiceStub::OnUpdateNetSupplierInfo(MessageParcel &data, MessageParcel &reply)
739 {
740 NETMGR_LOG_D("OnUpdateNetSupplierInfo in.");
741 uint32_t supplierId;
742 if (!data.ReadUint32(supplierId)) {
743 NETMGR_LOG_D("fail to get supplier id.");
744 return NETMANAGER_ERR_READ_DATA_FAIL;
745 }
746
747 NETMGR_LOG_D("OnUpdateNetSupplierInfo supplierId=[%{public}d].", supplierId);
748 sptr<NetSupplierInfo> netSupplierInfo = NetSupplierInfo::Unmarshalling(data);
749 int32_t ret = UpdateNetSupplierInfo(supplierId, netSupplierInfo);
750 if (!reply.WriteInt32(ret)) {
751 NETMGR_LOG_D("fail to update net supplier info.");
752 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
753 }
754 NETMGR_LOG_D("OnUpdateNetSupplierInfo out.");
755
756 return NETMANAGER_SUCCESS;
757 }
758
OnUpdateNetLinkInfo(MessageParcel & data,MessageParcel & reply)759 int32_t NetConnServiceStub::OnUpdateNetLinkInfo(MessageParcel &data, MessageParcel &reply)
760 {
761 uint32_t supplierId;
762
763 if (!data.ReadUint32(supplierId)) {
764 return NETMANAGER_ERR_READ_DATA_FAIL;
765 }
766
767 sptr<NetLinkInfo> netLinkInfo = NetLinkInfo::Unmarshalling(data);
768
769 int32_t ret = UpdateNetLinkInfo(supplierId, netLinkInfo);
770 if (!reply.WriteInt32(ret)) {
771 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
772 }
773
774 return NETMANAGER_SUCCESS;
775 }
776
OnRegisterNetDetectionCallback(MessageParcel & data,MessageParcel & reply)777 int32_t NetConnServiceStub::OnRegisterNetDetectionCallback(MessageParcel &data, MessageParcel &reply)
778 {
779 if (!data.ContainFileDescriptors()) {
780 NETMGR_LOG_E("Execute ContainFileDescriptors failed");
781 }
782 int32_t netId = 0;
783 if (!data.ReadInt32(netId)) {
784 return NETMANAGER_ERR_READ_DATA_FAIL;
785 }
786
787 sptr<IRemoteObject> remote = data.ReadRemoteObject();
788 if (remote == nullptr) {
789 NETMGR_LOG_E("Remote ptr is nullptr.");
790 if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
791 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
792 }
793 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
794 }
795
796 sptr<INetDetectionCallback> callback = iface_cast<INetDetectionCallback>(remote);
797 if (callback == nullptr) {
798 NETMGR_LOG_E("Callback ptr is nullptr.");
799 if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
800 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
801 }
802 return NETMANAGER_ERR_LOCAL_PTR_NULL;
803 }
804
805 int32_t result = RegisterNetDetectionCallback(netId, callback);
806 if (!reply.WriteInt32(result)) {
807 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
808 }
809 return NETMANAGER_SUCCESS;
810 }
811
OnUnRegisterNetDetectionCallback(MessageParcel & data,MessageParcel & reply)812 int32_t NetConnServiceStub::OnUnRegisterNetDetectionCallback(MessageParcel &data, MessageParcel &reply)
813 {
814 if (!data.ContainFileDescriptors()) {
815 NETMGR_LOG_E("Execute ContainFileDescriptors failed");
816 }
817 int32_t netId = 0;
818 if (!data.ReadInt32(netId)) {
819 return NETMANAGER_ERR_READ_DATA_FAIL;
820 }
821
822 sptr<IRemoteObject> remote = data.ReadRemoteObject();
823 if (remote == nullptr) {
824 NETMGR_LOG_E("Remote ptr is nullptr.");
825 if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
826 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
827 }
828 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
829 }
830
831 sptr<INetDetectionCallback> callback = iface_cast<INetDetectionCallback>(remote);
832 if (callback == nullptr) {
833 NETMGR_LOG_E("Callback ptr is nullptr.");
834 if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
835 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
836 }
837 return NETMANAGER_ERR_LOCAL_PTR_NULL;
838 }
839
840 int32_t result = UnRegisterNetDetectionCallback(netId, callback);
841 if (!reply.WriteInt32(result)) {
842 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
843 }
844 return NETMANAGER_SUCCESS;
845 }
846
OnNetDetection(MessageParcel & data,MessageParcel & reply)847 int32_t NetConnServiceStub::OnNetDetection(MessageParcel &data, MessageParcel &reply)
848 {
849 int32_t netId = 0;
850 if (!data.ReadInt32(netId)) {
851 return NETMANAGER_ERR_READ_DATA_FAIL;
852 }
853 int32_t ret = NetDetection(netId);
854 if (!reply.WriteInt32(ret)) {
855 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
856 }
857 return NETMANAGER_SUCCESS;
858 }
859
OnGetIfaceNames(MessageParcel & data,MessageParcel & reply)860 int32_t NetConnServiceStub::OnGetIfaceNames(MessageParcel &data, MessageParcel &reply)
861 {
862 uint32_t netType = 0;
863 if (!data.ReadUint32(netType)) {
864 return NETMANAGER_ERR_READ_DATA_FAIL;
865 }
866 if (netType > static_cast<uint32_t>(NetBearType::BEARER_DEFAULT)) {
867 return NETMANAGER_ERR_INTERNAL;
868 }
869 NetBearType bearerType = static_cast<NetBearType>(netType);
870 std::list<std::string> ifaceNames;
871 int32_t ret = GetIfaceNames(bearerType, ifaceNames);
872 if (!reply.WriteInt32(ret)) {
873 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
874 }
875 if (ret == NETMANAGER_SUCCESS) {
876 if (!reply.WriteUint32(ifaceNames.size())) {
877 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
878 }
879
880 for (const auto &ifaceName : ifaceNames) {
881 if (!reply.WriteString(ifaceName)) {
882 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
883 }
884 }
885 }
886 return NETMANAGER_SUCCESS;
887 }
888
OnGetIfaceNameByType(MessageParcel & data,MessageParcel & reply)889 int32_t NetConnServiceStub::OnGetIfaceNameByType(MessageParcel &data, MessageParcel &reply)
890 {
891 uint32_t netType = 0;
892 if (!data.ReadUint32(netType)) {
893 return NETMANAGER_ERR_READ_DATA_FAIL;
894 }
895 if (netType > static_cast<uint32_t>(NetBearType::BEARER_DEFAULT)) {
896 return NETMANAGER_ERR_INTERNAL;
897 }
898 NetBearType bearerType = static_cast<NetBearType>(netType);
899
900 std::string ident;
901 if (!data.ReadString(ident)) {
902 return NETMANAGER_ERR_READ_DATA_FAIL;
903 }
904
905 std::string ifaceName;
906 int32_t ret = GetIfaceNameByType(bearerType, ident, ifaceName);
907 if (!reply.WriteInt32(ret)) {
908 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
909 }
910 if (ret == NETMANAGER_SUCCESS) {
911 if (!reply.WriteString(ifaceName)) {
912 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
913 }
914 }
915 return NETMANAGER_SUCCESS;
916 }
917
OnGetIfaceNameIdentMaps(MessageParcel & data,MessageParcel & reply)918 int32_t NetConnServiceStub::OnGetIfaceNameIdentMaps(MessageParcel &data, MessageParcel &reply)
919 {
920 uint32_t netType = 0;
921 if (!data.ReadUint32(netType)) {
922 return NETMANAGER_ERR_READ_DATA_FAIL;
923 }
924 if (netType > static_cast<uint32_t>(NetBearType::BEARER_DEFAULT)) {
925 return NETMANAGER_ERR_INTERNAL;
926 }
927 NetBearType bearerType = static_cast<NetBearType>(netType);
928 SafeMap<std::string, std::string> ifaceNameIdentMaps;
929 int32_t ret = GetIfaceNameIdentMaps(bearerType, ifaceNameIdentMaps);
930 if (!reply.WriteInt32(ret)) {
931 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
932 }
933 if (ret == NETMANAGER_SUCCESS) {
934 if (!reply.WriteUint32(ifaceNameIdentMaps.Size())) {
935 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
936 }
937 int32_t err = NETMANAGER_SUCCESS;
938 ifaceNameIdentMaps.Iterate([&err, &reply](const std::string &k, const std::string &v) -> void {
939 if (!reply.WriteString(k) || !reply.WriteString(v)) {
940 err = NETMANAGER_ERR_WRITE_REPLY_FAIL;
941 }
942 });
943 if (err != NETMANAGER_SUCCESS) {
944 return err;
945 }
946 }
947 return NETMANAGER_SUCCESS;
948 }
949
OnGetDefaultNet(MessageParcel & data,MessageParcel & reply)950 int32_t NetConnServiceStub::OnGetDefaultNet(MessageParcel &data, MessageParcel &reply)
951 {
952 NETMGR_LOG_D("OnGetDefaultNet Begin...");
953 int32_t netId;
954 int32_t result = GetDefaultNet(netId);
955 NETMGR_LOG_D("GetDefaultNet result is: [%{public}d]", result);
956 if (!reply.WriteInt32(result)) {
957 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
958 }
959 if (result == NETMANAGER_SUCCESS) {
960 if (!reply.WriteUint32(netId)) {
961 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
962 }
963 }
964 return NETMANAGER_SUCCESS;
965 }
966
OnHasDefaultNet(MessageParcel & data,MessageParcel & reply)967 int32_t NetConnServiceStub::OnHasDefaultNet(MessageParcel &data, MessageParcel &reply)
968 {
969 NETMGR_LOG_D("OnHasDefaultNet Begin...");
970 bool flag = false;
971 int32_t result = HasDefaultNet(flag);
972 NETMGR_LOG_D("HasDefaultNet result is: [%{public}d]", result);
973 if (!reply.WriteInt32(result)) {
974 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
975 }
976 if (result == NETMANAGER_SUCCESS) {
977 if (!reply.WriteBool(flag)) {
978 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
979 }
980 }
981 return NETMANAGER_SUCCESS;
982 }
983
OnGetSpecificNet(MessageParcel & data,MessageParcel & reply)984 int32_t NetConnServiceStub::OnGetSpecificNet(MessageParcel &data, MessageParcel &reply)
985 {
986 uint32_t type;
987 if (!data.ReadUint32(type)) {
988 return NETMANAGER_ERR_READ_DATA_FAIL;
989 }
990
991 if (type > static_cast<uint32_t>(NetBearType::BEARER_DEFAULT)) {
992 return NETMANAGER_ERR_INTERNAL;
993 }
994
995 NetBearType bearerType = static_cast<NetBearType>(type);
996
997 NETMGR_LOG_D("stub execute GetSpecificNet");
998 std::list<int32_t> netIdList;
999 int32_t ret = GetSpecificNet(bearerType, netIdList);
1000 if (!reply.WriteInt32(ret)) {
1001 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1002 }
1003 if (ret == NETMANAGER_SUCCESS) {
1004 uint32_t size = static_cast<uint32_t>(netIdList.size());
1005 size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
1006 if (!reply.WriteUint32(size)) {
1007 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1008 }
1009
1010 uint32_t index = 0;
1011 for (auto p = netIdList.begin(); p != netIdList.end(); ++p) {
1012 if (++index > MAX_IFACE_NUM) {
1013 break;
1014 }
1015 if (!reply.WriteInt32(*p)) {
1016 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1017 }
1018 }
1019 }
1020 return NETMANAGER_SUCCESS;
1021 }
1022
OnGetSpecificNetByIdent(MessageParcel & data,MessageParcel & reply)1023 int32_t NetConnServiceStub::OnGetSpecificNetByIdent(MessageParcel &data, MessageParcel &reply)
1024 {
1025 uint32_t type;
1026 std::string ident = "";
1027 if (!data.ReadUint32(type)) {
1028 return NETMANAGER_ERR_READ_DATA_FAIL;
1029 }
1030
1031 if (type > static_cast<uint32_t>(NetBearType::BEARER_DEFAULT)) {
1032 return NETMANAGER_ERR_INTERNAL;
1033 }
1034
1035 NetBearType bearerType = static_cast<NetBearType>(type);
1036 if (!data.ReadString(ident)) {
1037 return NETMANAGER_ERR_READ_DATA_FAIL;
1038 }
1039
1040 NETMGR_LOG_D("stub execute GetSpecificNetByIdent");
1041 std::list<int32_t> netIdList;
1042 int32_t ret = GetSpecificNetByIdent(bearerType, ident, netIdList);
1043 if (!reply.WriteInt32(ret)) {
1044 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1045 }
1046 if (ret == NETMANAGER_SUCCESS) {
1047 uint32_t size = static_cast<uint32_t>(netIdList.size());
1048 size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
1049 if (!reply.WriteUint32(size)) {
1050 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1051 }
1052
1053 uint32_t index = 0;
1054 for (auto p = netIdList.begin(); p != netIdList.end(); ++p) {
1055 if (++index > MAX_IFACE_NUM) {
1056 break;
1057 }
1058 if (!reply.WriteInt32(*p)) {
1059 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1060 }
1061 }
1062 }
1063 return NETMANAGER_SUCCESS;
1064 }
1065
OnGetAllNets(MessageParcel & data,MessageParcel & reply)1066 int32_t NetConnServiceStub::OnGetAllNets(MessageParcel &data, MessageParcel &reply)
1067 {
1068 NETMGR_LOG_D("stub execute GetAllNets");
1069 std::list<int32_t> netIdList;
1070 int32_t ret = GetAllNets(netIdList);
1071 if (!reply.WriteInt32(ret)) {
1072 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1073 }
1074 if (ret == NETMANAGER_SUCCESS) {
1075 uint32_t size = static_cast<uint32_t>(netIdList.size());
1076 if (!reply.WriteUint32(size)) {
1077 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1078 }
1079
1080 for (auto p = netIdList.begin(); p != netIdList.end(); ++p) {
1081 if (!reply.WriteInt32(*p)) {
1082 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1083 }
1084 }
1085 }
1086 return NETMANAGER_SUCCESS;
1087 }
1088
OnGetSpecificUidNet(MessageParcel & data,MessageParcel & reply)1089 int32_t NetConnServiceStub::OnGetSpecificUidNet(MessageParcel &data, MessageParcel &reply)
1090 {
1091 int32_t uid = 0;
1092 if (!data.ReadInt32(uid)) {
1093 return NETMANAGER_ERR_READ_DATA_FAIL;
1094 }
1095 NETMGR_LOG_D("stub execute GetSpecificUidNet");
1096
1097 int32_t netId = 0;
1098 int32_t ret = GetSpecificUidNet(uid, netId);
1099 if (!reply.WriteInt32(ret)) {
1100 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1101 }
1102 if (ret == NETMANAGER_SUCCESS) {
1103 if (!reply.WriteInt32(netId)) {
1104 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1105 }
1106 }
1107 return NETMANAGER_SUCCESS;
1108 }
1109
OnGetConnectionProperties(MessageParcel & data,MessageParcel & reply)1110 int32_t NetConnServiceStub::OnGetConnectionProperties(MessageParcel &data, MessageParcel &reply)
1111 {
1112 int32_t netId = 0;
1113 if (!data.ReadInt32(netId)) {
1114 return NETMANAGER_ERR_READ_DATA_FAIL;
1115 }
1116
1117 NETMGR_LOG_D("stub execute GetConnectionProperties");
1118 NetLinkInfo info;
1119 int32_t ret = GetConnectionProperties(netId, info);
1120 if (!reply.WriteInt32(ret)) {
1121 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1122 }
1123 if (ret == NETMANAGER_SUCCESS) {
1124 sptr<NetLinkInfo> netLinkInfo_ptr = sptr<NetLinkInfo>::MakeSptr(info);
1125 if (!NetLinkInfo::Marshalling(reply, netLinkInfo_ptr)) {
1126 NETMGR_LOG_E("proxy Marshalling failed");
1127 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1128 }
1129 }
1130 return NETMANAGER_SUCCESS;
1131 }
1132
OnGetNetCapabilities(MessageParcel & data,MessageParcel & reply)1133 int32_t NetConnServiceStub::OnGetNetCapabilities(MessageParcel &data, MessageParcel &reply)
1134 {
1135 int32_t netId = 0;
1136 if (!data.ReadInt32(netId)) {
1137 return NETMANAGER_ERR_READ_DATA_FAIL;
1138 }
1139
1140 NETMGR_LOG_D("stub execute GetNetCapabilities");
1141
1142 NetAllCapabilities netAllCap;
1143 int32_t ret = GetNetCapabilities(netId, netAllCap);
1144 if (!reply.WriteInt32(ret)) {
1145 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1146 }
1147 if (ret == NETMANAGER_SUCCESS) {
1148 if (!reply.WriteUint32(netAllCap.linkUpBandwidthKbps_) ||
1149 !reply.WriteUint32(netAllCap.linkDownBandwidthKbps_)) {
1150 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1151 }
1152 uint32_t size = netAllCap.netCaps_.size();
1153 size = size > MAX_NET_CAP_NUM ? MAX_NET_CAP_NUM : size;
1154 if (!reply.WriteUint32(size)) {
1155 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1156 }
1157 uint32_t index = 0;
1158 for (auto netCap : netAllCap.netCaps_) {
1159 if (++index > MAX_NET_CAP_NUM) {
1160 break;
1161 }
1162 if (!reply.WriteUint32(static_cast<uint32_t>(netCap))) {
1163 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1164 }
1165 }
1166
1167 size = netAllCap.bearerTypes_.size();
1168 size = size > MAX_NET_CAP_NUM ? MAX_NET_CAP_NUM : size;
1169 if (!reply.WriteUint32(size)) {
1170 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1171 }
1172 index = 0;
1173 for (auto bearerType : netAllCap.bearerTypes_) {
1174 if (++index > MAX_NET_CAP_NUM) {
1175 break;
1176 }
1177 if (!reply.WriteUint32(static_cast<uint32_t>(bearerType))) {
1178 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1179 }
1180 }
1181 }
1182 return NETMANAGER_SUCCESS;
1183 }
1184
OnGetAddressesByName(MessageParcel & data,MessageParcel & reply)1185 int32_t NetConnServiceStub::OnGetAddressesByName(MessageParcel &data, MessageParcel &reply)
1186 {
1187 std::string host;
1188 if (!data.ReadString(host)) {
1189 return NETMANAGER_ERR_READ_DATA_FAIL;
1190 }
1191 int32_t netId;
1192 if (!data.ReadInt32(netId)) {
1193 return NETMANAGER_ERR_READ_DATA_FAIL;
1194 }
1195 NETMGR_LOG_D("stub execute GetAddressesByName");
1196 std::vector<INetAddr> addrList;
1197 int32_t ret = GetAddressesByName(host, netId, addrList);
1198 if (!reply.WriteInt32(ret)) {
1199 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1200 }
1201 if (ret == NETMANAGER_SUCCESS) {
1202 uint32_t size = static_cast<uint32_t>(addrList.size());
1203 size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
1204 if (!reply.WriteUint32(size)) {
1205 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1206 }
1207 uint32_t index = 0;
1208 for (auto p = addrList.begin(); p != addrList.end(); ++p) {
1209 if (++index > MAX_IFACE_NUM) {
1210 break;
1211 }
1212 sptr<INetAddr> netaddr_ptr = (std::make_unique<INetAddr>(*p)).release();
1213 if (!INetAddr::Marshalling(reply, netaddr_ptr)) {
1214 NETMGR_LOG_E("proxy Marshalling failed");
1215 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1216 }
1217 }
1218 }
1219 return NETMANAGER_SUCCESS;
1220 }
1221
OnGetAddressByName(MessageParcel & data,MessageParcel & reply)1222 int32_t NetConnServiceStub::OnGetAddressByName(MessageParcel &data, MessageParcel &reply)
1223 {
1224 std::string host;
1225 if (!data.ReadString(host)) {
1226 return NETMANAGER_ERR_READ_DATA_FAIL;
1227 }
1228 int32_t netId;
1229 if (!data.ReadInt32(netId)) {
1230 return NETMANAGER_ERR_READ_DATA_FAIL;
1231 }
1232 NETMGR_LOG_D("stub execute GetAddressByName");
1233 INetAddr addr;
1234 int32_t ret = GetAddressByName(host, netId, addr);
1235 if (!reply.WriteInt32(ret)) {
1236 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1237 }
1238 if (ret == NETMANAGER_SUCCESS) {
1239 sptr<INetAddr> netaddr_ptr = (std::make_unique<INetAddr>(addr)).release();
1240 if (!INetAddr::Marshalling(reply, netaddr_ptr)) {
1241 NETMGR_LOG_E("proxy Marshalling failed");
1242 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1243 }
1244 }
1245 return NETMANAGER_SUCCESS;
1246 }
1247
OnBindSocket(MessageParcel & data,MessageParcel & reply)1248 int32_t NetConnServiceStub::OnBindSocket(MessageParcel &data, MessageParcel &reply)
1249 {
1250 int32_t socketFd;
1251 if (!data.ReadInt32(socketFd)) {
1252 return NETMANAGER_ERR_READ_DATA_FAIL;
1253 }
1254 int32_t netId;
1255 if (!data.ReadInt32(netId)) {
1256 return NETMANAGER_ERR_READ_DATA_FAIL;
1257 }
1258 NETMGR_LOG_D("stub execute BindSocket");
1259
1260 int32_t ret = BindSocket(socketFd, netId);
1261 if (!reply.WriteInt32(ret)) {
1262 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1263 }
1264 return NETMANAGER_SUCCESS;
1265 }
1266
OnSetAirplaneMode(MessageParcel & data,MessageParcel & reply)1267 int32_t NetConnServiceStub::OnSetAirplaneMode(MessageParcel &data, MessageParcel &reply)
1268 {
1269 bool state = false;
1270 if (!data.ReadBool(state)) {
1271 return NETMANAGER_ERR_READ_DATA_FAIL;
1272 }
1273 int32_t ret = SetAirplaneMode(state);
1274 if (!reply.WriteInt32(ret)) {
1275 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1276 }
1277 return NETMANAGER_SUCCESS;
1278 }
1279
OnIsDefaultNetMetered(MessageParcel & data,MessageParcel & reply)1280 int32_t NetConnServiceStub::OnIsDefaultNetMetered(MessageParcel &data, MessageParcel &reply)
1281 {
1282 NETMGR_LOG_D("stub execute IsDefaultNetMetered");
1283 bool flag = false;
1284 int32_t result = IsDefaultNetMetered(flag);
1285 if (!reply.WriteInt32(result)) {
1286 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1287 }
1288 if (result == NETMANAGER_SUCCESS) {
1289 if (!reply.WriteBool(flag)) {
1290 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1291 }
1292 }
1293 return NETMANAGER_SUCCESS;
1294 }
1295
OnSetGlobalHttpProxy(MessageParcel & data,MessageParcel & reply)1296 int32_t NetConnServiceStub::OnSetGlobalHttpProxy(MessageParcel &data, MessageParcel &reply)
1297 {
1298 NETMGR_LOG_D("stub execute SetGlobalHttpProxy");
1299
1300 HttpProxy httpProxy;
1301 if (!HttpProxy::Unmarshalling(data, httpProxy)) {
1302 return ERR_FLATTEN_OBJECT;
1303 }
1304 if (httpProxy.GetUserId() == 0) {
1305 httpProxy.SetUserId(PRIMARY_USER_ID);
1306 NETMGR_LOG_I("SetGlobalHttpProxy change userId");
1307 }
1308
1309 int32_t ret = SetGlobalHttpProxy(httpProxy);
1310 if (!reply.WriteInt32(ret)) {
1311 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1312 }
1313 return NETMANAGER_SUCCESS;
1314 }
1315
OnGetGlobalHttpProxy(MessageParcel & data,MessageParcel & reply)1316 int32_t NetConnServiceStub::OnGetGlobalHttpProxy(MessageParcel &data, MessageParcel &reply)
1317 {
1318 int32_t userId = -1;
1319 if (!data.ReadInt32(userId)) {
1320 NETMGR_LOG_E("ReadUserId failed");
1321 return NETMANAGER_ERR_READ_DATA_FAIL;
1322 }
1323
1324 HttpProxy httpProxy;
1325 httpProxy.SetUserId(userId);
1326 int32_t result = GetGlobalHttpProxy(httpProxy);
1327 if (!reply.WriteInt32(result)) {
1328 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1329 }
1330
1331 if (result != NETMANAGER_SUCCESS) {
1332 return result;
1333 }
1334
1335 if (!httpProxy.Marshalling(reply)) {
1336 return ERR_FLATTEN_OBJECT;
1337 }
1338 return NETMANAGER_SUCCESS;
1339 }
1340
OnGetDefaultHttpProxy(MessageParcel & data,MessageParcel & reply)1341 int32_t NetConnServiceStub::OnGetDefaultHttpProxy(MessageParcel &data, MessageParcel &reply)
1342 {
1343 NETMGR_LOG_D("stub execute OnGetDefaultHttpProxy");
1344 int32_t bindNetId = 0;
1345 if (!data.ReadInt32(bindNetId)) {
1346 return NETMANAGER_ERR_READ_DATA_FAIL;
1347 }
1348 int32_t userId = -1;
1349 if (!data.ReadInt32(userId)) {
1350 NETMGR_LOG_E("ReadUserId failed");
1351 return NETMANAGER_ERR_READ_DATA_FAIL;
1352 }
1353 HttpProxy httpProxy;
1354 httpProxy.SetUserId(userId);
1355 int32_t result = GetDefaultHttpProxy(bindNetId, httpProxy);
1356 if (!reply.WriteInt32(result)) {
1357 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1358 }
1359
1360 if (result != NETMANAGER_SUCCESS) {
1361 return result;
1362 }
1363
1364 if (!httpProxy.Marshalling(reply)) {
1365 return ERR_FLATTEN_OBJECT;
1366 }
1367 return NETMANAGER_SUCCESS;
1368 }
1369
OnQueryTraceRoute(MessageParcel & data,MessageParcel & reply)1370 int32_t NetConnServiceStub::OnQueryTraceRoute(MessageParcel &data, MessageParcel &reply)
1371 {
1372 NETMGR_LOG_D("stub execute OnQueryTraceRoute");
1373 std::string destination = "";
1374 int32_t maxJumpNumber = -1;
1375 int32_t packetsType = -1;
1376 std::string traceRouteInfo = "";
1377 if (!data.ReadString(destination)) {
1378 return NETMANAGER_ERR_READ_DATA_FAIL;
1379 }
1380 if (!data.ReadInt32(maxJumpNumber)) {
1381 return NETMANAGER_ERR_READ_DATA_FAIL;
1382 }
1383 if (!data.ReadInt32(packetsType)) {
1384 return NETMANAGER_ERR_READ_DATA_FAIL;
1385 }
1386 int32_t result = QueryTraceRoute(destination, maxJumpNumber, packetsType, traceRouteInfo);
1387 if (!reply.WriteInt32(result)) {
1388 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1389 }
1390
1391 if (result != NETMANAGER_SUCCESS) {
1392 return result;
1393 }
1394 if (!reply.WriteString(traceRouteInfo)) {
1395 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1396 }
1397 return NETMANAGER_SUCCESS;
1398 }
1399
OnGetPacUrl(MessageParcel & data,MessageParcel & reply)1400 int32_t NetConnServiceStub::OnGetPacUrl(MessageParcel &data, MessageParcel &reply)
1401 {
1402 NETMGR_LOG_D("stub execute OnGetPacUrl");
1403 std::string pacUrl = "";
1404 int32_t ret = GetPacUrl(pacUrl);
1405 if (!reply.WriteInt32(ret)) {
1406 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1407 }
1408 if (ret != NETMANAGER_SUCCESS) {
1409 return ret;
1410 }
1411 if (!reply.WriteString(pacUrl)) {
1412 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1413 }
1414
1415 return NETMANAGER_SUCCESS;
1416 }
1417
OnSetPacUrl(MessageParcel & data,MessageParcel & reply)1418 int32_t NetConnServiceStub::OnSetPacUrl(MessageParcel &data, MessageParcel &reply)
1419 {
1420 NETMGR_LOG_D("stub execute OnSetPacUrl");
1421 std::string pacUrl;
1422 if (!data.ReadString(pacUrl)) {
1423 return NETMANAGER_ERR_READ_DATA_FAIL;
1424 }
1425
1426 int32_t ret = SetPacUrl(pacUrl);
1427 if (!reply.WriteInt32(ret)) {
1428 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1429 }
1430
1431 return NETMANAGER_SUCCESS;
1432 }
1433
OnFindProxyForURL(MessageParcel & data,MessageParcel & reply)1434 int32_t NetConnServiceStub::OnFindProxyForURL(MessageParcel &data, MessageParcel &reply)
1435 {
1436 NETMGR_LOG_D("stub execute OnFindProxyForURL");
1437 std::string url = "";
1438 if (!data.ReadString(url)) {
1439 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1440 }
1441 std::string host = "";
1442 if (!data.ReadString(host)) {
1443 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1444 }
1445 std::string proxy;
1446 int32_t ret = FindProxyForURL(url, host, proxy);
1447
1448 int32_t status = 0;
1449 if (ret != 0) {
1450 proxy.clear();
1451 status = NETMANAGER_SUCCESS;
1452 }
1453 if (!reply.WriteInt32(status)) {
1454 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1455 }
1456 if (!reply.WriteString(proxy)) {
1457 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1458 }
1459 return NETMANAGER_SUCCESS;
1460 }
1461
OnGetPacFileUrl(MessageParcel & data,MessageParcel & reply)1462 int32_t NetConnServiceStub::OnGetPacFileUrl(MessageParcel &data, MessageParcel &reply)
1463 {
1464 NETMGR_LOG_D("stub execute OnGetPacFileUrl");
1465 std::string pacUrl = "";
1466 int32_t ret = GetPacFileUrl(pacUrl);
1467 if (!reply.WriteInt32(ret)) {
1468 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1469 }
1470 if (ret != NETMANAGER_SUCCESS) {
1471 return ret;
1472 }
1473 if (!reply.WriteString(pacUrl)) {
1474 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1475 }
1476 return NETMANAGER_SUCCESS;
1477 }
1478
OnGetProxyMode(MessageParcel & data,MessageParcel & reply)1479 int32_t NetConnServiceStub::OnGetProxyMode(MessageParcel &data, MessageParcel &reply)
1480 {
1481 NETMGR_LOG_D("stub execute OnGetProxyMode");
1482 OHOS::NetManagerStandard::ProxyModeType mode;
1483 int32_t ret = GetProxyMode(mode);
1484 if (!reply.WriteInt32(ret)) {
1485 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1486 }
1487 if (ret != NETMANAGER_SUCCESS) {
1488 return ret;
1489 }
1490 if (!reply.WriteInt32(mode)) {
1491 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1492 }
1493 return NETMANAGER_SUCCESS;
1494 }
1495
OnSetProxyMode(MessageParcel & data,MessageParcel & reply)1496 int32_t NetConnServiceStub::OnSetProxyMode(MessageParcel &data, MessageParcel &reply)
1497 {
1498 NETMGR_LOG_D("stub execute OnSetProxyMode");
1499 int32_t mode = -1;
1500 if (!data.ReadInt32(mode)) {
1501 return NETMANAGER_ERR_READ_DATA_FAIL;
1502 }
1503 OHOS::NetManagerStandard::ProxyModeType proxyMode;
1504 switch (mode) {
1505 case PROXY_MODE_OFF:
1506 proxyMode = PROXY_MODE_OFF;
1507 break;
1508 case PROXY_MODE_AUTO:
1509 proxyMode = PROXY_MODE_AUTO;
1510 break;
1511 default:
1512 return NETMANAGER_ERR_INVALID_PARAMETER;
1513 }
1514 int32_t ret = SetProxyMode(proxyMode);
1515 if (!reply.WriteInt32(ret)) {
1516 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1517 }
1518 return NETMANAGER_SUCCESS;
1519 }
1520
OnSetPacFileUrl(MessageParcel & data,MessageParcel & reply)1521 int32_t NetConnServiceStub::OnSetPacFileUrl(MessageParcel &data, MessageParcel &reply)
1522 {
1523 NETMGR_LOG_D("stub execute OnSetPacFileUrl");
1524 std::string pacUrl;
1525 if (!data.ReadString(pacUrl)) {
1526 return NETMANAGER_ERR_READ_DATA_FAIL;
1527 }
1528 int32_t ret = SetPacFileUrl(pacUrl);
1529 if (!reply.WriteInt32(ret)) {
1530 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1531 }
1532 return NETMANAGER_SUCCESS;
1533 }
1534
OnGetNetIdByIdentifier(MessageParcel & data,MessageParcel & reply)1535 int32_t NetConnServiceStub::OnGetNetIdByIdentifier(MessageParcel &data, MessageParcel &reply)
1536 {
1537 NETMGR_LOG_D("stub execute OnGetNetIdByIdentifier");
1538 std::string ident;
1539 if (!data.ReadString(ident)) {
1540 return NETMANAGER_ERR_READ_DATA_FAIL;
1541 }
1542
1543 std::list<int32_t> netIdList;
1544 int32_t ret = GetNetIdByIdentifier(ident, netIdList);
1545 if (!reply.WriteInt32(ret)) {
1546 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1547 }
1548
1549 if (ret == NETMANAGER_SUCCESS) {
1550 uint32_t size = static_cast<uint32_t>(netIdList.size());
1551 if (!reply.WriteUint32(size)) {
1552 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1553 }
1554 for (auto p = netIdList.begin(); p != netIdList.end(); ++p) {
1555 if (!reply.WriteInt32(*p)) {
1556 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1557 }
1558 }
1559 }
1560 return NETMANAGER_SUCCESS;
1561 }
1562
OnSetAppNet(MessageParcel & data,MessageParcel & reply)1563 int32_t NetConnServiceStub::OnSetAppNet(MessageParcel &data, MessageParcel &reply)
1564 {
1565 int32_t netId = 0;
1566 if (!data.ReadInt32(netId)) {
1567 return NETMANAGER_ERR_READ_DATA_FAIL;
1568 }
1569 int ret = SetAppNet(netId);
1570 if (!reply.WriteInt32(ret)) {
1571 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1572 }
1573 return NETMANAGER_SUCCESS;
1574 }
1575
OnRegisterNetInterfaceCallback(MessageParcel & data,MessageParcel & reply)1576 int32_t NetConnServiceStub::OnRegisterNetInterfaceCallback(MessageParcel &data, MessageParcel &reply)
1577 {
1578 sptr<IRemoteObject> remote = data.ReadRemoteObject();
1579 if (remote == nullptr) {
1580 NETMGR_LOG_E("Remote ptr is nullptr.");
1581 if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
1582 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1583 }
1584 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
1585 }
1586
1587 sptr<INetInterfaceStateCallback> callback = iface_cast<INetInterfaceStateCallback>(remote);
1588 int32_t ret = RegisterNetInterfaceCallback(callback);
1589 if (!reply.WriteInt32(ret)) {
1590 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1591 }
1592 return NETMANAGER_SUCCESS;
1593 }
1594
OnUnregisterNetInterfaceCallback(MessageParcel & data,MessageParcel & reply)1595 int32_t NetConnServiceStub::OnUnregisterNetInterfaceCallback(MessageParcel &data, MessageParcel &reply)
1596 {
1597 sptr<IRemoteObject> remote = data.ReadRemoteObject();
1598 if (remote == nullptr) {
1599 NETMGR_LOG_E("Remote ptr is nullptr.");
1600 if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
1601 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1602 }
1603 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
1604 }
1605
1606 sptr<INetInterfaceStateCallback> callback = iface_cast<INetInterfaceStateCallback>(remote);
1607 int32_t ret = UnregisterNetInterfaceCallback(callback);
1608 if (!reply.WriteInt32(ret)) {
1609 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1610 }
1611 return NETMANAGER_SUCCESS;
1612 }
1613
OnGetNetInterfaceConfiguration(MessageParcel & data,MessageParcel & reply)1614 int32_t NetConnServiceStub::OnGetNetInterfaceConfiguration(MessageParcel &data, MessageParcel &reply)
1615 {
1616 std::string iface;
1617 if (!data.ReadString(iface)) {
1618 return NETMANAGER_ERR_READ_DATA_FAIL;
1619 }
1620
1621 NetInterfaceConfiguration config;
1622 int32_t ret = GetNetInterfaceConfiguration(iface, config);
1623 if (!reply.WriteInt32(ret)) {
1624 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1625 }
1626
1627 if (ret == NETMANAGER_SUCCESS) {
1628 if (!config.Marshalling(reply)) {
1629 return ERR_FLATTEN_OBJECT;
1630 }
1631 }
1632 return NETMANAGER_SUCCESS;
1633 }
1634
OnSetNetInterfaceIpAddress(MessageParcel & data,MessageParcel & reply)1635 int32_t NetConnServiceStub::OnSetNetInterfaceIpAddress(MessageParcel &data, MessageParcel &reply)
1636 {
1637 std::string iface;
1638 if (!data.ReadString(iface)) {
1639 return NETMANAGER_ERR_READ_DATA_FAIL;
1640 }
1641
1642 std::string ipAddress;
1643 if (!data.ReadString(ipAddress)) {
1644 return NETMANAGER_ERR_READ_DATA_FAIL;
1645 }
1646
1647 int32_t ret = SetNetInterfaceIpAddress(iface, ipAddress);
1648 if (!reply.WriteInt32(ret)) {
1649 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1650 }
1651
1652 return NETMANAGER_SUCCESS;
1653 }
1654
OnSetInterfaceUp(MessageParcel & data,MessageParcel & reply)1655 int32_t NetConnServiceStub::OnSetInterfaceUp(MessageParcel &data, MessageParcel &reply)
1656 {
1657 std::string iface;
1658 if (!data.ReadString(iface)) {
1659 return NETMANAGER_ERR_READ_DATA_FAIL;
1660 }
1661
1662 int32_t ret = SetInterfaceUp(iface);
1663 if (!reply.WriteInt32(ret)) {
1664 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1665 }
1666
1667 return NETMANAGER_SUCCESS;
1668 }
1669
OnSetInterfaceDown(MessageParcel & data,MessageParcel & reply)1670 int32_t NetConnServiceStub::OnSetInterfaceDown(MessageParcel &data, MessageParcel &reply)
1671 {
1672 std::string iface;
1673 if (!data.ReadString(iface)) {
1674 return NETMANAGER_ERR_READ_DATA_FAIL;
1675 }
1676
1677 int32_t ret = SetInterfaceDown(iface);
1678 if (!reply.WriteInt32(ret)) {
1679 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1680 }
1681
1682 return NETMANAGER_SUCCESS;
1683 }
1684
OnAddNetworkRoute(MessageParcel & data,MessageParcel & reply)1685 int32_t NetConnServiceStub::OnAddNetworkRoute(MessageParcel &data, MessageParcel &reply)
1686 {
1687 int32_t netId = 0;
1688 if (!data.ReadInt32(netId)) {
1689 return NETMANAGER_ERR_READ_DATA_FAIL;
1690 }
1691
1692 std::string ifName = "";
1693 if (!data.ReadString(ifName)) {
1694 return NETMANAGER_ERR_READ_DATA_FAIL;
1695 }
1696
1697 std::string destination = "";
1698 if (!data.ReadString(destination)) {
1699 return NETMANAGER_ERR_READ_DATA_FAIL;
1700 }
1701
1702 std::string nextHop = "";
1703 if (!data.ReadString(nextHop)) {
1704 return NETMANAGER_ERR_READ_DATA_FAIL;
1705 }
1706
1707 int32_t ret = AddNetworkRoute(netId, ifName, destination, nextHop);
1708 if (!reply.WriteInt32(ret)) {
1709 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1710 }
1711
1712 return NETMANAGER_SUCCESS;
1713 }
1714
OnRemoveNetworkRoute(MessageParcel & data,MessageParcel & reply)1715 int32_t NetConnServiceStub::OnRemoveNetworkRoute(MessageParcel &data, MessageParcel &reply)
1716 {
1717 int32_t netId = 0;
1718 if (!data.ReadInt32(netId)) {
1719 return NETMANAGER_ERR_READ_DATA_FAIL;
1720 }
1721
1722 std::string ifName = "";
1723 if (!data.ReadString(ifName)) {
1724 return NETMANAGER_ERR_READ_DATA_FAIL;
1725 }
1726
1727 std::string destination = "";
1728 if (!data.ReadString(destination)) {
1729 return NETMANAGER_ERR_READ_DATA_FAIL;
1730 }
1731
1732 std::string nextHop = "";
1733 if (!data.ReadString(nextHop)) {
1734 return NETMANAGER_ERR_READ_DATA_FAIL;
1735 }
1736
1737 int32_t ret = RemoveNetworkRoute(netId, ifName, destination, nextHop);
1738 if (!reply.WriteInt32(ret)) {
1739 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1740 }
1741
1742 return NETMANAGER_SUCCESS;
1743 }
1744
OnAddInterfaceAddress(MessageParcel & data,MessageParcel & reply)1745 int32_t NetConnServiceStub::OnAddInterfaceAddress(MessageParcel &data, MessageParcel &reply)
1746 {
1747 std::string ifName = "";
1748 if (!data.ReadString(ifName)) {
1749 return NETMANAGER_ERR_READ_DATA_FAIL;
1750 }
1751
1752 std::string ipAddr = "";
1753 if (!data.ReadString(ipAddr)) {
1754 return NETMANAGER_ERR_READ_DATA_FAIL;
1755 }
1756
1757 int32_t prefixLength = 0;
1758 if (!data.ReadInt32(prefixLength)) {
1759 return NETMANAGER_ERR_READ_DATA_FAIL;
1760 }
1761
1762 int32_t ret = AddInterfaceAddress(ifName, ipAddr, prefixLength);
1763 if (!reply.WriteInt32(ret)) {
1764 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1765 }
1766
1767 return NETMANAGER_SUCCESS;
1768 }
1769
OnDelInterfaceAddress(MessageParcel & data,MessageParcel & reply)1770 int32_t NetConnServiceStub::OnDelInterfaceAddress(MessageParcel &data, MessageParcel &reply)
1771 {
1772 std::string ifName = "";
1773 if (!data.ReadString(ifName)) {
1774 return NETMANAGER_ERR_READ_DATA_FAIL;
1775 }
1776
1777 std::string ipAddr = "";
1778 if (!data.ReadString(ipAddr)) {
1779 return NETMANAGER_ERR_READ_DATA_FAIL;
1780 }
1781
1782 int32_t prefixLength = 0;
1783 if (!data.ReadInt32(prefixLength)) {
1784 return NETMANAGER_ERR_READ_DATA_FAIL;
1785 }
1786
1787 int32_t ret = DelInterfaceAddress(ifName, ipAddr, prefixLength);
1788 if (!reply.WriteInt32(ret)) {
1789 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1790 }
1791
1792 return NETMANAGER_SUCCESS;
1793 }
1794
OnAddStaticArp(MessageParcel & data,MessageParcel & reply)1795 int32_t NetConnServiceStub::OnAddStaticArp(MessageParcel &data, MessageParcel &reply)
1796 {
1797 std::string ipAddr = "";
1798 if (!data.ReadString(ipAddr)) {
1799 return NETMANAGER_ERR_READ_DATA_FAIL;
1800 }
1801
1802 std::string macAddr = "";
1803 if (!data.ReadString(macAddr)) {
1804 return NETMANAGER_ERR_READ_DATA_FAIL;
1805 }
1806
1807 std::string ifName = "";
1808 if (!data.ReadString(ifName)) {
1809 return NETMANAGER_ERR_READ_DATA_FAIL;
1810 }
1811
1812 int32_t ret = AddStaticArp(ipAddr, macAddr, ifName);
1813 if (!reply.WriteInt32(ret)) {
1814 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1815 }
1816
1817 return NETMANAGER_SUCCESS;
1818 }
1819
OnDelStaticArp(MessageParcel & data,MessageParcel & reply)1820 int32_t NetConnServiceStub::OnDelStaticArp(MessageParcel &data, MessageParcel &reply)
1821 {
1822 std::string ipAddr = "";
1823 if (!data.ReadString(ipAddr)) {
1824 return NETMANAGER_ERR_READ_DATA_FAIL;
1825 }
1826
1827 std::string macAddr = "";
1828 if (!data.ReadString(macAddr)) {
1829 return NETMANAGER_ERR_READ_DATA_FAIL;
1830 }
1831
1832 std::string ifName = "";
1833 if (!data.ReadString(ifName)) {
1834 return NETMANAGER_ERR_READ_DATA_FAIL;
1835 }
1836
1837 int32_t ret = DelStaticArp(ipAddr, macAddr, ifName);
1838 if (!reply.WriteInt32(ret)) {
1839 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1840 }
1841
1842 return NETMANAGER_SUCCESS;
1843 }
1844
OnAddStaticIpv6Addr(MessageParcel & data,MessageParcel & reply)1845 int32_t NetConnServiceStub::OnAddStaticIpv6Addr(MessageParcel &data, MessageParcel &reply)
1846 {
1847 std::string ipAddr = "";
1848 if (!data.ReadString(ipAddr)) {
1849 return NETMANAGER_ERR_READ_DATA_FAIL;
1850 }
1851
1852 std::string macAddr = "";
1853 if (!data.ReadString(macAddr)) {
1854 return NETMANAGER_ERR_READ_DATA_FAIL;
1855 }
1856
1857 std::string ifName = "";
1858 if (!data.ReadString(ifName)) {
1859 return NETMANAGER_ERR_READ_DATA_FAIL;
1860 }
1861
1862 int32_t ret = AddStaticIpv6Addr(ipAddr, macAddr, ifName);
1863 if (!reply.WriteInt32(ret)) {
1864 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1865 }
1866
1867 return NETMANAGER_SUCCESS;
1868 }
1869
OnDelStaticIpv6Addr(MessageParcel & data,MessageParcel & reply)1870 int32_t NetConnServiceStub::OnDelStaticIpv6Addr(MessageParcel &data, MessageParcel &reply)
1871 {
1872 std::string ipAddr = "";
1873 if (!data.ReadString(ipAddr)) {
1874 return NETMANAGER_ERR_READ_DATA_FAIL;
1875 }
1876
1877 std::string macAddr = "";
1878 if (!data.ReadString(macAddr)) {
1879 return NETMANAGER_ERR_READ_DATA_FAIL;
1880 }
1881
1882 std::string ifName = "";
1883 if (!data.ReadString(ifName)) {
1884 return NETMANAGER_ERR_READ_DATA_FAIL;
1885 }
1886
1887 int32_t ret = DelStaticIpv6Addr(ipAddr, macAddr, ifName);
1888 if (!reply.WriteInt32(ret)) {
1889 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1890 }
1891
1892 return NETMANAGER_SUCCESS;
1893 }
1894
OnRegisterSlotType(MessageParcel & data,MessageParcel & reply)1895 int32_t NetConnServiceStub::OnRegisterSlotType(MessageParcel &data, MessageParcel &reply)
1896 {
1897 uint32_t supplierId = 0;
1898 if (!data.ReadUint32(supplierId)) {
1899 return NETMANAGER_ERR_READ_DATA_FAIL;
1900 }
1901
1902 int32_t type = 0;
1903 if (!data.ReadInt32(type)) {
1904 return NETMANAGER_ERR_READ_DATA_FAIL;
1905 }
1906
1907 int32_t ret = RegisterSlotType(supplierId, type);
1908 if (!reply.WriteInt32(ret)) {
1909 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1910 }
1911
1912 return NETMANAGER_SUCCESS;
1913 }
1914
OnGetSlotType(MessageParcel & data,MessageParcel & reply)1915 int32_t NetConnServiceStub::OnGetSlotType(MessageParcel &data, MessageParcel &reply)
1916 {
1917 std::string type = "";
1918 int32_t ret = GetSlotType(type);
1919 if (!reply.WriteInt32(ret)) {
1920 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1921 }
1922 if (!reply.WriteString(type)) {
1923 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1924 }
1925 return NETMANAGER_SUCCESS;
1926 }
1927
OnFactoryResetNetwork(MessageParcel & data,MessageParcel & reply)1928 int32_t NetConnServiceStub::OnFactoryResetNetwork(MessageParcel &data, MessageParcel &reply)
1929 {
1930 int32_t ret = FactoryResetNetwork();
1931 if (!reply.WriteInt32(ret)) {
1932 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1933 }
1934
1935 return NETMANAGER_SUCCESS;
1936 }
1937
OnRegisterNetFactoryResetCallback(MessageParcel & data,MessageParcel & reply)1938 int32_t NetConnServiceStub::OnRegisterNetFactoryResetCallback(MessageParcel &data, MessageParcel &reply)
1939 {
1940 sptr<IRemoteObject> remote = data.ReadRemoteObject();
1941 if (remote == nullptr) {
1942 NETMGR_LOG_E("Remote ptr is nullptr.");
1943 if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
1944 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1945 }
1946 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
1947 }
1948
1949 sptr<INetFactoryResetCallback> callback = iface_cast<INetFactoryResetCallback>(remote);
1950 if (callback == nullptr) {
1951 NETMGR_LOG_E("Callback ptr is nullptr.");
1952 if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
1953 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1954 }
1955 return NETMANAGER_ERR_LOCAL_PTR_NULL;
1956 }
1957
1958 int32_t result = RegisterNetFactoryResetCallback(callback);
1959 if (!reply.WriteInt32(result)) {
1960 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1961 }
1962
1963 return NETMANAGER_SUCCESS;
1964 }
1965
OnIsPreferCellularUrl(MessageParcel & data,MessageParcel & reply)1966 int32_t NetConnServiceStub::OnIsPreferCellularUrl(MessageParcel &data, MessageParcel &reply)
1967 {
1968 std::string url;
1969 if (!data.ReadString(url)) {
1970 return NETMANAGER_ERR_READ_DATA_FAIL;
1971 }
1972 bool preferCellular = false;
1973 int32_t ret = IsPreferCellularUrl(url, preferCellular);
1974 if (!reply.WriteInt32(ret)) {
1975 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1976 }
1977 if (!reply.WriteBool(preferCellular)) {
1978 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1979 }
1980
1981 return NETMANAGER_SUCCESS;
1982 }
1983
OnGetDefaultSupplierId(MessageParcel & data,MessageParcel & reply)1984 int32_t NetConnServiceStub::OnGetDefaultSupplierId(MessageParcel &data, MessageParcel &reply)
1985 {
1986 uint32_t type = 0;
1987 std::string ident = "";
1988 uint32_t supplierId;
1989 if (!data.ReadUint32(type)) {
1990 return NETMANAGER_ERR_READ_DATA_FAIL;
1991 }
1992 if (type > static_cast<uint32_t>(NetBearType::BEARER_DEFAULT)) {
1993 return NETMANAGER_ERR_INTERNAL;
1994 }
1995 if (!data.ReadString(ident)) {
1996 return NETMANAGER_ERR_READ_DATA_FAIL;
1997 }
1998 if (!data.ReadUint32(supplierId)) {
1999 return NETMANAGER_ERR_READ_DATA_FAIL;
2000 }
2001 NetBearType bearerType = static_cast<NetBearType>(type);
2002 int32_t ret = GetDefaultSupplierId(bearerType, ident, supplierId);
2003 if (!reply.WriteInt32(ret)) {
2004 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
2005 }
2006 if (ret == NETMANAGER_SUCCESS) {
2007 NETMGR_LOG_D("supplierId[%{public}d].", supplierId);
2008 if (!reply.WriteUint32(supplierId)) {
2009 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
2010 }
2011 }
2012 return NETMANAGER_SUCCESS;
2013 }
2014
OnUpdateSupplierScore(MessageParcel & data,MessageParcel & reply)2015 int32_t NetConnServiceStub::OnUpdateSupplierScore(MessageParcel &data, MessageParcel &reply)
2016 {
2017 uint32_t supplierId;
2018 uint32_t detectionStatus = 0;
2019 if (!data.ReadUint32(supplierId)) {
2020 return NETMANAGER_ERR_READ_DATA_FAIL;
2021 }
2022 if (!data.ReadUint32(detectionStatus)) {
2023 return NETMANAGER_ERR_READ_DATA_FAIL;
2024 }
2025 int32_t ret = UpdateSupplierScore(supplierId, detectionStatus);
2026 if (!reply.WriteInt32(ret)) {
2027 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
2028 }
2029 return NETMANAGER_SUCCESS;
2030 }
2031
OnRegisterPreAirplaneCallback(MessageParcel & data,MessageParcel & reply)2032 int32_t NetConnServiceStub::OnRegisterPreAirplaneCallback(MessageParcel &data, MessageParcel &reply)
2033 {
2034 sptr<IRemoteObject> remote = data.ReadRemoteObject();
2035 if (remote == nullptr) {
2036 NETMGR_LOG_E("Remote ptr is nullptr.");
2037 if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
2038 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
2039 }
2040 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
2041 }
2042
2043 sptr<IPreAirplaneCallback> callback = iface_cast<IPreAirplaneCallback>(remote);
2044 if (callback == nullptr) {
2045 NETMGR_LOG_E("Callback ptr is nullptr.");
2046 if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
2047 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
2048 }
2049 return NETMANAGER_ERR_LOCAL_PTR_NULL;
2050 }
2051
2052 int32_t result = RegisterPreAirplaneCallback(callback);
2053 if (!reply.WriteInt32(result)) {
2054 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
2055 }
2056
2057 return NETMANAGER_SUCCESS;
2058 }
2059
OnUnregisterPreAirplaneCallback(MessageParcel & data,MessageParcel & reply)2060 int32_t NetConnServiceStub::OnUnregisterPreAirplaneCallback(MessageParcel &data, MessageParcel &reply)
2061 {
2062 sptr<IRemoteObject> remote = data.ReadRemoteObject();
2063 if (remote == nullptr) {
2064 NETMGR_LOG_E("Remote ptr is nullptr.");
2065 if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
2066 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
2067 }
2068 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
2069 }
2070
2071 sptr<IPreAirplaneCallback> callback = iface_cast<IPreAirplaneCallback>(remote);
2072 if (callback == nullptr) {
2073 NETMGR_LOG_E("Callback ptr is nullptr.");
2074 if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
2075 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
2076 }
2077 return NETMANAGER_ERR_LOCAL_PTR_NULL;
2078 }
2079
2080 int32_t result = UnregisterPreAirplaneCallback(callback);
2081 if (!reply.WriteInt32(result)) {
2082 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
2083 }
2084
2085 return NETMANAGER_SUCCESS;
2086 }
2087
OnCloseSocketsUid(MessageParcel & data,MessageParcel & reply)2088 int32_t NetConnServiceStub::OnCloseSocketsUid(MessageParcel &data, MessageParcel &reply)
2089 {
2090 int32_t netId;
2091 NETMGR_LOG_I("OnCloseSocketsUid");
2092 if (!data.ReadInt32(netId)) {
2093 NETMGR_LOG_E("ReadInt32 error.");
2094 return NETMANAGER_ERR_READ_DATA_FAIL;
2095 }
2096 uint32_t uid;
2097 if (!data.ReadUint32(uid)) {
2098 NETMGR_LOG_E("ReadUint32 error.");
2099 return NETMANAGER_ERR_READ_DATA_FAIL;
2100 }
2101
2102 int32_t ret = CloseSocketsUid(netId, uid);
2103 if (!reply.WriteInt32(ret)) {
2104 NETMGR_LOG_E("reply.WriteInt32 error");
2105 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
2106 }
2107 return NETMANAGER_SUCCESS;
2108 }
2109
OnSetAppIsFrozened(MessageParcel & data,MessageParcel & reply)2110 int32_t NetConnServiceStub::OnSetAppIsFrozened(MessageParcel &data, MessageParcel &reply)
2111 {
2112 uint32_t uid = 0;
2113 if (!data.ReadUint32(uid)) {
2114 NETMGR_LOG_E("ReadUint32 error.");
2115 return NETMANAGER_ERR_READ_DATA_FAIL;
2116 }
2117 bool isFrozened = false;
2118 if (!data.ReadBool(isFrozened)) {
2119 NETMGR_LOG_E("ReadBool error.");
2120 return NETMANAGER_ERR_READ_DATA_FAIL;
2121 }
2122
2123 int32_t ret = SetAppIsFrozened(uid, isFrozened);
2124 if (!reply.WriteInt32(ret)) {
2125 NETMGR_LOG_E("reply.WriteInt32 error");
2126 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
2127 }
2128 return NETMANAGER_SUCCESS;
2129 }
2130
OnEnableAppFrozenedCallbackLimitation(MessageParcel & data,MessageParcel & reply)2131 int32_t NetConnServiceStub::OnEnableAppFrozenedCallbackLimitation(MessageParcel &data, MessageParcel &reply)
2132 {
2133 bool flag = false;
2134 if (!data.ReadBool(flag)) {
2135 NETMGR_LOG_E("ReadBool error.");
2136 return NETMANAGER_ERR_READ_DATA_FAIL;
2137 }
2138
2139 int32_t ret = EnableAppFrozenedCallbackLimitation(flag);
2140 if (!reply.WriteInt32(ret)) {
2141 NETMGR_LOG_E("reply.WriteInt32 error");
2142 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
2143 }
2144 return NETMANAGER_SUCCESS;
2145 }
2146
OnSetReuseSupplierId(MessageParcel & data,MessageParcel & reply)2147 int32_t NetConnServiceStub::OnSetReuseSupplierId(MessageParcel &data, MessageParcel &reply)
2148 {
2149 uint32_t supplierId;
2150 uint32_t reuseSupplierId;
2151 bool isReused;
2152 if (!data.ReadUint32(supplierId)) {
2153 return NETMANAGER_ERR_READ_DATA_FAIL;
2154 }
2155 if (!data.ReadUint32(reuseSupplierId)) {
2156 return NETMANAGER_ERR_READ_DATA_FAIL;
2157 }
2158 if (!data.ReadBool(isReused)) {
2159 return NETMANAGER_ERR_READ_DATA_FAIL;
2160 }
2161 int32_t ret = SetReuseSupplierId(supplierId, reuseSupplierId, isReused);
2162 if (!reply.WriteInt32(ret)) {
2163 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
2164 }
2165 return NETMANAGER_SUCCESS;
2166 }
2167
OnGetNetExtAttribute(MessageParcel & data,MessageParcel & reply)2168 int32_t NetConnServiceStub::OnGetNetExtAttribute(MessageParcel &data, MessageParcel &reply)
2169 {
2170 NETMGR_LOG_D("Enter OnGetNetExtAttribute");
2171 int32_t netId = 0;
2172 std::string netExtAttribute = "";
2173 if (!data.ReadInt32(netId)) {
2174 return NETMANAGER_ERR_READ_DATA_FAIL;
2175 }
2176 if (!data.ReadString(netExtAttribute)) {
2177 return NETMANAGER_ERR_READ_DATA_FAIL;
2178 }
2179 int32_t ret = GetNetExtAttribute(netId, netExtAttribute);
2180 if (!reply.WriteInt32(ret)) {
2181 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
2182 }
2183 if (ret == NETMANAGER_SUCCESS) {
2184 NETMGR_LOG_D("get netExtAttribute: [%{private}s]", netExtAttribute.c_str());
2185 if (!reply.WriteString(netExtAttribute)) {
2186 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
2187 }
2188 }
2189 return NETMANAGER_SUCCESS;
2190 }
2191
OnSetNetExtAttribute(MessageParcel & data,MessageParcel & reply)2192 int32_t NetConnServiceStub::OnSetNetExtAttribute(MessageParcel &data, MessageParcel &reply)
2193 {
2194 NETMGR_LOG_D("Enter OnSetNetExtAttribute");
2195 int32_t netId = 0;
2196 std::string netExtAttribute = "";
2197 if (!data.ReadInt32(netId)) {
2198 return NETMANAGER_ERR_READ_DATA_FAIL;
2199 }
2200 if (!data.ReadString(netExtAttribute)) {
2201 return NETMANAGER_ERR_READ_DATA_FAIL;
2202 }
2203 int32_t ret = SetNetExtAttribute(netId, netExtAttribute);
2204 if (!reply.WriteInt32(ret)) {
2205 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
2206 }
2207 return NETMANAGER_SUCCESS;
2208 }
2209
2210 } // namespace NetManagerStandard
2211 } // namespace OHOS
2212