Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include "ra_comm.h"
12 : #include <errno.h>
13 : #include "securec.h"
14 : #include "ra_rs_err.h"
15 :
16 6 : int RaGetSocketConnectInfo(const struct SocketConnectInfoT conn[], unsigned int num, struct SocketConnectInfo rsConn[],
17 : unsigned int rsNum)
18 : {
19 6 : struct RaSocketHandle *socketHandle = NULL;
20 : unsigned int i;
21 : int ret;
22 :
23 6 : CHK_PRT_RETURN(num > rsNum || num > MAX_SOCKET_NUM || num == 0 || conn == NULL || rsConn == NULL,
24 : hccp_err("[get]"
25 : "[ra_socket_connect_info]num(%u) > rs_num(%u) or num == 0 or conn or rs_conn is NULL, invalid",
26 : num, rsNum),
27 : -EINVAL);
28 9 : for (i = 0; i < num; i++) {
29 5 : socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
30 5 : CHK_PRT_RETURN(socketHandle == NULL, hccp_err("[get][ra_socket_connect_info] conn[%u].socketHandle is null", i),
31 : -EINVAL);
32 5 : rsConn[i].phyId = socketHandle->rdevInfo.phyId;
33 5 : rsConn[i].family = socketHandle->rdevInfo.family;
34 5 : rsConn[i].port = conn[i].port;
35 5 : ret = memcpy_s(&(rsConn[i].localIp), sizeof(union HccpIpAddr), &(socketHandle->rdevInfo.localIp),
36 : sizeof(union HccpIpAddr));
37 5 : CHK_PRT_RETURN(ret, hccp_err("[get][ra_socket_connect_info]memcpy_s for local_ip failed, ret(%d)", ret),
38 : -ESAFEFUNC);
39 4 : ret = memcpy_s(&(rsConn[i].remoteIp), sizeof(union HccpIpAddr), &(conn[i].remoteIp), sizeof(union HccpIpAddr));
40 4 : CHK_PRT_RETURN(ret, hccp_err("[get][ra_socket_connect_info]memcpy_s for remote_ip failed, ret(%d)", ret),
41 : -ESAFEFUNC);
42 4 : ret = memcpy_s(rsConn[i].tag, SOCK_CONN_TAG_SIZE, conn[i].tag, SOCK_CONN_TAG_SIZE);
43 4 : CHK_PRT_RETURN(ret, hccp_err("[get][ra_socket_connect_info]memcpy_s for tag failed, ret(%d)", ret), -ESAFEFUNC);
44 : }
45 4 : return 0;
46 : }
47 :
48 16 : int RaGetSocketListenInfo(const struct SocketListenInfoT conn[], unsigned int num, struct SocketListenInfo rsConn[],
49 : unsigned int rsNum)
50 : {
51 : unsigned int i;
52 : int ret;
53 16 : struct RaSocketHandle *socketHandle = NULL;
54 :
55 16 : CHK_PRT_RETURN(num > rsNum || num > MAX_SOCKET_NUM || num == 0 || conn == NULL || rsConn == NULL,
56 : hccp_err("[get]"
57 : "[ra_socket_listen_info]num(%u) > rs_num(%u) or num == 0 or conn or rsConn is NULL, invalid",
58 : num, rsNum),
59 : -EINVAL);
60 :
61 29 : for (i = 0; i < num; i++) {
62 15 : rsConn[i].phase = conn[i].phase;
63 15 : rsConn[i].err = conn[i].err;
64 15 : socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
65 15 : rsConn[i].phyId = socketHandle->rdevInfo.phyId;
66 15 : rsConn[i].family = socketHandle->rdevInfo.family;
67 15 : rsConn[i].port = conn[i].port;
68 15 : ret = memcpy_s(&(rsConn[i].localIp), sizeof(union HccpIpAddr), &(socketHandle->rdevInfo.localIp),
69 : sizeof(union HccpIpAddr));
70 15 : CHK_PRT_RETURN(ret, hccp_err("[get][ra_socket_listen_info]memcpy_s for local_ip failed, ret(%d)", ret),
71 : -ESAFEFUNC);
72 : }
73 14 : return 0;
74 : }
75 :
76 4 : int RaGetSocketListenResult(const struct SocketListenInfo rsConn[], unsigned int rsNum, struct SocketListenInfoT conn[],
77 : unsigned int num)
78 : {
79 4 : struct RaSocketHandle *socketHandle = NULL;
80 : unsigned int i;
81 : int ret;
82 :
83 4 : CHK_PRT_RETURN(rsNum > num || rsNum > MAX_SOCKET_NUM || num == 0 || conn == NULL || rsConn == NULL,
84 : hccp_err("[get]"
85 : "[ra_socket_listen_result]rs_num(%u) > num(%u) or num == 0 or conn or rs_conn is NULL, invalid",
86 : rsNum, num),
87 : -EINVAL);
88 :
89 5 : for (i = 0; i < rsNum; i++) {
90 3 : conn[i].phase = rsConn[i].phase;
91 3 : conn[i].err = rsConn[i].err;
92 3 : conn[i].port = rsConn[i].port;
93 3 : socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
94 3 : socketHandle->rdevInfo.phyId = rsConn[i].phyId;
95 3 : socketHandle->rdevInfo.family = rsConn[i].family;
96 3 : ret = memcpy_s(&(socketHandle->rdevInfo.localIp), sizeof(union HccpIpAddr), &(rsConn[i].localIp),
97 : sizeof(union HccpIpAddr));
98 3 : CHK_PRT_RETURN(ret, hccp_err("[get][ra_socket_listen_result]memcpy_s for local_ip failed, ret(%d)", ret),
99 : -ESAFEFUNC);
100 : }
101 2 : return 0;
102 : }
|