1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef TRANS_TCP_PROCESS_DATA_H 17 #define TRANS_TCP_PROCESS_DATA_H 18 19 #include <stdint.h> 20 21 #include "common_list.h" 22 #include "softbus_app_info.h" 23 #include "softbus_def.h" 24 #include "trans_assemble_tlv.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 #ifndef MAGIC_NUMBER 30 #define MAGIC_NUMBER 0xBABEFACE 31 32 #define DC_DATA_HEAD_SIZE 16 33 #endif 34 35 typedef struct { 36 ListNode node; 37 int32_t channelId; 38 int32_t fd; 39 uint32_t size; 40 char *data; 41 char *w; 42 } DataBuf; 43 44 typedef struct { 45 uint32_t magicNumber; 46 int32_t seq; 47 uint32_t flags; 48 uint32_t dataLen; 49 } __attribute__((packed)) TcpDataPacketHead; 50 51 typedef struct { 52 uint32_t magicNumber; 53 uint8_t tlvCount; 54 int32_t seq; 55 uint32_t dataSeq; 56 uint32_t flags; 57 uint32_t dataLen; 58 bool needAck; 59 } __attribute__((packed)) TcpDataTlvPacketHead; 60 61 typedef struct { 62 uint32_t outLen; 63 uint32_t tlvHeadLen; 64 } DataLenInfo; 65 66 typedef struct { 67 bool needAck; 68 bool supportTlv; 69 int32_t seq; 70 uint32_t len; 71 } TransTdcPackDataInfo; 72 73 typedef struct { 74 const char *in; 75 uint32_t inLen; 76 char *out; 77 uint32_t *outLen; 78 } EncrptyInfo; 79 80 int32_t TransTdcRecvFirstData(int32_t channelId, char *recvBuf, int32_t *recvLen, int32_t fd, size_t len); 81 int32_t TransTdcUnPackAllData(int32_t channelId, DataBuf *node, bool *flag); 82 int32_t TransTdcUnPackData(int32_t channelId, const char *sessionKey, char *plain, uint32_t *plainLen, DataBuf *node); 83 int32_t TransTdcUnPackAllTlvData( 84 int32_t channelId, TcpDataTlvPacketHead *head, uint32_t *newDataHeadSize, DataBuf *node, bool *flag); 85 int32_t TransTdcDecrypt(const char *sessionKey, const char *in, uint32_t inLen, char *out, uint32_t *outLen); 86 int32_t MoveNode(int32_t channelId, DataBuf *node, uint32_t dataLen, int32_t pkgHeadSize); 87 int32_t TransTdcSendData(DataLenInfo *lenInfo, bool supportTlv, int32_t fd, uint32_t len, char *buf); 88 int32_t TransGetTdcDataBufMaxSize(void); 89 uint32_t TransGetDataBufSize(void); 90 char *TransTdcPackAllData( 91 TransTdcPackDataInfo *info, const char *sessionKey, const char *data, int32_t flags, DataLenInfo *lenInfo); 92 int32_t BuildNeedAckTlvData(DataHead *pktHead, bool needAck, uint32_t dataSeqs, int32_t *tlvBufferSize); 93 int32_t BuildDataHead(DataHead *pktHead, int32_t finalSeq, int32_t flags, uint32_t dataLen, int32_t *tlvBuffersize); 94 char *TransTdcPackTlvData(DataHead *pktHead, int32_t tlvBufferSize, uint32_t dataLen); 95 void ReleaseDataHeadResource(DataHead *pktHead); 96 int32_t TransTdcEncryptWithSeq(const char *sessionKey, int32_t seqNum, EncrptyInfo *info); 97 #ifdef __cplusplus 98 } 99 #endif /* __cplusplus */ 100 #endif // TRANS_TCP_PROCESS_DATA_H 101 102