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