1 /* 2 * Copyright (c) 2020 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 OHOS_DISTRIBUTEDSCHEDULE_TLVCOMMON_H 17 #define OHOS_DISTRIBUTEDSCHEDULE_TLVCOMMON_H 18 19 #include <stdint.h> 20 21 #ifdef __cplusplus 22 #if __cplusplus 23 extern "C" { 24 #endif 25 #endif 26 27 #define TLV_ONE_BYTE_LENGTH 127 28 #define TLV_MAX_LENGTH_BYTES 2 29 #define TLV_TYPE_LEN 1 30 #define MAX_DMS_MSG_LENGTH 1024 31 32 typedef struct TlvNode { 33 uint8_t type; 34 uint16_t length; 35 const uint8_t *value; 36 struct TlvNode *next; 37 } TlvNode; 38 39 typedef enum { 40 DMS_TLV_SUCCESS = 0, 41 DMS_TLV_ERR_NO_MEM = 1, 42 DMS_TLV_ERR_PARAM = 2, 43 DMS_TLV_ERR_LEN = 3, 44 DMS_TLV_ERR_OUT_OF_ORDER = 4, 45 DMS_TLV_ERR_BAD_NODE_NUM = 5, 46 DMS_TLV_ERR_UNKNOWN_TYPE = 6, 47 DMS_TLV_ERR_BAD_SOURCE = 7, 48 } TlvErrorCode; 49 50 typedef enum { 51 COMMAND_ID = 1, 52 DMS_VERSION = 2, 53 CALLEE_BUNDLE_NAME = 3, 54 CALLEE_ABILITY_NAME = 4, 55 CALLER_SIGNATURE = 5, 56 CALLER_PAYLOAD = 6, 57 REPLY_ERR_CODE = 0xFF 58 } FieldType; 59 60 typedef struct { 61 uint16_t payloadLength; 62 const uint8_t *payload; 63 } CommuMessage; 64 65 enum DmsCommuMsgCmdType { 66 DMS_MSG_CMD_START_FA = 0x01, 67 DMS_MSG_CMD_REPLY = 0xFFFF 68 }; 69 70 uint8_t UnMarshallUint8(const TlvNode *tlvHead, uint8_t nodeType); 71 uint16_t UnMarshallUint16(const TlvNode *tlvHead, uint8_t nodeType); 72 uint32_t UnMarshallUint32(const TlvNode *tlvHead, uint8_t nodeType); 73 uint64_t UnMarshallUint64(const TlvNode *tlvHead, uint8_t nodeType); 74 int8_t UnMarshallInt8(const TlvNode *tlvHead, uint8_t nodeType); 75 int16_t UnMarshallInt16(const TlvNode *tlvHead, uint8_t nodeType); 76 int32_t UnMarshallInt32(const TlvNode *tlvHead, uint8_t nodeType); 77 int64_t UnMarshallInt64(const TlvNode *tlvHead, uint8_t nodeType); 78 const char* UnMarshallString(const TlvNode *tlvHead, uint8_t nodeType); 79 #ifdef __cplusplus 80 #if __cplusplus 81 } 82 #endif 83 #endif 84 85 #endif /* OHOS_DISTRIBUTEDSCHEDULE_TLVCOMMON_H */