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 <stdlib.h>
12 : #include <errno.h>
13 : #include "ra_hdc_tlv.h"
14 : #include "ra_rs_err.h"
15 : #include "rs_tlv.h"
16 : #include "ra_adp.h"
17 : #include "ra_adp_tlv.h"
18 :
19 : struct RsTlvOps {
20 : int (*tlvInit)(unsigned int phyId, unsigned int *bufferSize);
21 : int (*tlvDeinit)(unsigned int phyId);
22 : int (*tlvRequest)(struct TlvRequestMsgHead *head, char *dataIn, char *dataOut, unsigned int *bufferSize,
23 : unsigned int dataMaxLength);
24 : int (*ccuCustomChannel)(const struct CustomChanInfoIn *in, struct CustomChanInfoOut *out);
25 : };
26 :
27 : struct RsTlvOps gRaRsTlvOps = {
28 : .tlvInit = RsTlvInit,
29 : .tlvDeinit = RsTlvDeinit,
30 : .tlvRequest = RsTlvRequest,
31 : .ccuCustomChannel = RsCtxCustomChannel,
32 : };
33 :
34 0 : int RaRsTlvInitV1(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
35 : {
36 : (void)inBuf;
37 : (void)outBuf;
38 : (void)outLen;
39 : (void)rcvBufLen;
40 0 : hccp_warn("Tlv init is not support in this version.");
41 0 : *opResult = -ENOTSUPP;
42 0 : return 0;
43 : }
44 :
45 4 : int RaRsTlvInit(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
46 : {
47 : (void)outLen;
48 4 : union OpTlvInitData *dataOut = (union OpTlvInitData *)(outBuf + sizeof(struct MsgHead));
49 4 : union OpTlvInitData *dataIn = (union OpTlvInitData *)(inBuf + sizeof(struct MsgHead));
50 :
51 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpTlvInitData), sizeof(struct MsgHead), rcvBufLen, opResult);
52 :
53 4 : *opResult = gRaRsTlvOps.tlvInit(dataIn->txData.phyId, &dataOut->rxData.bufferSize);
54 4 : CHK_PRT_RETURN(*opResult == -ENOTSUPP, hccp_warn("tlv_init unsuccessful ret[%d]", *opResult), 0);
55 3 : if (*opResult != 0) {
56 1 : hccp_err("tlv_init failed ret[%d]", *opResult);
57 : }
58 :
59 3 : return 0;
60 : }
61 :
62 3 : int RaRsTlvDeinit(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
63 : {
64 : (void)outBuf;
65 : (void)outLen;
66 3 : union OpTlvDeinitData *dataIn = (union OpTlvDeinitData *)(inBuf + sizeof(struct MsgHead));
67 :
68 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpTlvDeinitData), sizeof(struct MsgHead), rcvBufLen, opResult);
69 :
70 3 : *opResult = gRaRsTlvOps.tlvDeinit(dataIn->txData.phyId);
71 3 : if (*opResult != 0) {
72 1 : hccp_err("tlv_deinit failed ret[%d]", *opResult);
73 : }
74 :
75 3 : return 0;
76 : }
77 :
78 4 : int RaRsTlvRequest(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
79 : {
80 : (void)outLen;
81 4 : union OpTlvRequestData *dataOut = (union OpTlvRequestData *)(outBuf + sizeof(struct MsgHead));
82 4 : union OpTlvRequestData *dataIn = (union OpTlvRequestData *)(inBuf + sizeof(struct MsgHead));
83 :
84 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpTlvRequestData), sizeof(struct MsgHead), rcvBufLen, opResult);
85 :
86 4 : *opResult = gRaRsTlvOps.tlvRequest(&dataIn->txData.head, dataIn->txData.data, dataOut->rxData.recvData,
87 : &dataOut->rxData.recvBytes, MAX_TLV_MSG_DATA_LEN);
88 :
89 4 : CHK_PRT_RETURN(*opResult == -EUSERS || *opResult == -ENOTSUPP, hccp_warn("tlv request unsuccessful"), 0);
90 4 : if (*opResult != 0) {
91 2 : hccp_err("tlv_request failed ret[%d]", *opResult);
92 : }
93 :
94 4 : return 0;
95 : }
96 :
97 0 : int RaRsTlvRequestV2(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
98 : {
99 : (void)outLen;
100 0 : union OpTlvRequestDataV2 *dataOut = (union OpTlvRequestDataV2 *)(outBuf + sizeof(struct MsgHead));
101 0 : union OpTlvRequestDataV2 *dataIn = (union OpTlvRequestDataV2 *)(inBuf + sizeof(struct MsgHead));
102 :
103 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpTlvRequestDataV2), sizeof(struct MsgHead), rcvBufLen, opResult);
104 :
105 0 : *opResult = gRaRsTlvOps.tlvRequest(&dataIn->txData.head, dataIn->txData.data, dataOut->rxData.recvData,
106 : &dataOut->rxData.recvBytes, MAX_TLV_MSG_DATA_LEN_V2);
107 :
108 0 : CHK_PRT_RETURN(*opResult == -EUSERS || *opResult == -ENOTSUPP, hccp_warn("tlv request v2 unsuccessful"), 0);
109 0 : if (*opResult != 0) {
110 0 : hccp_err("tlv_request_v2 failed ret[%d]", *opResult);
111 : }
112 :
113 0 : return 0;
114 : }
115 :
116 0 : int RaRsCustomChannel(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
117 : {
118 : (void)outLen;
119 0 : union OpCustomChannelData *opDataOut = (union OpCustomChannelData *)(outBuf + sizeof(struct MsgHead));
120 0 : union OpCustomChannelData *opData = (union OpCustomChannelData *)(inBuf + sizeof(struct MsgHead));
121 :
122 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpCustomChannelData), sizeof(struct MsgHead), rcvBufLen, opResult);
123 :
124 0 : *opResult = gRaRsTlvOps.ccuCustomChannel(&opData->txData.info, &opDataOut->rxData.info);
125 0 : if (*opResult != 0) {
126 0 : hccp_err("[ccu]custom channel failed, ret[%d], phyId[%u]", *opResult, opData->txData.phyId);
127 : }
128 :
129 0 : return 0;
130 : }
|