1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "softbus_client_stub.h"
17 #include "client_trans_session_manager.h"
18 #include "client_bus_center_manager.h"
19 #include "client_disc_manager.h"
20 #include "client_trans_channel_callback.h"
21 #include "ipc_skeleton.h"
22 #include "ipc_types.h"
23 #include "message_parcel.h"
24 #include "securec.h"
25 #include "softbus_def.h"
26 #include "softbus_errcode.h"
27 #include "softbus_ipc_def.h"
28 #include "softbus_log.h"
29
30 namespace OHOS {
SoftBusClientStub()31 SoftBusClientStub::SoftBusClientStub()
32 {
33 memberFuncMap_[CLIENT_DISCOVERY_DEVICE_FOUND] =
34 &SoftBusClientStub::OnDeviceFoundInner;
35 memberFuncMap_[CLIENT_DISCOVERY_SUCC] =
36 &SoftBusClientStub::OnDiscoverySuccessInner;
37 memberFuncMap_[CLIENT_DISCOVERY_FAIL] =
38 &SoftBusClientStub::OnDiscoverFailedInner;
39 memberFuncMap_[CLIENT_PUBLISH_SUCC] =
40 &SoftBusClientStub::OnPublishSuccessInner;
41 memberFuncMap_[CLIENT_PUBLISH_FAIL] =
42 &SoftBusClientStub::OnPublishFailInner;
43 memberFuncMap_[CLIENT_ON_CHANNEL_OPENED] =
44 &SoftBusClientStub::OnChannelOpenedInner;
45 memberFuncMap_[CLIENT_ON_CHANNEL_OPENFAILED] =
46 &SoftBusClientStub::OnChannelOpenFailedInner;
47 memberFuncMap_[CLIENT_ON_CHANNEL_LINKDOWN] =
48 &SoftBusClientStub::OnChannelLinkDownInner;
49 memberFuncMap_[CLIENT_ON_CHANNEL_CLOSED] =
50 &SoftBusClientStub::OnChannelClosedInner;
51 memberFuncMap_[CLIENT_ON_CHANNEL_MSGRECEIVED] =
52 &SoftBusClientStub::OnChannelMsgReceivedInner;
53 memberFuncMap_[CLIENT_ON_CHANNEL_QOSEVENT] =
54 &SoftBusClientStub::OnChannelQosEventInner;
55 memberFuncMap_[CLIENT_ON_JOIN_RESULT] =
56 &SoftBusClientStub::OnJoinLNNResultInner;
57 memberFuncMap_[CLIENT_ON_JOIN_METANODE_RESULT] =
58 &SoftBusClientStub::OnJoinMetaNodeResultInner;
59 memberFuncMap_[CLIENT_ON_LEAVE_RESULT] =
60 &SoftBusClientStub::OnLeaveLNNResultInner;
61 memberFuncMap_[CLIENT_ON_LEAVE_METANODE_RESULT] =
62 &SoftBusClientStub::OnLeaveMetaNodeResultInner;
63 memberFuncMap_[CLIENT_ON_NODE_ONLINE_STATE_CHANGED] =
64 &SoftBusClientStub::OnNodeOnlineStateChangedInner;
65 memberFuncMap_[CLIENT_ON_NODE_BASIC_INFO_CHANGED] =
66 &SoftBusClientStub::OnNodeBasicInfoChangedInner;
67 memberFuncMap_[CLIENT_ON_TIME_SYNC_RESULT] =
68 &SoftBusClientStub::OnTimeSyncResultInner;
69 memberFuncMap_[CLIENT_ON_PUBLISH_LNN_RESULT] =
70 &SoftBusClientStub::OnPublishLNNResultInner;
71 memberFuncMap_[CLIENT_ON_REFRESH_LNN_RESULT] =
72 &SoftBusClientStub::OnRefreshLNNResultInner;
73 memberFuncMap_[CLIENT_ON_REFRESH_DEVICE_FOUND] =
74 &SoftBusClientStub::OnRefreshDeviceFoundInner;
75 memberFuncMap_[CLIENT_ON_PERMISSION_CHANGE] =
76 &SoftBusClientStub::OnClientPermissonChangeInner;
77 }
78
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)79 int32_t SoftBusClientStub::OnRemoteRequest(uint32_t code,
80 MessageParcel &data, MessageParcel &reply, MessageOption &option)
81 {
82 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "SoftBusClientStub::OnReceived, code = %u", code);
83 if (data.ReadInterfaceToken() != GetDescriptor()) {
84 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "SoftBusClientStub: ReadInterfaceToken faild!");
85 return SOFTBUS_ERR;
86 }
87 auto itFunc = memberFuncMap_.find(code);
88 if (itFunc != memberFuncMap_.end()) {
89 auto memberFunc = itFunc->second;
90 if (memberFunc != nullptr) {
91 return (this->*memberFunc)(data, reply);
92 }
93 }
94 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "SoftBusClientStub: default case, need check.");
95 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
96 }
97
OnClientPermissonChangeInner(MessageParcel & data,MessageParcel & reply)98 int32_t SoftBusClientStub::OnClientPermissonChangeInner(MessageParcel &data, MessageParcel &reply)
99 {
100 int32_t state;
101 if (!data.ReadInt32(state)) {
102 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnClientPermissonChangeInner read state failed!");
103 return SOFTBUS_ERR;
104 }
105 const char *pkgName = data.ReadCString();
106 if (pkgName == nullptr) {
107 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnClientPermissonChangeInner read pkgName failed!");
108 return SOFTBUS_ERR;
109 }
110 PermissionStateChange(pkgName, state);
111 return SOFTBUS_OK;
112 }
113
OnDeviceFoundInner(MessageParcel & data,MessageParcel & reply)114 int32_t SoftBusClientStub::OnDeviceFoundInner(MessageParcel &data, MessageParcel &reply)
115 {
116 const unsigned char *info = data.ReadBuffer(sizeof(DeviceInfo));
117 if (info == nullptr) {
118 return SOFTBUS_ERR;
119 }
120 DeviceInfo deviceInfo;
121 if (memcpy_s(&deviceInfo, sizeof(DeviceInfo), info, sizeof(DeviceInfo)) != EOK) {
122 return SOFTBUS_ERR;
123 }
124 OnDeviceFound(&deviceInfo);
125 return SOFTBUS_OK;
126 }
127
OnDiscoverFailedInner(MessageParcel & data,MessageParcel & reply)128 int32_t SoftBusClientStub::OnDiscoverFailedInner(MessageParcel &data, MessageParcel &reply)
129 {
130 int subscribeId = data.ReadInt32();
131 int failReason = data.ReadInt32();
132 OnDiscoverFailed(subscribeId, failReason);
133 return SOFTBUS_OK;
134 }
135
OnDiscoverySuccessInner(MessageParcel & data,MessageParcel & reply)136 int32_t SoftBusClientStub::OnDiscoverySuccessInner(MessageParcel &data, MessageParcel &reply)
137 {
138 int subscribeId = data.ReadInt32();
139 OnDiscoverySuccess(subscribeId);
140 return SOFTBUS_OK;
141 }
142
OnPublishSuccessInner(MessageParcel & data,MessageParcel & reply)143 int32_t SoftBusClientStub::OnPublishSuccessInner(MessageParcel &data, MessageParcel &reply)
144 {
145 int publishId = data.ReadInt32();
146 OnPublishSuccess(publishId);
147 return SOFTBUS_OK;
148 }
149
OnPublishFailInner(MessageParcel & data,MessageParcel & reply)150 int32_t SoftBusClientStub::OnPublishFailInner(MessageParcel &data, MessageParcel &reply)
151 {
152 int publishId = data.ReadInt32();
153 int failReason = data.ReadInt32();
154 OnPublishFail(publishId, failReason);
155 return SOFTBUS_OK;
156 }
157
OnDeviceFound(const DeviceInfo * device)158 void SoftBusClientStub::OnDeviceFound(const DeviceInfo *device)
159 {
160 DiscClientOnDeviceFound(device);
161 }
162
OnDiscoverFailed(int subscribeId,int failReason)163 void SoftBusClientStub::OnDiscoverFailed(int subscribeId, int failReason)
164 {
165 DiscClientOnDiscoverFailed(subscribeId, (DiscoveryFailReason)failReason);
166 }
167
OnDiscoverySuccess(int subscribeId)168 void SoftBusClientStub::OnDiscoverySuccess(int subscribeId)
169 {
170 DiscClientOnDiscoverySuccess(subscribeId);
171 }
172
OnPublishSuccess(int publishId)173 void SoftBusClientStub::OnPublishSuccess(int publishId)
174 {
175 DiscClientOnPublishSuccess(publishId);
176 }
177
OnPublishFail(int publishId,int reason)178 void SoftBusClientStub::OnPublishFail(int publishId, int reason)
179 {
180 DiscClientOnPublishFail(publishId, (PublishFailReason)reason);
181 }
182
OnChannelOpened(const char * sessionName,const ChannelInfo * info)183 int32_t SoftBusClientStub::OnChannelOpened(const char *sessionName, const ChannelInfo *info)
184 {
185 return TransOnChannelOpened(sessionName, info);
186 }
187
OnChannelOpenFailed(int32_t channelId,int32_t channelType,int32_t errCode)188 int32_t SoftBusClientStub::OnChannelOpenFailed(int32_t channelId, int32_t channelType, int32_t errCode)
189 {
190 return TransOnChannelOpenFailed(channelId, channelType, errCode);
191 }
192
OnChannelLinkDown(const char * networkId,int32_t routeType)193 int32_t SoftBusClientStub::OnChannelLinkDown(const char *networkId, int32_t routeType)
194 {
195 return TransOnChannelLinkDown(networkId, routeType);
196 }
197
OnChannelClosed(int32_t channelId,int32_t channelType)198 int32_t SoftBusClientStub::OnChannelClosed(int32_t channelId, int32_t channelType)
199 {
200 return TransOnChannelClosed(channelId, channelType);
201 }
202
OnChannelMsgReceived(int32_t channelId,int32_t channelType,const void * data,uint32_t len,int32_t type)203 int32_t SoftBusClientStub::OnChannelMsgReceived(int32_t channelId, int32_t channelType, const void *data,
204 uint32_t len, int32_t type)
205 {
206 return TransOnChannelMsgReceived(channelId, channelType, data, len, static_cast<SessionPktType>(type));
207 }
208
OnChannelQosEvent(int32_t channelId,int32_t channelType,int32_t eventId,int32_t tvCount,const QosTv * tvList)209 int32_t SoftBusClientStub::OnChannelQosEvent(int32_t channelId, int32_t channelType, int32_t eventId,
210 int32_t tvCount, const QosTv *tvList)
211 {
212 return TransOnChannelQosEvent(channelId, channelType, eventId, tvCount, tvList);
213 }
214
OnChannelOpenedInner(MessageParcel & data,MessageParcel & reply)215 int32_t SoftBusClientStub::OnChannelOpenedInner(MessageParcel &data, MessageParcel &reply)
216 {
217 const char *sessionName = data.ReadCString();
218 if (sessionName == nullptr) {
219 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read sessionName failed!");
220 return SOFTBUS_ERR;
221 }
222
223 ChannelInfo channel = {0};
224 if (!data.ReadInt32(channel.channelId)) {
225 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read retCode failed!");
226 return SOFTBUS_ERR;
227 }
228 if (!data.ReadInt32(channel.channelType)) {
229 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read retCode failed!");
230 return SOFTBUS_ERR;
231 }
232 if (channel.channelType == CHANNEL_TYPE_TCP_DIRECT) {
233 channel.fd = data.ReadFileDescriptor();
234 }
235 if (!data.ReadBool(channel.isServer)) {
236 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read retCode failed!");
237 return SOFTBUS_ERR;
238 }
239 if (!data.ReadBool(channel.isEnabled)) {
240 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read retCode failed!");
241 return SOFTBUS_ERR;
242 }
243 if (!data.ReadInt32(channel.peerUid)) {
244 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read retCode failed!");
245 return SOFTBUS_ERR;
246 }
247 if (!data.ReadInt32(channel.peerPid)) {
248 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read retCode failed!");
249 return SOFTBUS_ERR;
250 }
251 channel.groupId = (char *)data.ReadCString();
252 if (channel.groupId == nullptr) {
253 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read addr failed!");
254 return SOFTBUS_ERR;
255 }
256 if (!data.ReadUint32(channel.keyLen)) {
257 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner len failed!");
258 return SOFTBUS_ERR;
259 }
260 channel.sessionKey = (char *)data.ReadRawData(channel.keyLen);
261 if (channel.sessionKey == nullptr) {
262 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read addr failed!");
263 return SOFTBUS_ERR;
264 }
265 channel.peerSessionName = (char *)data.ReadCString();
266 if (channel.peerSessionName == nullptr) {
267 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read addr failed!");
268 return SOFTBUS_ERR;
269 }
270 channel.peerDeviceId = (char *)data.ReadCString();
271 if (channel.peerDeviceId == nullptr) {
272 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read addr failed!");
273 return SOFTBUS_ERR;
274 }
275 data.ReadInt32(channel.businessType);
276 if (channel.channelType == CHANNEL_TYPE_UDP) {
277 channel.myIp = (char *)data.ReadCString();
278 data.ReadInt32(channel.streamType);
279 data.ReadBool(channel.isUdpFile);
280 if (!channel.isServer) {
281 data.ReadInt32(channel.peerPort);
282 channel.peerIp = (char *)data.ReadCString();
283 }
284 }
285 data.ReadInt32(channel.routeType);
286 data.ReadInt32(channel.encrypt);
287 data.ReadInt32(channel.algorithm);
288 data.ReadInt32(channel.crc);
289
290 int ret = OnChannelOpened(sessionName, &channel);
291 bool res = reply.WriteInt32(ret);
292 if (!res) {
293 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner write reply failed!");
294 return SOFTBUS_ERR;
295 }
296 return SOFTBUS_OK;
297 }
298
OnChannelOpenFailedInner(MessageParcel & data,MessageParcel & reply)299 int32_t SoftBusClientStub::OnChannelOpenFailedInner(MessageParcel &data, MessageParcel &reply)
300 {
301 int32_t channelId;
302 if (!data.ReadInt32(channelId)) {
303 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenFailedInner read channel id failed!");
304 return SOFTBUS_ERR;
305 }
306
307 int32_t channelType;
308 if (!data.ReadInt32(channelType)) {
309 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenFailedInner read channel type failed!");
310 return SOFTBUS_ERR;
311 }
312
313 int32_t errCode;
314 if (!data.ReadInt32(errCode)) {
315 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenFailedInner read channel type failed!");
316 return SOFTBUS_ERR;
317 }
318
319 int32_t ret = OnChannelOpenFailed(channelId, channelType, errCode);
320 if (ret != SOFTBUS_OK) {
321 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenFailed failed! ret=%d.", ret);
322 }
323 return ret;
324 }
325
OnChannelLinkDownInner(MessageParcel & data,MessageParcel & reply)326 int32_t SoftBusClientStub::OnChannelLinkDownInner(MessageParcel &data, MessageParcel &reply)
327 {
328 const char *networkId = data.ReadCString();
329 if (networkId == nullptr) {
330 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelLinkDownInner read networkId failed!");
331 return SOFTBUS_ERR;
332 }
333 int32_t routeType;
334 if (!data.ReadInt32(routeType)) {
335 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelLinkDownInner read routeType failed!");
336 return SOFTBUS_ERR;
337 }
338 int32_t retReply = OnChannelLinkDown(networkId, routeType);
339 if (!reply.WriteInt32(retReply)) {
340 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelLinkDownInner write reply failed!");
341 return SOFTBUS_ERR;
342 }
343 return SOFTBUS_OK;
344 }
345
OnChannelClosedInner(MessageParcel & data,MessageParcel & reply)346 int32_t SoftBusClientStub::OnChannelClosedInner(MessageParcel &data, MessageParcel &reply)
347 {
348 int32_t channelId;
349 if (!data.ReadInt32(channelId)) {
350 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelClosedInner read channel id failed!");
351 return SOFTBUS_ERR;
352 }
353
354 int32_t channelType;
355 if (!data.ReadInt32(channelType)) {
356 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenFailedInner read channel type failed!");
357 return SOFTBUS_ERR;
358 }
359
360 int ret = OnChannelClosed(channelId, channelType);
361 bool res = reply.WriteInt32(ret);
362 if (!res) {
363 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelClosedInner write reply failed!");
364 return SOFTBUS_ERR;
365 }
366 return SOFTBUS_OK;
367 }
368
OnChannelMsgReceivedInner(MessageParcel & data,MessageParcel & reply)369 int32_t SoftBusClientStub::OnChannelMsgReceivedInner(MessageParcel &data, MessageParcel &reply)
370 {
371 int32_t channelId;
372 if (!data.ReadInt32(channelId)) {
373 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelMsgReceivedInner read channel id failed!");
374 return SOFTBUS_ERR;
375 }
376 int32_t channelType;
377 if (!data.ReadInt32(channelType)) {
378 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelMsgReceivedInner read channel type failed!");
379 return SOFTBUS_ERR;
380 }
381 uint32_t len;
382 if (!data.ReadUint32(len)) {
383 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelMsgReceivedInner read data len failed!");
384 return SOFTBUS_ERR;
385 }
386 char *dataInfo = (char *)data.ReadRawData(len);
387 if (dataInfo == nullptr) {
388 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read dataInfo failed!");
389 return SOFTBUS_ERR;
390 }
391 int32_t type;
392 if (!data.ReadInt32(type)) {
393 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelMsgReceivedInner read type failed!");
394 return SOFTBUS_ERR;
395 }
396 int ret = OnChannelMsgReceived(channelId, channelType, dataInfo, len, type);
397 bool res = reply.WriteInt32(ret);
398 if (!res) {
399 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelMsgReceivedInner write reply failed!");
400 return SOFTBUS_ERR;
401 }
402 return SOFTBUS_OK;
403 }
404
OnChannelQosEventInner(MessageParcel & data,MessageParcel & reply)405 int32_t SoftBusClientStub::OnChannelQosEventInner(MessageParcel &data, MessageParcel &reply)
406 {
407 SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_INFO, "OnChannelQosEventInner");
408 int32_t channelId;
409 if (!data.ReadInt32(channelId)) {
410 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelQosEventInner read channel id failed!");
411 return SOFTBUS_ERR;
412 }
413 int32_t channelType;
414 if (!data.ReadInt32(channelType)) {
415 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelQosEventInner read channel type failed!");
416 return SOFTBUS_ERR;
417 }
418 int32_t eventId;
419 if (!data.ReadInt32(eventId)) {
420 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelQosEventInner read eventId failed!");
421 return SOFTBUS_ERR;
422 }
423 int32_t tvCount;
424 if (!data.ReadInt32(tvCount)) {
425 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelQosEventInner read tv count failed!");
426 return SOFTBUS_ERR;
427 }
428 QosTv *tvList = (QosTv *)data.ReadRawData(sizeof(QosTv) * tvCount);
429 if (tvList == nullptr) {
430 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelQosEventInner read tv list failed!");
431 return SOFTBUS_ERR;
432 }
433 int ret = OnChannelQosEvent(channelId, channelType, eventId, tvCount, tvList);
434 bool res = reply.WriteInt32(ret);
435 if (!res) {
436 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelQosEventInner write reply failed!");
437 return SOFTBUS_ERR;
438 }
439 return SOFTBUS_OK;
440 }
441
OnJoinLNNResultInner(MessageParcel & data,MessageParcel & reply)442 int32_t SoftBusClientStub::OnJoinLNNResultInner(MessageParcel &data, MessageParcel &reply)
443 {
444 uint32_t addrTypeLen;
445 if (!data.ReadUint32(addrTypeLen) || addrTypeLen != sizeof(ConnectionAddr)) {
446 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR,
447 "OnJoinLNNResultInner read addr type length:%d failed!", addrTypeLen);
448 return SOFTBUS_ERR;
449 }
450 void *addr = (void *)data.ReadRawData(addrTypeLen);
451 if (addr == nullptr) {
452 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnJoinLNNResultInner read addr failed!");
453 return SOFTBUS_ERR;
454 }
455 int32_t retCode;
456 if (!data.ReadInt32(retCode)) {
457 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnJoinLNNResultInner read retCode failed!");
458 return SOFTBUS_ERR;
459 }
460 const char *networkId = nullptr;
461 if (retCode == 0) {
462 networkId = data.ReadCString();
463 if (networkId == nullptr) {
464 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnJoinLNNResultInner read networkId failed!");
465 return SOFTBUS_ERR;
466 }
467 }
468 int32_t retReply = OnJoinLNNResult(addr, addrTypeLen, networkId, retCode);
469 if (retReply != SOFTBUS_OK) {
470 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnJoinLNNResultInner notify join result failed!");
471 }
472 return SOFTBUS_OK;
473 }
474
OnJoinMetaNodeResultInner(MessageParcel & data,MessageParcel & reply)475 int32_t SoftBusClientStub::OnJoinMetaNodeResultInner(MessageParcel &data, MessageParcel &reply)
476 {
477 uint32_t addrTypeLen;
478 if (!data.ReadUint32(addrTypeLen) || addrTypeLen != sizeof(ConnectionAddr)) {
479 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR,
480 "OnJoinMetaNodeResultInner read addrTypeLen:%d failed!", addrTypeLen);
481 return SOFTBUS_ERR;
482 }
483 void *addr = (void *)data.ReadRawData(addrTypeLen);
484 if (addr == nullptr) {
485 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnJoinMetaNodeResultInner read addr failed!");
486 return SOFTBUS_ERR;
487 }
488 int32_t retCode;
489 if (!data.ReadInt32(retCode)) {
490 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnJoinMetaNodeResultInner read retCode failed!");
491 return SOFTBUS_ERR;
492 }
493 const char *networkId = nullptr;
494 if (retCode == 0) {
495 networkId = data.ReadCString();
496 if (networkId == nullptr) {
497 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnJoinMetaNodeResultInner read networkId failed!");
498 return SOFTBUS_ERR;
499 }
500 }
501 int32_t retReply = OnJoinMetaNodeResult(addr, addrTypeLen, networkId, retCode);
502 if (retReply != SOFTBUS_OK) {
503 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnJoinMetaNodeResultInner notify join result failed!");
504 }
505 return SOFTBUS_OK;
506 }
507
OnLeaveLNNResultInner(MessageParcel & data,MessageParcel & reply)508 int32_t SoftBusClientStub::OnLeaveLNNResultInner(MessageParcel &data, MessageParcel &reply)
509 {
510 const char *networkId = data.ReadCString();
511 if (networkId == nullptr) {
512 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnLeaveLNNResultInner read networkId failed!");
513 return SOFTBUS_ERR;
514 }
515 int32_t retCode;
516 if (!data.ReadInt32(retCode)) {
517 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnLeaveLNNResultInner read retCode failed!");
518 return SOFTBUS_ERR;
519 }
520 int32_t retReply = OnLeaveLNNResult(networkId, retCode);
521 if (retReply != SOFTBUS_OK) {
522 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnLeaveLNNResultInner notify leave result failed!");
523 }
524 return SOFTBUS_OK;
525 }
526
OnLeaveMetaNodeResultInner(MessageParcel & data,MessageParcel & reply)527 int32_t SoftBusClientStub::OnLeaveMetaNodeResultInner(MessageParcel &data, MessageParcel &reply)
528 {
529 const char *networkId = data.ReadCString();
530 if (networkId == nullptr) {
531 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnLeaveMetaNodeResultInner read networkId failed!");
532 return SOFTBUS_ERR;
533 }
534 int32_t retCode;
535 if (!data.ReadInt32(retCode)) {
536 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnLeaveMetaNodeResultInner read retCode failed!");
537 return SOFTBUS_ERR;
538 }
539 int32_t retReply = OnLeaveMetaNodeResult(networkId, retCode);
540 if (retReply != SOFTBUS_OK) {
541 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnLeaveMetaNodeResultInner notify leave result failed!");
542 }
543 return SOFTBUS_OK;
544 }
545
OnNodeOnlineStateChangedInner(MessageParcel & data,MessageParcel & reply)546 int32_t SoftBusClientStub::OnNodeOnlineStateChangedInner(MessageParcel &data, MessageParcel &reply)
547 {
548 bool isOnline = false;
549 if (!data.ReadBool(isOnline)) {
550 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnNodeOnlineStateChangedInner read online state failed!");
551 return SOFTBUS_ERR;
552 }
553 uint32_t infoTypeLen;
554 if (!data.ReadUint32(infoTypeLen) || infoTypeLen != sizeof(NodeBasicInfo)) {
555 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR,
556 "OnNodeOnlineStateChangedInner read info type length:%d failed!", infoTypeLen);
557 return SOFTBUS_ERR;
558 }
559 void *info = (void *)data.ReadRawData(infoTypeLen);
560 if (info == nullptr) {
561 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnNodeOnlineStateChangedInner read basic info failed!");
562 return SOFTBUS_ERR;
563 }
564 int32_t retReply = OnNodeOnlineStateChanged(isOnline, info, infoTypeLen);
565 if (!reply.WriteInt32(retReply)) {
566 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnNodeOnlineStateChangedInner write reply failed!");
567 return SOFTBUS_ERR;
568 }
569 return SOFTBUS_OK;
570 }
571
OnNodeBasicInfoChangedInner(MessageParcel & data,MessageParcel & reply)572 int32_t SoftBusClientStub::OnNodeBasicInfoChangedInner(MessageParcel &data, MessageParcel &reply)
573 {
574 int32_t type;
575 if (!data.ReadInt32(type)) {
576 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnNodeBasicInfoChangedInner read type failed!");
577 return SOFTBUS_ERR;
578 }
579 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "OnNodeBasicInfoChangedInner type %d", type);
580 uint32_t infoTypeLen;
581 if (!data.ReadUint32(infoTypeLen) || infoTypeLen != sizeof(NodeBasicInfo)) {
582 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR,
583 "OnNodeBasicInfoChangedInner read info type length:%d failed!", infoTypeLen);
584 return SOFTBUS_ERR;
585 }
586 void *info = (void *)data.ReadRawData(infoTypeLen);
587 if (info == nullptr) {
588 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnNodeBasicInfoChangedInner read basic info failed!");
589 return SOFTBUS_ERR;
590 }
591 int32_t retReply = OnNodeBasicInfoChanged(info, infoTypeLen, type);
592 if (!reply.WriteInt32(retReply)) {
593 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnNodeBasicInfoChangedInner write reply failed!");
594 return SOFTBUS_ERR;
595 }
596 return SOFTBUS_OK;
597 }
598
OnTimeSyncResultInner(MessageParcel & data,MessageParcel & reply)599 int32_t SoftBusClientStub::OnTimeSyncResultInner(MessageParcel &data, MessageParcel &reply)
600 {
601 uint32_t infoTypeLen;
602 if (!data.ReadUint32(infoTypeLen) || infoTypeLen != sizeof(TimeSyncResultInfo)) {
603 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR,
604 "OnTimeSyncResultInner read info length:%d failed!", infoTypeLen);
605 return SOFTBUS_ERR;
606 }
607 void *info = (void *)data.ReadRawData(infoTypeLen);
608 if (info == nullptr) {
609 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnTimeSyncResultInner read info failed!");
610 return SOFTBUS_ERR;
611 }
612 int32_t retCode;
613 if (!data.ReadInt32(retCode)) {
614 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnTimeSyncResultInner read retCode failed!");
615 return SOFTBUS_ERR;
616 }
617
618 int32_t retReply = OnTimeSyncResult(info, infoTypeLen, retCode);
619 if (!reply.WriteInt32(retReply)) {
620 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnTimeSyncResultInner write reply failed!");
621 return SOFTBUS_ERR;
622 }
623 return SOFTBUS_OK;
624 }
625
OnPublishLNNResultInner(MessageParcel & data,MessageParcel & reply)626 int32_t SoftBusClientStub::OnPublishLNNResultInner(MessageParcel &data, MessageParcel &reply)
627 {
628 int32_t publishId;
629 if (!data.ReadInt32(publishId)) {
630 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnPublishLNNResultInner read publishId failed!");
631 return SOFTBUS_ERR;
632 }
633 int32_t reason;
634 if (!data.ReadInt32(reason)) {
635 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnPublishLNNResultInner read reason failed!");
636 return SOFTBUS_ERR;
637 }
638
639 OnPublishLNNResult(publishId, reason);
640 return SOFTBUS_OK;
641 }
642
OnRefreshLNNResultInner(MessageParcel & data,MessageParcel & reply)643 int32_t SoftBusClientStub::OnRefreshLNNResultInner(MessageParcel &data, MessageParcel &reply)
644 {
645 int32_t refreshId;
646 if (!data.ReadInt32(refreshId)) {
647 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnRefreshLNNResultInner read publishId failed!");
648 return SOFTBUS_ERR;
649 }
650 int32_t reason;
651 if (!data.ReadInt32(reason)) {
652 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnRefreshLNNResultInner read reason failed!");
653 return SOFTBUS_ERR;
654 }
655
656 OnRefreshLNNResult(refreshId, reason);
657 return SOFTBUS_OK;
658 }
659
OnRefreshDeviceFoundInner(MessageParcel & data,MessageParcel & reply)660 int32_t SoftBusClientStub::OnRefreshDeviceFoundInner(MessageParcel &data, MessageParcel &reply)
661 {
662 uint32_t deviceLen;
663 if (!data.ReadUint32(deviceLen) || deviceLen != sizeof(DeviceInfo)) {
664 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR,
665 "OnRefreshDeviceFoundInner read info length:%d failed!", deviceLen);
666 return SOFTBUS_ERR;
667 }
668 void *device = (void *)data.ReadRawData(deviceLen);
669 if (device == nullptr) {
670 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnRefreshDeviceFoundInner read info failed!");
671 return SOFTBUS_ERR;
672 }
673 OnRefreshDeviceFound(device, deviceLen);
674 return SOFTBUS_OK;
675 }
676
OnJoinLNNResult(void * addr,uint32_t addrTypeLen,const char * networkId,int retCode)677 int32_t SoftBusClientStub::OnJoinLNNResult(void *addr, uint32_t addrTypeLen, const char *networkId, int retCode)
678 {
679 (void)addrTypeLen;
680 return LnnOnJoinResult(addr, networkId, retCode);
681 }
682
OnJoinMetaNodeResult(void * addr,uint32_t addrTypeLen,const char * networkId,int retCode)683 int32_t SoftBusClientStub::OnJoinMetaNodeResult(void *addr, uint32_t addrTypeLen, const char *networkId, int retCode)
684 {
685 (void)addrTypeLen;
686 return MetaNodeOnJoinResult(addr, networkId, retCode);
687 }
688
OnLeaveLNNResult(const char * networkId,int retCode)689 int32_t SoftBusClientStub::OnLeaveLNNResult(const char *networkId, int retCode)
690 {
691 return LnnOnLeaveResult(networkId, retCode);
692 }
693
OnLeaveMetaNodeResult(const char * networkId,int retCode)694 int32_t SoftBusClientStub::OnLeaveMetaNodeResult(const char *networkId, int retCode)
695 {
696 return MetaNodeOnLeaveResult(networkId, retCode);
697 }
698
OnNodeOnlineStateChanged(bool isOnline,void * info,uint32_t infoTypeLen)699 int32_t SoftBusClientStub::OnNodeOnlineStateChanged(bool isOnline, void *info, uint32_t infoTypeLen)
700 {
701 (void)infoTypeLen;
702 return LnnOnNodeOnlineStateChanged(isOnline, info);
703 }
704
OnNodeBasicInfoChanged(void * info,uint32_t infoTypeLen,int32_t type)705 int32_t SoftBusClientStub::OnNodeBasicInfoChanged(void *info, uint32_t infoTypeLen, int32_t type)
706 {
707 (void)infoTypeLen;
708 return LnnOnNodeBasicInfoChanged(info, type);
709 }
710
OnTimeSyncResult(const void * info,uint32_t infoTypeLen,int32_t retCode)711 int32_t SoftBusClientStub::OnTimeSyncResult(const void *info, uint32_t infoTypeLen, int32_t retCode)
712 {
713 (void)infoTypeLen;
714 return LnnOnTimeSyncResult(info, retCode);
715 }
716
OnPublishLNNResult(int32_t publishId,int32_t reason)717 void SoftBusClientStub::OnPublishLNNResult(int32_t publishId, int32_t reason)
718 {
719 LnnOnPublishLNNResult(publishId, reason);
720 }
721
OnRefreshLNNResult(int32_t refreshId,int32_t reason)722 void SoftBusClientStub::OnRefreshLNNResult(int32_t refreshId, int32_t reason)
723 {
724 LnnOnRefreshLNNResult(refreshId, reason);
725 }
726
OnRefreshDeviceFound(const void * device,uint32_t deviceLen)727 void SoftBusClientStub::OnRefreshDeviceFound(const void *device, uint32_t deviceLen)
728 {
729 (void)deviceLen;
730 LnnOnRefreshDeviceFound(device);
731 }
732 } // namespace OHOS