• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "trans_client_stub.h"
17 
18 #include "client_trans_channel_callback.h"
19 #include "ipc_skeleton.h"
20 #include "softbus_errcode.h"
21 #include "softbus_server_ipc_interface_code.h"
22 #include "trans_log.h"
23 
ClientOnChannelOpened(IpcIo * data,IpcIo * reply)24 int32_t ClientOnChannelOpened(IpcIo *data, IpcIo *reply)
25 {
26     if (reply == NULL) {
27         TRANS_LOGE(TRANS_CTRL, "invalid param.");
28         return SOFTBUS_INVALID_PARAM;
29     }
30     size_t size = 0;
31     ChannelInfo channel = {0};
32     const char *sessionName = (const char *)ReadString(data, &size);
33     ReadInt32(data, &(channel.channelId));
34     ReadInt32(data, &(channel.channelType));
35     ReadBool(data, &(channel.isServer));
36     ReadBool(data, &(channel.isEnabled));
37     ReadBool(data, &(channel.isEncrypt));
38     ReadInt32(data, &(channel.peerUid));
39     ReadInt32(data, &(channel.peerPid));
40     channel.groupId = (char *)ReadString(data, &size);
41     ReadUint32(data, &(channel.keyLen));
42     channel.sessionKey = (char *)ReadBuffer(data, channel.keyLen);
43     channel.peerSessionName = (char *)ReadString(data, &size);
44     channel.peerDeviceId = (char *)ReadString(data, &size);
45     if (channel.groupId == NULL || channel.sessionKey == NULL || channel.peerSessionName == NULL ||
46         channel.peerDeviceId == NULL) {
47         TRANS_LOGE(TRANS_CTRL, "pointer null error.");
48         return SOFTBUS_ERR;
49     }
50     if (channel.channelType == CHANNEL_TYPE_TCP_DIRECT) {
51         channel.fd = ReadFileDescriptor(data);
52     }
53     ReadInt32(data, &(channel.businessType));
54     if (channel.channelType == CHANNEL_TYPE_UDP) {
55         channel.myIp = (char *)ReadString(data, &size);
56         ReadInt32(data, &(channel.streamType));
57         ReadBool(data, &(channel.isUdpFile));
58         if (channel.isServer) {
59             int32_t udpPort = TransOnChannelOpened(sessionName, &channel);
60             WriteInt32(reply, udpPort);
61             return SOFTBUS_ERR;
62         }
63         ReadInt32(data, &(channel.peerPort));
64         channel.peerIp = (char *)ReadString(data, &size);
65     }
66     int ret = TransOnChannelOpened(sessionName, &channel);
67     if (ret < 0) {
68         TRANS_LOGE(TRANS_CTRL, "TransOnChannelOpened fail, errcode=%{public}d.", ret);
69     }
70     return SOFTBUS_OK;
71 }
72 
ClientOnChannelOpenfailed(IpcIo * data,IpcIo * reply)73 int32_t ClientOnChannelOpenfailed(IpcIo *data, IpcIo *reply)
74 {
75     if (data == NULL) {
76         TRANS_LOGE(TRANS_CTRL, "invalid param.");
77         return SOFTBUS_INVALID_PARAM;
78     }
79     int32_t channelId = 0;
80     int32_t channelType = 0;
81     int32_t errCode = SOFTBUS_OK;
82     ReadInt32(data, &channelId);
83     ReadInt32(data, &channelType);
84     ReadInt32(data, &errCode);
85     (void)TransOnChannelOpenFailed(channelId, channelType, errCode);
86     return SOFTBUS_OK;
87 }
88 
ClientOnChannelClosed(IpcIo * data,IpcIo * reply)89 int32_t ClientOnChannelClosed(IpcIo *data, IpcIo *reply)
90 {
91     if (data == NULL) {
92         TRANS_LOGE(TRANS_CTRL, "invalid param.");
93         return SOFTBUS_INVALID_PARAM;
94     }
95     int32_t channelId = 0;
96     int32_t channelType = 0;
97     ReadInt32(data, &channelId);
98     ReadInt32(data, &channelType);
99     (void)TransOnChannelClosed(channelId, channelType, SHUTDOWN_REASON_PEER);
100     return SOFTBUS_OK;
101 }
102 
ClientOnChannelMsgreceived(IpcIo * data,IpcIo * reply)103 int32_t ClientOnChannelMsgreceived(IpcIo *data, IpcIo *reply)
104 {
105     if (data == NULL) {
106         TRANS_LOGE(TRANS_CTRL, "invalid param.");
107         return SOFTBUS_INVALID_PARAM;
108     }
109     int32_t channelId = 0;
110     int32_t channelType = 0;
111     int32_t type = 0;
112     ReadInt32(data, &channelId);
113     ReadInt32(data, &channelType);
114     ReadInt32(data, &type);
115     uint32_t dataLen = 0;
116     ReadUint32(data, &dataLen);
117     const uint8_t *data2 = ReadBuffer(data, dataLen);
118     (void)TransOnChannelMsgReceived(channelId, channelType, data2, dataLen, type);
119     return SOFTBUS_OK;
120 }