1 /* 2 * Copyright (C) 2021 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 DAS_VERSION_UTIL_H 17 #define DAS_VERSION_UTIL_H 18 19 #include "pake_defs.h" 20 #include "common_defs.h" 21 #include "protocol_common.h" 22 23 #define ALG_OFFSET_FOR_PAKE_V1 0 24 #define ALG_OFFSET_FOR_PAKE_V2 5 25 26 #define MAJOR_VERSION_NO 2 27 #define TMP_VERSION_STR_LEN 15 28 29 typedef enum { 30 UNSUPPORTED_ALG = 0x0000, 31 DL_PAKE_V1 = 0x0001, // 0001 32 EC_PAKE_V1 = 0x0002, // 0010 33 STS_ALG = 0x0004, // 0100 34 PSK_SPEKE = 0x0008, // 1000 35 ISO_ALG = 0x0010, // 0001 0000 36 DL_PAKE_V2 = 0x0020, // 0010 0000 37 EC_PAKE_V2 = 0x0040, // 0100 0000 38 } DasAlgType; 39 40 typedef enum { 41 INITIAL, 42 VERSION_CONFIRM, 43 VERSION_DECIDED, 44 } VersionAgreementStatus; 45 46 typedef struct { 47 uint32_t first; 48 uint32_t second; 49 uint32_t third; 50 } VersionStruct; 51 52 typedef struct VersionInfoT { 53 int32_t opCode; 54 VersionAgreementStatus versionStatus; 55 VersionStruct minVersion; 56 VersionStruct curVersion; 57 } VersionInfo; 58 59 #ifdef __cplusplus 60 extern "C" { 61 #endif 62 63 int32_t VersionToString(const VersionStruct *version, char *verStr, uint32_t len); 64 int32_t StringToVersion(const char* verStr, VersionStruct* version); 65 66 int32_t AddSingleVersionToJson(CJson *jsonObj, const VersionStruct *version); 67 int32_t GetSingleVersionFromJson(const CJson* jsonObj, VersionStruct *version); 68 void InitGroupAndModuleVersion(VersionStruct *version); 69 70 int32_t GetVersionFromJson(const CJson *jsonObj, VersionStruct *minVer, VersionStruct *maxVer); 71 int32_t AddVersionToJson(CJson *jsonObj, const VersionStruct *minVer, const VersionStruct *maxVer); 72 73 bool IsVersionEqual(VersionStruct *src, VersionStruct *des); 74 int32_t NegotiateVersion(VersionStruct *minVersionPeer, VersionStruct *curVersionPeer, 75 VersionStruct *curVersionSelf); 76 77 ProtocolType GetPrototolType(VersionStruct *curVersion, OperationCode opCode); 78 PakeAlgType GetSupportedPakeAlg(VersionStruct *curVersion, ProtocolType protocolType); 79 bool IsSupportedPsk(VersionStruct *curVersion); 80 81 #ifdef __cplusplus 82 } 83 #endif 84 #endif 85