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