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 "user_log.h"
12 : #include "ra.h"
13 : #include "ra_rs_comm.h"
14 : #include "ra_client_host.h"
15 : #include "hccp.h"
16 :
17 0 : HCCP_ATTRI_VISI_DEF int RaGetClientSocketErrInfo(struct SocketConnectInfoT conn[], struct SocketErrInfo err[],
18 : unsigned int num)
19 : {
20 0 : struct RaSocketHandle *socketHandle = NULL;
21 0 : char remoteIp[MAX_IP_LEN] = {0};
22 0 : char localIp[MAX_IP_LEN] = {0};
23 0 : unsigned int phyId = 0;
24 : unsigned int i;
25 : int ret;
26 :
27 0 : CHK_PRT_RETURN(conn == NULL || err == NULL || num == 0 || num > MAX_SOCKET_NUM,
28 : hccp_err("[get][ra_socket]conn is NULL or err is NULL or num[%u] is zero or num is greater than %d", num,
29 : MAX_SOCKET_NUM),
30 : ConverReturnCode(SOCKET_OP, -EINVAL));
31 :
32 0 : for (i = 0; i < num; i++) {
33 0 : socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
34 0 : CHK_PRT_RETURN(socketHandle == NULL || socketHandle->socketOps == NULL ||
35 : socketHandle->socketOps->raGetClientSocketErrInfo == NULL,
36 : hccp_err("[get][ra_socket]socket_handle or func is NULL"), ConverReturnCode(SOCKET_OP, -EINVAL));
37 :
38 0 : phyId = socketHandle->rdevInfo.phyId;
39 0 : CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
40 : hccp_err("[get][ra_socket]RaGetClientSocketErrInfo get phyid failed, phyid[%u] should < max[%u]", phyId,
41 : RA_MAX_PHY_ID_NUM),
42 : -EINVAL);
43 :
44 0 : ret = RaInetPton(socketHandle->rdevInfo.family, socketHandle->rdevInfo.localIp, localIp, MAX_IP_LEN);
45 0 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][ra_socket]ra_inet_pton for local_ip failed, ret(%d)", ret),
46 : ConverReturnCode(SOCKET_OP, ret));
47 :
48 0 : ret = RaInetPton(socketHandle->rdevInfo.family, conn[i].remoteIp, remoteIp, MAX_IP_LEN);
49 0 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][ra_socket]ra_inet_pton for remote_ip failed, ret(%d)", ret),
50 : ConverReturnCode(SOCKET_OP, ret));
51 :
52 0 : hccp_info("Input parameters: [%u]th, phyId[%u], localIp[%s], remoteIp[%s], port[%u], tag[%s]", i, phyId,
53 : localIp, remoteIp, conn[i].port, conn[i].tag);
54 : }
55 :
56 0 : ret = socketHandle->socketOps->raGetClientSocketErrInfo(phyId, conn, err, num);
57 0 : return ConverReturnCode(SOCKET_OP, ret);
58 : }
59 :
60 0 : HCCP_ATTRI_VISI_DEF int RaGetServerSocketErrInfo(struct SocketListenInfoT conn[], struct ServerSocketErrInfo err[],
61 : unsigned int num)
62 : {
63 0 : struct RaSocketHandle *socketHandle = NULL;
64 0 : char localIp[MAX_IP_LEN] = {0};
65 0 : unsigned int phyId = 0;
66 : unsigned int i;
67 : int ret;
68 :
69 0 : CHK_PRT_RETURN(conn == NULL || err == NULL || num == 0 || num > MAX_SOCKET_NUM,
70 : hccp_err("[get][ra_socket]conn is NULL or err is NULL or num[%u] is zero or num is greater than %d", num,
71 : MAX_SOCKET_NUM),
72 : ConverReturnCode(SOCKET_OP, -EINVAL));
73 :
74 0 : for (i = 0; i < num; i++) {
75 0 : socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
76 0 : CHK_PRT_RETURN(socketHandle == NULL || socketHandle->socketOps == NULL ||
77 : socketHandle->socketOps->raGetServerSocketErrInfo == NULL,
78 : hccp_err("[get][ra_socket]socket_handle or func is NULL"), ConverReturnCode(SOCKET_OP, -EINVAL));
79 :
80 0 : phyId = socketHandle->rdevInfo.phyId;
81 0 : CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
82 : hccp_err("[get][ra_socket]RaGetServerSocketErrInfo get phyid failed, phyid[%u] should < max[%u]", phyId,
83 : RA_MAX_PHY_ID_NUM),
84 : -EINVAL);
85 :
86 0 : ret = RaInetPton(socketHandle->rdevInfo.family, socketHandle->rdevInfo.localIp, localIp, MAX_IP_LEN);
87 0 : CHK_PRT_RETURN(ret, hccp_err("[get][ra_socket]ra_inet_pton for server_ip failed, ret(%d)", ret),
88 : ConverReturnCode(SOCKET_OP, ret));
89 :
90 0 : hccp_info("Input parameters: [%u]th, phyId[%u], localIp[%s], port[%u]", i, phyId, localIp, conn[i].port);
91 : }
92 :
93 0 : ret = socketHandle->socketOps->raGetServerSocketErrInfo(phyId, conn, err, num);
94 0 : return ConverReturnCode(SOCKET_OP, ret);
95 : }
96 :
97 0 : HCCP_ATTRI_VISI_DEF int RaSocketAcceptCreditAdd(struct SocketListenInfoT conn[], unsigned int num,
98 : unsigned int creditLimit)
99 : {
100 0 : struct RaSocketHandle *socketHandle = NULL;
101 0 : char localIp[MAX_IP_LEN] = {0};
102 0 : unsigned int phyId = 0;
103 : unsigned int i;
104 : int ret;
105 :
106 0 : CHK_PRT_RETURN(conn == NULL || num == 0 || num > MAX_SOCKET_NUM || creditLimit == 0,
107 : hccp_err("[set][ra_socket]conn is NULL or num[%u] is 0 or greater than %d, or creditLimit[%u] is 0", num,
108 : MAX_SOCKET_NUM, creditLimit),
109 : ConverReturnCode(SOCKET_OP, -EINVAL));
110 :
111 0 : for (i = 0; i < num; i++) {
112 0 : socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
113 0 : CHK_PRT_RETURN(socketHandle == NULL || socketHandle->socketOps == NULL ||
114 : socketHandle->socketOps->raSocketAcceptCreditAdd == NULL,
115 : hccp_err("[set][ra_socket]socket_handle or func is NULL"), ConverReturnCode(SOCKET_OP, -EINVAL));
116 :
117 0 : phyId = socketHandle->rdevInfo.phyId;
118 0 : CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
119 : hccp_err("[set][ra_socket]phyId(%u) must smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
120 : ConverReturnCode(SOCKET_OP, -EINVAL));
121 :
122 0 : ret = RaInetPton(socketHandle->rdevInfo.family, socketHandle->rdevInfo.localIp, localIp, MAX_IP_LEN);
123 0 : CHK_PRT_RETURN(ret, hccp_err("[set][ra_socket]ra_inet_pton for server_ip failed, ret(%d)", ret),
124 : ConverReturnCode(SOCKET_OP, ret));
125 :
126 0 : hccp_run_info("Input parameters: [%u]th, phyId[%u], localIp[%s] port[%u] creditLimit[%u]", i, phyId, localIp,
127 : conn[i].port, creditLimit);
128 : }
129 :
130 0 : ret = socketHandle->socketOps->raSocketAcceptCreditAdd(phyId, conn, num, creditLimit);
131 0 : return ConverReturnCode(SOCKET_OP, ret);
132 : }
|