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