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